-
Notifications
You must be signed in to change notification settings - Fork 921
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
Introduce rawPath in RequestTarget and ServiceRequestContext #5932
Conversation
core/src/main/java/com/linecorp/armeria/internal/common/DefaultRequestTarget.java
Outdated
Show resolved
Hide resolved
core/src/main/java/com/linecorp/armeria/internal/common/DefaultRequestTarget.java
Show resolved
Hide resolved
hoping to get some feedbacks! |
@ikhoon I hope to get some feedbacks thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall it looks nice.
core/src/test/java/com/linecorp/armeria/internal/common/DefaultRequestTargetTest.java
Show resolved
Hide resolved
Please address the line failure.
|
9d460f4
to
5a3bfcf
Compare
/** | ||
* Returns the server-side raw path of this {@link RequestTarget} from the ":path" header. | ||
* Unlike {@link #path()}, the returned string is the original path without any normalization. | ||
* For client-side target it always returns {@code null}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would returning a non-null make sense on the client-side? By doing so, this method could be always non-null, which removes the need for null check on the server side as well (i.e. no complaints from NullAway and other linters)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about that as well, it's not very clear to me what's the semantic, because we need to consider the case for absolute or not, and its transformation along the lines.
Another idea I have is to expose it only in ServiceRequestContext, and keep the one in RequestTarget internal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exposing it only in ServiceRequestContext
sounds good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
took a closer look, b/c DefaultRequestTarget and DefaultServiceRequestContext don't live within the same package, it doesn't seems to be very easy, I might be missing something though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could keep RequestTarget.rawPath()
public and just access it from DefaultServiceRequestContext
, asserting it is non-null before returning it? i.e.
public interface ServiceRequestContext {
...
// Note no @Nullable
String rawPath();
}
public class DefaultServiceRequestContext {
...
@Override
String rawPath() {
final String rawPath = requestTarget().rawPath();
assert rawPath != null;
return rawPath;
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that should work! (I was thinking about keeping rawPath package private but java doesn't seem to work as scala), thanks for you idea!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated!
TEST_URLS.add("/%3A%2F%3F%23%5B%5D%40%21%24%26%27%28%29*%2B%2C%3B%3D"); | ||
} | ||
|
||
@Test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we use @ParameterizedTest
with @CsvSource
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sg, will update
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated!
assertThat(res.requestTarget.path()).isEqualTo(expectedPath); | ||
assertThat(res.requestTarget.query()).isEqualTo(expectedQuery); | ||
assertThat(res.requestTarget.fragment()).isEqualTo(expectedFragment); | ||
assertThat(res.requestTarget.rawPath()).isEqualTo(res.rawPath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check rawPath for all test cases.
6402594
to
60744a5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks!
60744a5
to
dffd133
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @yzfeng2020! 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 👍 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for a late review. Looks great! Thanks, @yzfeng2020 🙇
Motivation:
It may be useful if we have access to the original request path unmodified. For example we have use cases where the decoding rules are different from the ones at
decodedPath
.Modifications:
rawPath
method inRequestTarget
to store the rawPath.rawPath
method inServiceRequestContext
, it's always non null for server-side targets.Result: