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

Fix URL parsing issue (#391) #393

Merged
merged 3 commits into from
Apr 5, 2019

Conversation

mikkokar
Copy link
Contributor

Fixes issue #391.

The sample URI from #391 is incorrectly exposed to the interceptor chain:

  • Sample URI: https://test.homeaway.co.uk//www.homeaway.co.uk/p6873759
  • The origin-form of the request is: //www.homeaway.co.uk/p6873759
  • The path component exposed to the plugins is: /p6873759
  • The request is proxied correctly.

Root cause: Styx calls Java URI.create which fails to parse the URI in its origin form. The problem disappears when we temporarily convert the URI to its absolute-form before calling URI.create.

@mikkokar mikkokar requested review from kvosper and dvlato March 29, 2019 07:51
@mikkokar
Copy link
Contributor Author

FYI @taer . Please give this a go if you can.

@@ -121,7 +121,7 @@ public boolean isFullyQualified() {
* @return true if the URL is absolute.
*/
public boolean isAbsolute() {
return path.startsWith("/");
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this method used for? We have changed from it's an absolute path to i_t's an absolute URI_ . What's the real purpose?

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 can only guess. I believe the original intention was to determine if the request is in origin-form or absolute-form. My gut feeling is that we don't really need this method in the URL class.

As to why this change? It is because every path component always starts with / therefore it always returned true.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would at least mark it as deprecated then. I think from previous discussions our goal could be to completely remove Url from the API.

@@ -222,17 +221,23 @@ public void throwsBadRequestExceptionWhenRequestMessageContainsMoreThanOneHostHe

@Test
public void callsTheEscaperForUnwiseChars() throws Exception {
UnwiseCharsEncoder encoder = mock(UnwiseCharsEncoder.class);
AtomicBoolean encoderCalled = new AtomicBoolean();
UnwiseCharsEncoder encoder = x -> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why replace mocking with this approach?

Copy link
Contributor

Choose a reason for hiding this comment

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

I meant to comment on the same to be honest... I think keeping mock.verify() would make our code a bit more uniform.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By mistake. I have backed off this change.

}

@Test
public void decodesOriginFormWithLowercaseHostHeader() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This test is identical to the one below and the first test in the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually it is different from the first test in the file. See the header case. But I have now made it different from the test below.

@Test
public void decodesOriginFormWithUppercaseHostHeader() {
DefaultFullHttpRequest request = new DefaultFullHttpRequest(HTTP_1_1, GET, "/foo");
request.headers().add("host", "example.com");
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be uppercase?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it should.


public class UrlDecoderTest {
@Test
public void decodesOriginForm() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This test is redundant

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 have made some changes to the test files. Please have another look.

}

@Test
public void decodesOriginFormIssue391() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is using the issue number in the name of the test something we usually do? I would still have a name that tried to explain the issue though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed. Let's describe the scenario in an issue-agnostic way for the test name, then maybe add the issue link in a comment above the test.

@mikkokar
Copy link
Contributor Author

Thanks for your comments @kvosper and @dvlato! I will address them soon.

@mikkokar mikkokar merged commit 23b00c1 into ExpediaGroup:master Apr 5, 2019
@mikkokar mikkokar deleted the issue-391-url-parsing branch April 5, 2019 08:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants