Skip to content

L16 Clients and redirects

19 minSuggested first: L15 Input validation and dependencies

Outcome

Separate request preparation from sending and trace a redirect under a given policy.

Learn

An HTTP client may combine per-call options with defaults, prepare a request, and choose a transport. A redirect response can make the client create another request. For each hop, check the status, the Location, the method, and the origin. An origin is the scheme, host, and port together.

Don't assume all redirect codes, clients, or credential types behave alike.

Worked example

The client sends POST https://a.example/submit and gets a 303 with Location: https://b.example/receipt. What is the next request?

A toy client's redirect policyText
prepare POST → send → 303 Location on a different origin
apply toy redirect policy → prepare GET with no body
remove Authorization for changed origin → send next hop
Predict first, then show the worked explanation

Under this toy policy, a 303 after a POST makes the next request a GET to the new URL with no body, and a changed origin removes the Authorization header. So the next hop is GET https://b.example/receipt, without the original body or Authorization. Compare the general status semantics in RFC 9110.

Practice and check

Guided practice

Practice, not scored

A 303 sends the client from https://a.example/submit to http://a.example/receipt: the same host, over plain HTTP. Under the toy policy, what happens to Authorization?

Choose one answer

Exit check

Counts toward completion

Now the Location is /receipt, on the same origin. Under the toy policy, what is the next request?

Choose one answer

Common mistake

Treating a redirect as a retry. A redirect follows a response and may change the target or the method; a retry makes another attempt at the same operation.

Practice on a real repository

Start with the first puzzle below, then try the second.

Related topics: HTTP clients

Practice is optional. Solving a puzzle doesn't complete a lesson, and lessons never change a puzzle's points.

References