Skip to content
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
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

yzfeng2020
Copy link
Contributor

@yzfeng2020 yzfeng2020 commented Oct 2, 2024

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:

  • Added a rawPath in RequestTarget to store the rawPath.
  • The rawPath is from the unmodified ':path' header at the server side; the client side target, it's always null.

Result:

@yzfeng2020 yzfeng2020 changed the title add rawPath to RequestTarget Introduce rawPath in RequestTarget Oct 2, 2024
@@ -645,7 +654,9 @@ private static RequestTarget slowForClient(String reqTarget,
null,
-1,
encodedPath,
encodedPath, encodedQuery,
encodedPath,
encodedPath,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh I am not sure what's the best behavior for client, I just reuse the encodedPath

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer using reqTarget, the original value we get from :path header.

@yzfeng2020
Copy link
Contributor Author

hoping to get some feedbacks!

@yzfeng2020 yzfeng2020 marked this pull request as ready for review October 2, 2024 09:26
@yzfeng2020
Copy link
Contributor Author

@ikhoon I hope to get some feedbacks thanks!

@ikhoon ikhoon added this to the 1.31.0 milestone Oct 8, 2024
Copy link
Contributor

@ikhoon ikhoon left a 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.

assertThat(res).isNotNull();
assertThat(res.query()).isEqualTo("a=..=" + qs + "b=..=");
assertThat(QueryParams.fromQueryString(res.query(), true)).containsExactly(
assertThat(res.requestTarget).isNotNull();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also write e2e tests to verify that rawPath is correctly preserved?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, added a new e2e test!

@ikhoon
Copy link
Contributor

ikhoon commented Oct 8, 2024

Please address the line failure.

Error: eckstyle] [ERROR] /home/runner/work/armeria/armeria/core/src/test/java/com/linecorp/armeria/internal/common/DefaultRequestTargetTest.java:660:16: Variable 'pathInTarget' should be declared final. [FinalLocalVariable]

@yzfeng2020 yzfeng2020 force-pushed the add-raw-path branch 3 times, most recently from 144b37f to 9d460f4 Compare October 22, 2024 04:35
/**
* 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}.
Copy link
Member

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)

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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

TEST_URLS.add("/%3A%2F%3F%23%5B%5D%40%21%24%26%27%28%29*%2B%2C%3B%3D");
}

@Test
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sg, will update

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Introduce rawPath in RequestTarget
3 participants