A Redirect Is Two Exchanges
A 301 answers one request with a Location field and no body; the client then sends a second request to that target, here on the same connection.
The question
A redirect is not one exchange. The server answers the first request with a status in the 300s and a place to look; the client has to send a second request. In the recording of this book (curl 8.5.0 with the option -L, the scripted server lmmock 0.1.0, loopback, 2026-11-21), what does the second request look like, and where did its path come from?
Work it by hand
RFC 9110, section 15.4.2, says that a 301 response should carry a Location field and that a user agent MAY use its value for automatic redirection. Section 10.2.2 says that a relative Location is resolved against the target URI of the request. RFC 9112, section 3.2.1, says that a client sends only the path and query of the target in the request line.
Take a constructed pair that no case uses: the request GET /docs HTTP/1.1 and the answer HTTP/1.1 301 Moved Permanently with Location: /docs/. The next request line is GET /docs/ HTTP/1.1: same method, new path. With the field Location: http://www.example.test/docs/ the line is the same, because the scheme and the host are not part of the request line.
Run it
The demo reads the four segments of connection 2, the -L follow.

Watch the steps (recorded video)
let lines = str_split(segments, "\n");
let m = str_list(); let loc = ""; let asked = "";
for (k in range(0, lines.len())) {
let p = str_split(lines.at(k), "|");
let text = ssl.unhex(p.at(2));
let first = str_split(text, "\r\n").at(0);
if (p.at(1) == "s2c") {
let at = str_find(text, "Location: ");
let note = "";
if (at >= 0) {
let rest = str_substr(text, at + 10, str_len(text) - at - 10);
loc = str_split(rest, "\r\n").at(0);
note = "Location: " + loc;
}
m.add("1>0|" + first + "|" + note);
} else {
if (k > 0) { asked = str_split(first, " ").at(1); }
m.add("0>1|" + first + "|");
}
}
let answer = asked == loc && loc != "";
lmcode_return_put("messages", m);
lmcode_return_put("location", loc);
lmcode_return_put("next_target", asked);
{
"answer": true,
"messages": [
"0>1|GET /old HTTP/1.1|",
"1>0|HTTP/1.1 301 Moved Permanently|Location: /hello",
"0>1|GET /hello HTTP/1.1|",
"1>0|HTTP/1.1 200 OK|"
],
"location": "/hello",
"next_target": "/hello"
}Lines 7 to 15 handle a response: line 8 looks for the field and lines 11 and 12 keep its value. Line 17 takes the second word of every request line after the first, its target. The answer on line 21 is true when that target equals the last Location seen. The server answered HTTP/1.1 301 Moved Permanently with Location: /hello, and the second request asked for /hello on the same connection: RFC 9112, section 9.3, says that HTTP/1.1 defaults to persistent connections.
You can change segments. A line with fewer than three parts stops the run with "StrList.at: index out of range: 2"; bytes that are not hex with "Ssl.unhex: invalid hex digit"; a request line without a second word with "StrList.at: index out of range: 1". Only the last request counts: a list that ends with a request for /old again gives false (measured).
Your turn
The program below should return the request line that a client sends after a redirect. Several candidate programs are offered. Read them, run them on pairs of messages of your own, and decide which of them is right for every pair. Every message in the cases is constructed, with the fields curl sends; the picture says so.

let method = "GET";
let text = ssl.unhex(redirect);
let at = str_find(text, "Location: ");
let rest = str_substr(text, at + 10, str_len(text) - at - 10);
let value = str_split(rest, "\r\n").at(0);
let target = value;
if (str_substr(value, 0, 7) == "http://") {
let tail = str_substr(value, 7, str_len(value) - 7);
target = str_substr(tail, str_find(tail, "/"), str_len(tail));
}
let answer = method + " " + target + " HTTP/1.1";
lmcode_return_put("location", value);
{
"answer": "GET /docs/start HTTP/1.1",
"location": "/docs/start"
}Return the request line that the client sends next after the redirect, as text such as GET /x HTTP/1.1. The hex input first_request is the request the client sent and redirect is the 3xx response with a Location field. The client uses the same method, version HTTP/1.1 and the same host, and puts the path of the Location value in the request line (RFC 9112 origin-form: only the path, never the scheme or the host). The Location value is either a path that starts with / or an address on the same host, written http://www.example.test followed by a path. Check runs your program on this redirect and on four others.
Read the result carefully
The recording shows what curl did with one 301 from this script. RFC 9110 gives user agents a MAY: a client may follow the Location or stop, and for POST the RFC allows a change of method, which this lesson does not model. The cases never use POST, and the Location is only a path or an address on the same host. A Location with another host, a fragment, or a relative path such as ../b is not covered.
The server is a script with a fixed route, not a model of real sites. The Host field of the second request was the same as the first, www.example.test, which nothing resolved. For the same exchange over constructed messages only, see Redirect Gives a New Location.
Recap
- A redirect response carries a status in the 300s and a Location field; here 301 had no body.
- The client's next request is a new message, here on the same connection.
- The request line holds the method and the path of the Location, not the host.
- A recording shows what one client did; the RFC says a client MAY follow.