rewrk icon indicating copy to clipboard operation
rewrk copied to clipboard

Send origin-form URL in HTTP request line.

Open mleonhard opened this issue 6 months ago • 3 comments

This PR is a fix for https://github.com/lnx-search/rewrk/issues/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.

mleonhard avatar Jun 23 '25 21:06 mleonhard