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

Don't assume port 80 when generating nextLink in ASP.NET Core #1559 #1560

Conversation

andrewlock
Copy link
Contributor

@andrewlock andrewlock commented Aug 3, 2018

Issues

This pull request fixes issue #1559

Description

Don't explicitly set a port when generating the nextLink

If the port isn't set on request.Host, port 80 was assumed previously. If the app is running behind a reverse proxy, and the port was not forwarded, this can result in invalid URLs - for example an HTTPS URL using port 80. Instead, we just omit the port completely if it's not explicitly set.

Checklist (Uncheck if it is not completed)

  • Test cases added
  • Build and test with one-click build and test script passed

Additional work necessary

Unfortunately, I couldn't build the repo after cloning (Could not load file or assembly 'Microsoft.Build, Version=14.0.0.0), and there are no existing tests for HttpRequestExtensions as far as I can see, so I haven't tried to add any.



If the port isn't set on `request.Host`, port 80 was assumed previously.
If the app is running behind a reverse proxy, and the port was not forwarded,
this can result in invalid URLs - for example an https URL using port 80
Instead, we just omit the port completely if it's not explictly set.
@biaol-odata
Copy link
Contributor

LGTM

@biaol-odata
Copy link
Contributor

The underlying ASP.NET Core issue https://github.com/aspnet/BasicMiddleware/issues/204 is being re-triaged.

@andrewlock
Copy link
Contributor Author

Just in my opinion, even if the underlying issue is fixed, I feel like the code is more-correct after the PR, as it does not assume any specific port to use for link generation.

@biaol-odata
Copy link
Contributor

@andrewlock Thanks for your contribution. We looked at the PR in today's team meeting, the code looks good. As general, we usually require test coverage for code. Can you please add some simple test? Thanks!

Copy link
Contributor

@biaol-odata biaol-odata left a comment

Choose a reason for hiding this comment

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

please add test code coverage. Thanks.

@andrewlock
Copy link
Contributor Author

I'll do my best, could take a while as I can't build the solution or run any tests (Could not load file or assembly 'Microsoft.Build, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified., so will be trial and error with the CI...

@biaol-odata
Copy link
Contributor

@andrewlock I think ASP.NET Core version of WebApi requires VS 2017. Are you using VS2017?

@msftclas
Copy link

msftclas commented Aug 10, 2018

CLA assistant check
All CLA requirements met.

@andrewlock
Copy link
Contributor Author

@biaol-odata , yes I am - I found the solution files eventually! It's the build.cmd that's failing to run on my machine.

Given that all your readme states under "Build" is build.cmd, it's not very friendly to newcomers unfortunately 🙂

I've added some unit tests that cover general link generation (similar to the tests of the non-core ASP.NET) and some tests for this specific case.

Copy link
Contributor

@biaol-odata biaol-odata left a comment

Choose a reason for hiding this comment

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

nit: can you also please add copy right header (refer to other files)?

public void GetNextPageLink_UsesPortWhenDefaultPortIsProvided(string requestUri, int pageSize, string nextPageUri)
{
// Arrange
// The RequestFactory removes the default port, so we explicitly add it
Copy link
Contributor

Choose a reason for hiding this comment

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

For this case, when the port specified in uri is same as the default value. request.Host is formalized, so we add it back, and the generated linked is still the one w/o port number?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah - UriBuilder formalizes the uri inside GetNextPageLink() too. Which is absolutely fine, the problem before was that in these cases, port 80 would be enforced, even if it was https!

@andrewlock
Copy link
Contributor Author

Copyright added 👍

@biaol-odata biaol-odata merged commit ecc4a0d into OData:master Aug 10, 2018
@biaol-odata
Copy link
Contributor

Merged. Closed.

@andrewlock andrewlock deleted the fix-assuming-port-80-when-generating-https-links branch August 10, 2018 22:28
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.

None yet

5 participants