Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Ignore everything but path and query in requests for absolute URIs (#666). #711

Closed
wants to merge 2 commits into from

Conversation

cesarblum
Copy link
Contributor

if (requestUrlPath.Length > 0 && requestUrlPath[0] != '/')
{
Uri uri;
if (Uri.TryCreate(requestUrlPath, UriKind.Absolute, out uri))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not optimal but I don't see the need to optimize for this case - requests for absolute URIs are not expected to be the norm. So most of the time we won't be running this.

Copy link
Member

Choose a reason for hiding this comment

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

System.Uri can't be used, it does lots of its own escaping and un-escaping. I think your three interesting cases are:

  • Starts with / if it's a path
  • * for OPTIONS
  • starts with http:// or https:// if its absolute, skip to the first / or ? after the scheme separator

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. I'll address OPTIONS * in a subsequent PR.

@@ -804,8 +804,43 @@ protected bool TakeStartLine(SocketInput input)
QueryString = queryString;
HttpVersion = httpVersion;

bool caseMatches;
if (requestUrlPath.Length > 0 && requestUrlPath[0] != '/')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Again, this is an edge case and I don't see the need to optimize this path.

Copy link
Member

Choose a reason for hiding this comment

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

what happens for requestUrlPath.Lenght == 0? That shouldn't be valid either.

Copy link
Member

Choose a reason for hiding this comment

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

Add a comment and RFC link for the scenario you're handling, and the fact that you're ignoring the scheme and host at the moment.

@Tratcher
Copy link
Member

The URL processing looks OK. @halter73 how about the 400 response?

int pathIndex = requestUrlPath.IndexOf('/', hostIndex);
if (pathIndex == -1)
{
int queryIndex = requestUrlPath.IndexOf('?', hostIndex);
Copy link
Member

Choose a reason for hiding this comment

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

Isn't the query string already removed from requestUrlPath?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Totally overlooked that.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, looking at the code that brings up an interesting point. pathBegin and pathEnd are now the wrong name, it should be urlBegin or targetBegin. Similar for requestUrlPath.

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, I'm renaming those.

@halter73
Copy link
Member

I wonder if we should take this opportunity to return a 400 for non HTTP/1.1 or HTTP/1.0 requests.

@Tratcher
Copy link
Member

Or 505 HTTP Version Not Supported ? https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

@cesarblum
Copy link
Contributor Author

We've decided this should be handled after RC2, since it's an edge case. We can more adequately handle this scenario, as well as #709, once we implement #594.

@cesarblum cesarblum closed this Mar 24, 2016
@cesarblum
Copy link
Contributor Author

I'll file an issue for the wrong HTTP version too.

@cesarblum cesarblum deleted the cesarbs/abspath-ignore-host branch May 19, 2016 21:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants