-
Notifications
You must be signed in to change notification settings - Fork 896
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deduplicate the code that strips the user info from authority #5490
Comments
Hi, @ikhoon, could I try this issue? |
Hi sorry, we're doing an internal open source sprint and this issue has been assigned 😅 Let us assign labels on such issues so that it is clear which issues are already being worked on 🙇 |
sure, so what kind of label could I take on? |
Armeria provides a HTTP client WebClient, which is able to send HTTP requests. Usually, a user provides a String format URI and
ref: https://www.rfc-editor.org/rfc/rfc3986.html#section-3 Amongst the different URI components, the authority determines 1) Where to send the request 2) What to set to the
ref: https://www.rfc-editor.org/rfc/rfc3986.html#section-3.2 However, the validation/parsing logic of the authority is fragmented across the code base:
The objective of this issue is to unify the validation/parsing logic above To get jump-started with the current code base, it's probably best one checks from unit tests how the above logic works. i.e. When sending the request from class WebClientTest {
@RegisterExtension
static final ServerExtension server = new ServerExtension() {
@Override
protected void configure(ServerBuilder sb) throws Exception {
sb.service("/", (ctx, req) -> HttpResponse.of(200));
}
};
@Test
void test1() {
final AggregatedHttpResponse res = WebClient.of().blocking().get(server.httpUri().toString());
assertThat(res.status().code()).isEqualTo(200);
}
@Test
void test2() {
final HttpRequest req = HttpRequest.builder()
.header(HttpHeaderNames.SCHEME, "http")
.header(HttpHeaderNames.AUTHORITY, server.httpUri().getRawAuthority())
.get("/")
.build();
final AggregatedHttpResponse res = WebClient.of().blocking().execute(req);
assertThat(res.status().code()).isEqualTo(200);
}
@Test
void test3() {
final AggregatedHttpResponse res = WebClient.of(server.httpUri()).blocking().get("/");
assertThat(res.status().code()).isEqualTo(200);
}
@Test
void test4() {
final Endpoint endpoint = Endpoint.of(server.httpUri().getRawAuthority());
final AggregatedHttpResponse res = WebClient.of(SessionProtocol.HTTP, endpoint).blocking().get("/");
assertThat(res.status().code()).isEqualTo(200);
}
} i.e. When altering headers from decorators @Test
void test5() {
final AggregatedHttpResponse res = server
.blockingWebClient(cb -> cb.decorator((delegate, ctx, req) -> {
ctx.addAdditionalRequestHeader(HttpHeaderNames.AUTHORITY, "my-authority:8080");
assertThat(ctx.host()).isEqualTo("my-authority");
return delegate.execute(ctx, req);
}))
.get("/");
assertThat(res.status().code()).isEqualTo(200);
} i.e. When parsing an arbitrary target string (this method is used in @Test
void test6() {
final RequestTarget requestTarget = RequestTarget.forClient("http://my-authority:8080/hello");
assertThat(requestTarget.authority()).isEqualTo("my-authority:8080");
} Afterwards, I recommend that we add a public method in ArmeriaHttpUtil and try to unify the above logic. The skeletal API would probably look something like the following: public static ... parseAuthority(...) {
...
} |
Let me add a |
Also note the following bullet points from the initial report:
For starters, we may want to make this the initial implementation and trying to run the build. We could work on fixing each test case as we move forward. |
…ation (#5561) Motivation: - Make util method to deduplicate the code that strips the user info from authority Modifications: - ~Add `normalizeAuthority()`, `normalizeSchemeAndAuthority()` static method in `ArmeriaHttpUtil`~ - Add SchemeAndAuthorit class which is in charge of authority normalization Result: - Closes #5490. (If this resolves the issue.) <!-- Visit this URL to learn more about how to write a pull request description: https://armeria.dev/community/developer-guide#how-to-write-pull-request-description -->
…ation (line#5561) Motivation: - Make util method to deduplicate the code that strips the user info from authority Modifications: - ~Add `normalizeAuthority()`, `normalizeSchemeAndAuthority()` static method in `ArmeriaHttpUtil`~ - Add SchemeAndAuthorit class which is in charge of authority normalization Result: - Closes line#5490. (If this resolves the issue.) <!-- Visit this URL to learn more about how to write a pull request description: https://armeria.dev/community/developer-guide#how-to-write-pull-request-description -->
When a user sends an HTTP request using Armeria client, a user can specify the user info part in a request URI:
However, the user info part is not actually used at all and stripped by
removeUserInfo()
method inEndpoint
andDefaultRequestContext
:We see the following problems with the above code:
HostAndPort.fromString()
with the stripped authority; andDefaultRequestTarget.normalizeSchemeAndAuthority()
(code) doesn't useHostAndPort.fromString()
, unlikeEndpoint
andDefaultClientRequestContext
do.To ensure the consistency in authority parsing, we should:
new URI(String)
to parse an authority string; andArmeriaHttpUtil
so it is shared byDefaultRequestTarget
,Endpoint
andDefaultClientRequestContext
.For
Endpoint
andDefaultClientRequestContext
, we could:For
DefaultRequestTarget
, we could:The text was updated successfully, but these errors were encountered: