Media type of the body, optionally with a charset.
Content-Type: application/json; charset=utf-8
What to test
Assert responses declare the right type (application/json, application/problem+json for errors). Send requests with a wrong or missing Content-Type and expect 415. Error pages from proxies often come back as text/html.
Check export endpoints set attachment with a sensible filename, non-ASCII names use filename*, and user-supplied names cannot inject quotes or path separators.
Send Accept: application/xml to a JSON-only API: expect 406 or documented fallback. Versioned media types (application/vnd.example.v2+json) should select the right version.
Credentials for the request (Basic, Bearer, etc.).
Authorization: Bearer eyJhbGciOiJSUzI1NiJ9...
What to test
Test missing, malformed, expired and wrong-audience tokens (expect 401), and valid tokens lacking scope (expect 403). Make sure the header is not logged and not forwarded on cross-host redirects.
Responses with personal data or tokens must be no-store (or at least private). Public, cacheable resources should have a deliberate max-age. Check CDN behaviour matches.
Must not blindly reflect any Origin when credentials are allowed. "*" cannot be combined with credentials. Include Vary: Origin when the value depends on the request.
If the frontend reads Location, ETag or rate limit headers, they must be exposed; otherwise they appear null in the browser even though curl shows them.
Session cookies need Secure, HttpOnly and SameSite (Lax or Strict). SameSite=None requires Secure. Check Max-Age/Expires, Domain scope, and that logout clears the cookie.
Current remaining quota and reset time for a policy. IETF draft.
RateLimit: "default";r=42;t=30
What to test
Remaining (r) should decrease by one per request and the reset (t) should count down. Older drafts used separate RateLimit-Limit/-Remaining/-Reset headers.
Send a known trace id from your test and confirm it appears in the tracing backend, linking test failures to server traces. Malformed values must be ignored, not cause errors.
Retry the same request with the same key: one side effect, same response. Same key with a different body: expect 422 (or 409). Check how long keys are remembered.
Original client IP and protocol as seen by proxies.
X-Forwarded-For: 203.0.113.7, 10.0.0.2
What to test
Send a spoofed value directly and check rate limiting, IP allow-lists and audit logs do not trust it from untrusted hops.
RFC 7239 (Forwarded); X-Forwarded-For is de-facto
Informazioni sullo strumento
Gli header determinano gran parte del comportamento di un’API: regole di caching, optimistic locking, permessi CORS, sicurezza dei cookie, rate limit e trace id. Questo riferimento elenca quasi sessanta header che emergono nel testing delle API, ciascuno con direzione, scopo, un esempio realistico, cosa testare e la specifica che lo definisce. Gli header ancora in bozza IETF, come RateLimit, RateLimit-Policy e Idempotency-Key, sono indicati come draft perché la loro sintassi può ancora cambiare; le convenzioni diffuse ma senza RFC, come X-Request-Id e X-RateLimit-*, sono indicate come standard de facto.
Come si usa
Cerca un header o un argomento come “cors”, “cookie” o “cache”.
Filtra per direzione (richiesta o risposta) o per categoria.
Copia la riga d’esempio nella tua richiesta, oppure usa la nota “What to test” come spunto per un’asserzione. Ogni header ha un link ad ancora.
Riferimento header HTTP: domande frequenti
Perché curl vede un header di risposta ma il mio codice nel browser no?
Il JavaScript cross-origin può leggere solo gli header di risposta nella safelist CORS, a meno che il server non ne elenchi altri in Access-Control-Expose-Headers. Location, ETag e gli header personalizzati spesso mancano da quell’elenco.
Quali header di sicurezza dovrebbe inviare un’API JSON?
Come minimo Strict-Transport-Security su HTTPS e X-Content-Type-Options: nosniff, più Cache-Control: no-store sulle risposte che contengono dati personali o token. Una Content-Security-Policy restrittiva è un rafforzamento aggiuntivo a costo quasi nullo. Evita di esporre le versioni in Server e X-Powered-By.
I nomi degli header distinguono maiuscole e minuscole?
No. I nomi dei campi header HTTP non distinguono tra maiuscole e minuscole, e HTTP/2 e HTTP/3 li inviano in minuscolo. Scrivi asserzioni che confrontino i nomi senza distinguere le maiuscole; la maggior parte dei client, compreso response.headers() di Playwright, li normalizza in minuscolo.