
Redirects in Go and the Right Status Code to Use for Each
Pick between 301, 302, 303, 307 and 308 in Go with http.Redirect, see which keep the method and body, and avoid open redirects from a query value.
Tag
15 articles

Pick between 301, 302, 303, 307 and 308 in Go with http.Redirect, see which keep the method and body, and avoid open redirects from a query value.

Reproduce the errors Go HTTP servers and clients print, from address already in use to HTTP response to HTTPS client, and see what each message means.

Add retries to a Go HTTP client as a RoundTripper with exponential backoff and jitter, Retry-After, body replay and a rule for which requests are safe.

Build an in-memory response cache for Go handlers with keys, a TTL, Vary awareness, a singleflight stampede guard and rules for what must never be cached.

Twelve mistakes in Go HTTP servers that pass code review and fail under load or attack, each with the symptom, a reproduction where one fits, and the fix.

Serve net/http/pprof from a separate loopback listener with a token, avoid the DefaultServeMux trap, and fix the WriteTimeout error on CPU profiles.

How Go's HTTP client reads HTTP_PROXY, HTTPS_PROXY and NO_PROXY, which hosts it never proxies, why runtime changes are ignored, and how to set one yourself.

Walk through every http.Transport field that matters in production, with the default value, what changing it does and measured effects of connection limits.

Write one small notes API twice, with net/http and with gin, and compare the code you write, where the behavior differs and what the framework really saved.

Build a server sent events endpoint in Go with flushing, event ids, Last-Event-ID resume, heartbeats and clean shutdown, and see the wire format it sends.

A one page Go HTTP cheat sheet: server settings, routing, JSON helpers, middleware, shutdown, a safe client, status codes and headers, all run together.

See when the Go HTTP client reuses a connection and when it dials a new one, using httptrace, and how idle timeouts and Connection close change that.