-
Notifications
You must be signed in to change notification settings - Fork 915
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 #5932
Open
yzfeng2020
wants to merge
2
commits into
line:main
Choose a base branch
from
yzfeng2020:add-raw-path
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,27 +143,27 @@ void serverShouldAcceptGoodDoubleDotPatterns(String pattern) { | |
void dotsAndEqualsInNameValueQuery() { | ||
QUERY_SEPARATORS.forEach(qs -> { | ||
assertThat(forServer("/?a=..=" + qs + "b=..=")).satisfies(res -> { | ||
assertThat(res).isNotNull(); | ||
assertThat(res.query()).isEqualTo("a=..=" + qs + "b=..="); | ||
assertThat(QueryParams.fromQueryString(res.query(), true)).containsExactly( | ||
assertThat(res.requestTarget).isNotNull(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we also write e2e tests to verify that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure, added a new e2e test! |
||
assertThat(res.requestTarget.query()).isEqualTo("a=..=" + qs + "b=..="); | ||
assertThat(QueryParams.fromQueryString(res.requestTarget.query(), true)).containsExactly( | ||
Maps.immutableEntry("a", "..="), | ||
Maps.immutableEntry("b", "..=") | ||
); | ||
}); | ||
|
||
assertThat(forServer("/?a==.." + qs + "b==..")).satisfies(res -> { | ||
assertThat(res).isNotNull(); | ||
assertThat(res.query()).isEqualTo("a==.." + qs + "b==.."); | ||
assertThat(QueryParams.fromQueryString(res.query(), true)).containsExactly( | ||
assertThat(res.requestTarget.query()).isEqualTo("a==.." + qs + "b==.."); | ||
assertThat(QueryParams.fromQueryString(res.requestTarget.query(), true)).containsExactly( | ||
Maps.immutableEntry("a", "=.."), | ||
Maps.immutableEntry("b", "=..") | ||
); | ||
}); | ||
|
||
assertThat(forServer("/?a==..=" + qs + "b==..=")).satisfies(res -> { | ||
assertThat(res).isNotNull(); | ||
assertThat(res.query()).isEqualTo("a==..=" + qs + "b==..="); | ||
assertThat(QueryParams.fromQueryString(res.query(), true)).containsExactly( | ||
assertThat(res.requestTarget.query()).isEqualTo("a==..=" + qs + "b==..="); | ||
assertThat(QueryParams.fromQueryString(res.requestTarget.query(), true)).containsExactly( | ||
Maps.immutableEntry("a", "=..="), | ||
Maps.immutableEntry("b", "=..=") | ||
); | ||
|
@@ -500,9 +500,9 @@ void clientShouldAcceptAbsoluteUri(String uri, | |
String expectedScheme, String expectedAuthority, String expectedPath, | ||
@Nullable String expectedQuery, @Nullable String expectedFragment) { | ||
|
||
final RequestTarget res = forClient(uri); | ||
assertThat(res.scheme()).isEqualTo(expectedScheme); | ||
assertThat(res.authority()).isEqualTo(expectedAuthority); | ||
final RequestTargetWithRawPath res = forClient(uri); | ||
assertThat(res.requestTarget.scheme()).isEqualTo(expectedScheme); | ||
assertThat(res.requestTarget.authority()).isEqualTo(expectedAuthority); | ||
assertAccepted(res, expectedPath, emptyToNull(expectedQuery), emptyToNull(expectedFragment)); | ||
} | ||
|
||
|
@@ -531,15 +531,15 @@ void shouldYieldEmptyStringForEmptyQueryAndFragment(Mode mode) { | |
@ParameterizedTest | ||
@EnumSource(Mode.class) | ||
void testToString(Mode mode) { | ||
assertThat(parse(mode, "/")).asString().isEqualTo("/"); | ||
assertThat(parse(mode, "/?")).asString().isEqualTo("/?"); | ||
assertThat(parse(mode, "/?a=b")).asString().isEqualTo("/?a=b"); | ||
assertThat(parse(mode, "/").requestTarget).asString().isEqualTo("/"); | ||
assertThat(parse(mode, "/?").requestTarget).asString().isEqualTo("/?"); | ||
assertThat(parse(mode, "/?a=b").requestTarget).asString().isEqualTo("/?a=b"); | ||
|
||
if (mode == Mode.CLIENT) { | ||
assertThat(forClient("/#")).asString().isEqualTo("/#"); | ||
assertThat(forClient("/?#")).asString().isEqualTo("/?#"); | ||
assertThat(forClient("/?a=b#c=d")).asString().isEqualTo("/?a=b#c=d"); | ||
assertThat(forClient("http://foo/bar?a=b#c=d")).asString().isEqualTo("http://foo/bar?a=b#c=d"); | ||
assertThat(forClient("/#").requestTarget).asString().isEqualTo("/#"); | ||
assertThat(forClient("/?#").requestTarget).asString().isEqualTo("/?#"); | ||
assertThat(forClient("/?a=b#c=d").requestTarget).asString().isEqualTo("/?a=b#c=d"); | ||
assertThat(forClient("http://foo/bar?a=b#c=d").requestTarget).asString().isEqualTo("http://foo/bar?a=b#c=d"); | ||
} | ||
} | ||
|
||
|
@@ -572,32 +572,32 @@ void testRemoveMatrixVariables() { | |
assertThat(removeMatrixVariables("/prefix/;a=b")).isNull(); | ||
} | ||
|
||
private static void assertAccepted(@Nullable RequestTarget res, String expectedPath) { | ||
private static void assertAccepted(RequestTargetWithRawPath res, String expectedPath) { | ||
assertAccepted(res, expectedPath, null, null); | ||
} | ||
|
||
private static void assertAccepted(@Nullable RequestTarget res, | ||
private static void assertAccepted(RequestTargetWithRawPath res, | ||
String expectedPath, | ||
@Nullable String expectedQuery) { | ||
assertAccepted(res, expectedPath, expectedQuery, null); | ||
} | ||
|
||
private static void assertAccepted(@Nullable RequestTarget res, | ||
private static void assertAccepted(RequestTargetWithRawPath res, | ||
String expectedPath, | ||
@Nullable String expectedQuery, | ||
@Nullable String expectedFragment) { | ||
assertThat(res).isNotNull(); | ||
assertThat(res.path()).isEqualTo(expectedPath); | ||
assertThat(res.query()).isEqualTo(expectedQuery); | ||
assertThat(res.fragment()).isEqualTo(expectedFragment); | ||
assertThat(res.requestTarget).isNotNull(); | ||
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); | ||
} | ||
|
||
private static void assertRejected(@Nullable RequestTarget res) { | ||
assertThat(res).isNull(); | ||
private static void assertRejected(RequestTargetWithRawPath res) { | ||
assertThat(res.requestTarget).isNull(); | ||
} | ||
|
||
@Nullable | ||
private static RequestTarget parse(Mode mode, String rawPath) { | ||
private static RequestTargetWithRawPath parse(Mode mode, String rawPath) { | ||
switch (mode) { | ||
case SERVER: | ||
return forServer(rawPath); | ||
|
@@ -608,37 +608,57 @@ private static RequestTarget parse(Mode mode, String rawPath) { | |
} | ||
} | ||
|
||
@Nullable | ||
private static RequestTarget forServer(String rawPath) { | ||
private static class RequestTargetWithRawPath { | ||
@Nullable | ||
final String rawPath; | ||
@Nullable | ||
final RequestTarget requestTarget; | ||
|
||
RequestTargetWithRawPath(@Nullable String rawPath, @Nullable RequestTarget requestTarget) { | ||
this.rawPath = rawPath; | ||
this.requestTarget = requestTarget; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "RequestTargetWithRawPath{" + | ||
"rawPath='" + rawPath + '\'' + | ||
", requestTarget=" + requestTarget + | ||
'}'; | ||
} | ||
} | ||
|
||
private static RequestTargetWithRawPath forServer(String rawPath) { | ||
return forServer(rawPath, false); | ||
} | ||
|
||
@Nullable | ||
private static RequestTarget forServer(String rawPath, boolean allowSemicolonInPathComponent) { | ||
final RequestTarget res = DefaultRequestTarget.forServer(rawPath, allowSemicolonInPathComponent, false); | ||
if (res != null) { | ||
logger.info("forServer({}) => path: {}, query: {}", rawPath, res.path(), res.query()); | ||
private static RequestTargetWithRawPath forServer(String rawPath, boolean allowSemicolonInPathComponent) { | ||
final RequestTarget target = DefaultRequestTarget.forServer( | ||
rawPath, | ||
allowSemicolonInPathComponent, | ||
false); | ||
if (target != null) { | ||
logger.info("forServer({}) => path: {}, query: {}", rawPath, target.path(), target.query()); | ||
} else { | ||
logger.info("forServer({}) => null", rawPath); | ||
} | ||
return res; | ||
return new RequestTargetWithRawPath(rawPath, target); | ||
} | ||
|
||
@Nullable | ||
private static RequestTarget forClient(String rawPath) { | ||
private static RequestTargetWithRawPath forClient(String rawPath) { | ||
return forClient(rawPath, null); | ||
} | ||
|
||
@Nullable | ||
private static RequestTarget forClient(String rawPath, @Nullable String prefix) { | ||
final RequestTarget res = DefaultRequestTarget.forClient(rawPath, prefix); | ||
if (res != null) { | ||
logger.info("forClient({}, {}) => path: {}, query: {}, fragment: {}", rawPath, prefix, res.path(), | ||
res.query(), res.fragment()); | ||
private static RequestTargetWithRawPath forClient(String rawPath, @Nullable String prefix) { | ||
final RequestTarget target = DefaultRequestTarget.forClient(rawPath, prefix); | ||
if (target != null) { | ||
logger.info("forClient({}, {}) => path: {}, query: {}, fragment: {}", | ||
rawPath, prefix, target.path(), | ||
target.query(), target.fragment()); | ||
} else { | ||
logger.info("forClient({}, {}) => null", rawPath, prefix); | ||
} | ||
return res; | ||
return new RequestTargetWithRawPath(null, target); | ||
} | ||
|
||
private static String toAbsolutePath(String pattern) { | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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