Skip to content

Conversation

@mleonhard
Copy link

This PR is a fix for #47 .

RFC 7230 says that ordinary HTTP requests must use the /path?query part of the URL, excluding the http://host part:

5.3.1. origin-form

The most common form of request-target is the origin-form.

origin-form    = absolute-path [ "?" query ]

When making a request directly to an origin server, other than a
CONNECT or server-wide OPTIONS request (as detailed below), a client
MUST send only the absolute path and query components of the target
URI as the request-target. If the target URI's path component is
empty, the client MUST send "/" as the path within the origin-form of
request-target. A Host header field is also sent, as defined in
Section 5.4.

For example, a client wishing to retrieve a representation of the
resource identified as

 http://www.example.org/where?q=now

directly from the origin server would open (or reuse) a TCP
connection to port 80 of the host "www.example.org" and send the
lines:

GET /where?q=now HTTP/1.1
Host: www.example.org

followed by the remainder of the request message.

It looks like we're sending the absolute-form url http://127.0.0.1:3000/ when we want to send the origin-form url /.
We're also omitting the port number in the Location header.

Send the request:

% rewrk -c 1 -d 1s -h http://127.0.0.1:3000/
Beginning round 1...
Benchmarking 1 connections @ http://127.0.0.1:3000/ for 1 second(s)
No requests completed successfully

%

Capture the request:

% nc -l 3000
GET http://127.0.0.1:3000/ HTTP/1.1
host: 127.0.0.1

%

This PR removes the scheme and authority parts of the URI that we send in the HTTP request line. A URL with only the path and query parts is an origin-form URL.

@ChillFish8
Copy link
Member

I would be curious to see if there is a reason why Hyper doesn't do this automatically, I know it does this on HTTP/2 so it strikes me as odd that it isn't specifically done for HTTP/1.1 as well.

@mleonhard
Copy link
Author

@ChillFish8 Would you be interested in merging this PR or sharing some feedback on how to move forward with it?

@ChillFish8
Copy link
Member

@mleonhard sorry this is my bad and should have been more clear. I wanted to know why Hyper doesn't do this automatically when it does this for HTTP2 as it makes me believe it is not as simple as always including the origin in the URL request line. Do you have any information on this and if there are any edge cases to this change?

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.

2 participants