HTTP
Methods, status codes, header fields, caching validators, connection reuse and what HTTP/2 and HTTP/3 changed on the wire. Interviewers start here because most backend answers end in an HTTP detail.
on this pageshowhide
guide
overview
~1 minHTTP is the request-response protocol under nearly every web page, API call and service-to-service hop. Interviewers use it as a baseline: whatever a backend answer is about, it tends to end in a method, a status code or a header field, and a candidate who knows what the specification promises is easier to trust than one who knows only what a framework does by default. The hub splits along the anatomy of a message and the connection beneath it. [Methods and status codes](/topics/proto-http-methods-status) are the vocabulary of intent and outcome. [Headers and metadata](/topics/proto-http-headers) describe the message itself, including how its body is framed. [Content negotiation](/topics/proto-http-content-negotiation) lets one URL serve several representations, and [caching and conditional requests](/topics/proto-http-caching) decide when a stored response may be reused and when an edit must be refused. [Cookies](/topics/proto-http-cookies) and the [authentication framework](/topics/proto-http-auth-framework) are how state and identity ride on a stateless protocol. Under the messages, [connections and keep-alive](/topics/proto-http-connections) covers the sockets HTTP/1.1 reuses and the timeouts around them, and [binary framing versions](/topics/proto-http-http2-http3) explains what HTTP/2 and HTTP/3 changed on the wire while leaving the meaning of a request alone. Junior rounds check definitions: which methods are idempotent, what a status class tells a client, what a cookie attribute restricts. Senior rounds turn to failures that surface as HTTP — a retried payment charged twice, a CDN handing one user's page to another, resets that appear only after a quiet period, a proxy and an application server that frame the same bytes differently — and expect you to say which layer is at fault before proposing a fix. Start with methods and status codes, then headers; every other section is written in their terms. Caching and connections come next, and HTTP/2 and HTTP/3 make sense only once the limits of an HTTP/1.1 connection are clear.
primer
### Semantics are separate from the wire HTTP defines messages — a method, a target, header fields, an optional body, a status — independently of how they travel. HTTP/1.1 writes them as text on a TCP connection, HTTP/2 as binary frames over TCP, HTTP/3 as frames over QUIC. A 404 or an `ETag` means the same thing in all three. Keeping the layers apart settles many version questions: a change to framing or transport does not change what a method promises or what a status asserts. ### Methods make promises to software you do not own A method is more than a routing key. **Safe** and **idempotent** are properties that crawlers, caches, proxies and client libraries rely on without knowing your application: links get followed because GET is expected to be harmless, and some requests get retried automatically because repeating them should not change the outcome. The promise concerns what the server ends up holding, not what it answers, and nothing in the protocol enforces it — your handler keeps it or breaks it. ### Status codes are read by class first The first digit carries the meaning every client must act on: interim, success, redirect, client fault, server fault. Specific codes refine it — who is failing, whether a retry could help, whether credentials would change anything. Interviewers probe the pairs that are easy to swap: 401 against 403, 301 against 302 and their method-preserving siblings, 502 against 504, 406 against 415. ### Headers carry most of the protocol Framing, caching, negotiation, cookies, authentication and connection control all live in fields. Knowing which fields steer the message, which describe the representation and which apply to a single hop explains a whole class of production bugs — including the ones that never reach application logs, because a proxy or the server's parser rejected the message first. ### A URL names a resource, not a byte sequence What travels is a **representation**, chosen by media type, language or encoding. That is why negotiation, `Vary`, compression and validators belong together: a cache must know which variant it holds, and a validator identifies one version of one representation, not the resource in the abstract. ### Caching is freshness plus validation A stored response is reused without asking while it is fresh, and checked with the origin once it is not. The validators that make revalidation cheap also make writes safe: a conditional request lets the server refuse an edit computed from a version the client no longer holds. The costly caching mistakes are usually about **who** may store a response rather than for how long. ### State and identity are resent, not remembered HTTP keeps no session. Cookies and the `Authorization` field supply continuity by carrying a value on every request, so each hardening attribute and each scheme answers one question: who else could obtain that value, and what could they do with it? ### Connections cost more than requests A new connection costs round trips and CPU; reusing one brings pools, idle timeouts and head-of-line blocking. HTTP/2 multiplexes streams over one TCP connection, which ends queueing between requests but not TCP's in-order delivery; HTTP/3 moves to QUIC so that one lost packet no longer stalls unrelated streams. A strong answer names the layer a delay lives in before naming the fix.
- Resource
- Whatever a URL identifies. It is never transferred itself; each response carries one representation of it.
- Representation
- The bytes plus metadata that reflect a resource's state at one moment, in one media type, language and content coding.
- Safe method
- A method through which the client requests no change to server state, such as GET or HEAD. Servers may still log or count such requests.
- Idempotent method
- A method whose repeated identical requests have the same intended effect on server state as one request, even when the responses differ.
- Hop-by-hop field
- A header field that applies only to one connection, such as Connection or Keep-Alive. Proxies consume and remove it instead of forwarding it.
- Message framing
- How a recipient finds where a body ends: Content-Length, chunked transfer coding or connection close in HTTP/1.1; frame boundaries in HTTP/2 and HTTP/3.
- Freshness lifetime
- How long a stored response may be reused without contacting the origin, set by max-age, s-maxage or Expires, or estimated heuristically when absent.
- Validator
- A value identifying one version of a representation, either an ETag or a Last-Modified date, compared in conditional requests.
- Shared cache
- A cache that serves many users, such as a CDN or reverse proxy, as opposed to the private cache inside one browser.
- Vary
- A response field listing the request headers that influenced the chosen representation, so caches include their values in the lookup key.
- Head-of-line blocking
- A stall in which one slow or lost item holds up independent items queued behind it, either at the HTTP layer or inside TCP.
- Stream
- In HTTP/2 and HTTP/3, one request-response exchange with its own identifier, interleaved with other streams on a single connection.
- ALPN
- A TLS extension through which client and server agree on the application protocol, such as h2 or http/1.1, during the handshake.
- Authentication challenge
- A 401 or 407 response whose WWW-Authenticate or Proxy-Authenticate field names the schemes the sender will accept credentials in.
- Bearer token
- A credential honoured on possession alone. Whoever presents it is treated as authorized, so keeping it confidential is the entire protection.
Follow one request. The client takes a connection from its pool or opens a new one — TCP and TLS for HTTP/1.1 and HTTP/2, QUIC for HTTP/3 — and the version is settled by ALPN during the TLS handshake or by an advertisement the origin sent earlier. It then sends a method and a target plus fields: `Host` for the site, `Accept` and `Accept-Encoding` for what it can use, a cookie or an `Authorization` value for identity, and perhaps a validator for a copy it already holds. On the way, a browser cache, a CDN and a reverse proxy may each answer from storage, forward the request, or reject it before the application ever runs. The origin selects a representation, evaluates any precondition, and replies with a status, fields describing its choice and how long the result may be reused, and a body framed so the recipient knows where it stops. Heading back, every cache decides whether to store the response and under which key; the client decodes the body, keeps any cookies, and returns the connection to the pool — or discards it when framing, an error or an idle timeout makes reuse unsafe. One revalidation shows several sections meeting: ```http GET /api/orders/42 HTTP/1.1 Host: api.example.com Accept: application/json Accept-Encoding: br, gzip Authorization: Bearer eyJhbGciOi... If-None-Match: "v7" HTTP/1.1 304 Not Modified ETag: "v7" Cache-Control: private, max-age=60 Vary: Accept, Accept-Encoding ``` The 304 carries no body, yet it restates the validator and the caching policy: `private` keeps a per-user answer out of the CDN, and `Vary` records that the choice depended on negotiation fields. Over HTTP/2 or HTTP/3 the exchange means exactly the same; only the encoding of these lines and the connection underneath differ.
- Methods and Status Codes →
The vocabulary of intent and outcome: what each verb promises and what each status class tells a client to do next.
- Headers and Metadata →
How a message describes itself and where its body ends; every later section is expressed in header fields.
- Caching and Conditional Requests →
Freshness, validators and preconditions: when a stored response may be reused and how conditional writes stop lost updates.
- Connections and Keep-Alive →
What a socket costs and how HTTP/1.1 reuses it, including the timeout and retry failures seen in production.
- Binary Framing Versions →
What binary framing and QUIC changed beneath unchanged semantics; it assumes HTTP/1.1's connection limits are already clear.
- Cookies →
How state rides on a stateless protocol, and the attributes that decide which requests carry a cookie and who can read it.
Treating idempotency as "the same response every time": it constrains the server's resulting state, so a repeated DELETE may legitimately return a different status.
Retrying any request after a timeout: the server may have completed it, so only idempotent operations, or failures proving nothing ran, are safe to repeat.
Answering 403 when credentials are missing, or sending 401 without
WWW-Authenticate; the distinction is whether different credentials could change the outcome.Reading
no-cacheas "do not store": it permits storage but requires revalidation before reuse, whileno-storeis the directive that forbids storing.Serving per-user responses without
private, or choosing a variant by a request header not listed inVary, so a shared cache hands one user's answer to others.Calling HTTP/2 the cure for head-of-line blocking: one lost TCP segment still stalls every stream — see QUIC over UDP.
Treating Base64 in Basic authentication as protection: it is an encoding, so without TLS the password crosses the network readable on every request.
Trusting the leftmost
X-Forwarded-Forentry as the client address: any client can write it, and only entries appended by your own proxies are reliable.Hunting in application logs for errors that appear only with large cookies or tokens; oversized header sections are refused by the edge before your code runs.
This guide assumes the current specification set published in 2022: RFC 9110 for semantics, RFC 9111 for caching, RFC 9112 for HTTP/1.1, RFC 9113 for HTTP/2 and RFC 9114 for HTTP/3, which runs on QUIC as defined in RFC 9000. Older material cites RFC 2616 (1999) or its 2014 replacement series, RFC 7230 to 7235; the semantics mostly carried over, so name the document when an answer rests on wording that changed. A few changes still come up in interviews: - **HTTP/1.0 to 1.1** made connections persistent by default and the `Host` field mandatory, which is what allowed many sites to share one address. - **RFC 9110** renamed some codes — 413 is now Content Too Large and 422 Unprocessable Content, the latter moved into the core specification. - **308 Permanent Redirect** was standardized in 2015 as the method-preserving counterpart of 301, mirroring what 307 does for 302. - **RFC 9113** deprecated HTTP/2's original stream-priority tree; the simpler replacement scheme applies to HTTP/2 and HTTP/3 alike. - **Server push** is defined for HTTP/2 but Chromium-based browsers have removed support, so treat it as history rather than a design option.
Interviewers expect you to place HTTP among the things built on it or chosen instead of it. **REST** is an architectural style that leans on HTTP's own semantics — resources, methods, status codes, caching — rather than a separate protocol. **gRPC** runs over HTTP/2 and uses it mainly as a transport for its own framed calls, trading browser reach and cache friendliness for typed contracts and efficient streaming. **GraphQL** usually funnels operations through a single endpoint, which gives up much of what URL-keyed caching and per-method semantics offer in exchange for client-shaped queries. **WebSockets** begin as an HTTP request and then leave request-response behind for a long-lived two-way channel. Reverse proxies, load balancers, CDNs and API gateways all act on HTTP semantics, which is why `Vary`, `private`, hop-by-hop fields and framing rules matter beyond your own server. For asynchronous work, message brokers replace HTTP rather than extend it: the choice is between a caller that waits for an answer and a producer that hands work off and moves on.
explore
- Methods and Status Codes33 questions
- Safety and Idempotency5 questions
- Verb-by-Verb Semantics4 questions
- Introspection and Tunneling Verbs4 questions
- Response Classes4 questions
- Redirect Semantics5 questions
- Client Errors6 questions
- Server Errors5 questions
- Headers and Metadata18 questions
- Field Categories3 questions
- Host and Authority4 questions
- Content-Length and Chunked Framing3 questions
- Custom and Extension Fields4 questions
- Field Size Limits4 questions
- Caching and Conditional Requests23 questions
- Cache-Control Directives5 questions
- Freshness vs Validation4 questions
- ETag and Last-Modified Validation3 questions
- Preconditions and Lost Updates3 questions
- Vary and Cache Keys5 questions
- Shared Caches and CDNs3 questions
- Connections and Keep-Alive21 questions
- Persistence and Pooling4 questions
- Head-of-Line Blocking and Pipelining4 questions
- Expect and 100 Continue4 questions
- Timeouts and Stale Sockets5 questions
- Redirect Mechanics4 questions
- Binary Framing Versions22 questions
- Streams and Multiplexing5 questions
- HPACK and QPACK4 questions
- Prioritization and Server Push4 questions
- QUIC over UDP4 questions
- Negotiation and Workload Fit5 questions
- Content Negotiation16 questions
- Accept Headers4 questions
- Quality Values3 questions
- Encoding and Compression5 questions
- 406 and 415 Failures4 questions
- Cookies15 questions
- Authentication Framework18 questions
- Challenge–Response Model4 questions
- Base64 Credential Scheme5 questions
- Digest Scheme4 questions
- Bearer Token Carriage5 questions
- AI Engineerroleanchors this topic
- Computer Scienceskillanchors this topic
- Data Engineerroleanchors this topic
- GraphQLskillanchors this topic
- Java SDETroleanchors this topic
- MLOps Engineerroleanchors this topic
- QA Engineerroleanchors this topic
- iOS Developerroleanchors this topic
- AI Red Teamingrole
- API Designskill
- API Testingskill
- Backend Developerrole
- Cyber Security Expertrole
- DevOps / SRE Engineerrole
- DevSecOps Engineerrole
- Frontend Developerrole
- Full Stack Developerrole
- Java Backend Developerrole
- Kotlin Backend Developerrole
- Network Engineerrole
- Software Architectrole
questions
166 · 8 sectionsIn HTTP, what is the difference between status 401 Unauthorized and status 403 Forbidden, and what header must a 401 response carry?
basics
~20 s401 means authentication is missing or invalid — the server asks "who are you?" and must send a WWW-Authenticate header. 403 means the identity is known (or irrelevant) and the request is still refused; retrying with credentials will not help.
What do the HTTP methods GET and POST actually mean on the wire, and what determines which one an operation should use?
basics
~20 sGET requests a representation of a resource — retrieval only, parameters in the URL, no intended side effects. POST asks the target resource to process the enclosed representation according to its own semantics — creating, submitting, or triggering work, with data in the body.
What does the HTTP HEAD method do, how must its response relate to the response a GET on the same URL would produce, and what should the Content-Length header say in a HEAD response?
basics
~20 sHEAD asks for exactly what GET would return, minus the response body. The status line and headers must match the GET response, so Content-Length states the size of the body that GET would have sent, even though HEAD sends zero bytes.
What is the difference between HTTP status 301 and HTTP status 302, and what does each one tell a browser, a cache, and a search engine to do?
basics
~20 sBoth send the client to the URL in the Location header. 301 Moved Permanently says the resource has a new home — clients and caches may store it indefinitely and search engines transfer ranking. 302 Found says it is temporary — keep using the original URL, and do not cache by default.
In HTTP, what does it mean for a request method to be "safe" versus "idempotent", and which of the standard methods have each property?
basics
~20 sSafe means the method is read-only: the client asks for nothing to change. Idempotent means sending the identical request many times leaves the server in the same state as sending it once. GET, HEAD, OPTIONS, TRACE are safe (and therefore idempotent); PUT and DELETE are idempotent but not safe; POST and PATCH are neither by definition.
HTTP/1.1 made the Host request header mandatory on every request. What problem does Host solve, and what is a server required to do when a request arrives with no Host header, or with two Host headers?
basics
~20 sHost names the target site, so one IP and port can serve many domains (name-based virtual hosting). Every HTTP/1.1 request must carry exactly one Host; a missing or duplicated Host must be answered with 400 Bad Request.
In HTTP/1.1, how does the receiver of a message know where the body ends, and what exactly does the Content-Length header field count?
basics
~20 sContent-Length states the body size in octets, so the receiver reads exactly that many bytes and stops. If it is absent, HTTP/1.1 can use Transfer-Encoding: chunked, where each chunk announces its own size and a zero-size chunk ends the body.
Walk through the wire format of an HTTP/1.1 message that uses Transfer-Encoding: chunked: how a chunk is written, how the body is terminated, and what trailer fields are for.
basics
~20 sEach chunk is its size in hexadecimal, CRLF, that many octets, CRLF. A chunk of size 0 ends the body. After the terminal chunk, optional trailer fields may appear (metadata such as a checksum computed only after streaming), then a final empty line.
Compare the HTTP Forwarded header defined by RFC 7239 with X-Forwarded-For and X-Forwarded-Proto, and explain how a service behind several proxies should determine the real client IP.
basics
~20 sForwarded is the standard single header carrying for, proto, host and by parameters; X-Forwarded-For and X-Forwarded-Proto are the de-facto split equivalents. All are client-spoofable, so trust only entries appended by proxies you control: count hops from the rightmost end, never take the leftmost value blindly.
Users report that your web app works in a fresh private browsing window but fails with an error page after they have been logged in for a while, and your application logs show nothing. How would you investigate, and what makes accumulated cookies or a large bearer token the likely cause?
basics
~20 sThat pattern means the request is rejected during header parsing, before the app runs. Cookies and token claims accumulate until the header section passes the server's ~8 KB cap, giving 400/431 or a reset. Measure header size at the edge, reproduce with curl, then shrink cookies and tokens.
Explain the difference between the HTTP response headers `Cache-Control: no-cache`, `Cache-Control: no-store` and `Cache-Control: must-revalidate`, and give a case where each is the right choice.
basics
~20 sno-store means never write this to any cache. no-cache means you may store it but must check with the origin before every reuse. must-revalidate means you may serve it freely while fresh, but once it expires you must revalidate rather than serve it stale. Use no-store for secrets, no-cache for always-current data, must-revalidate when stale answers are unacceptable.
In HTTP caching, what does it mean for a stored response to be fresh versus stale, and what is a cache allowed to do once a stored response goes stale?
basics
~20 sA stored response is fresh while its age is below its freshness lifetime; it can be reused with no network trip. Once age exceeds that lifetime it is stale — which does not mean deleted. The cache normally revalidates with the origin, and a successful check makes the copy usable again with a reset clock.
Two clients read the same HTTP resource, each edits it, and each sends a PUT. Both get 200 OK, but one client's edit has vanished. What happened, and what does HTTP offer to prevent it?
basics
~20 sThat is the lost update problem: the second PUT was computed from stale data and overwrote the first. HTTP prevents it with a conditional write - the client echoes the ETag it read in an If-Match header, and the server answers 412 Precondition Failed on mismatch.
Walk through how an HTTP ETag and the If-None-Match request header produce a 304 Not Modified response, and what a client is expected to do when it receives one.
basics
~20 sThe server sends an ETag identifying the representation. On the next request the client sends If-None-Match with that value; if it still matches, the server replies 304 Not Modified with headers but no body, and the client reuses its stored copy. Only the round trip is spent, not the payload.
On a single HTTP/1.1 TCP connection, what happens when a client wants to issue three requests at once, and what is the resulting delay when a slow response holds up the ones behind it called?
basics
~10 sHTTP/1.1 handles one request-response exchange at a time per connection, so the second and third wait for the first to finish. A slow first response stalls the queue behind it; that is head-of-line blocking.
In HTTP/1.1, what does it mean that connections are persistent by default, and what effect does sending the HTTP header `Connection: close` have on a request or response?
basics
~20 sHTTP/1.1 leaves the TCP connection open after a response so the next request reuses it instead of paying for a new handshake. Connection: close announces this is the last message on that connection; the sender closes it once the message ends.
What does a client communicate by sending the HTTP request header Expect: 100-continue, and what is the server expected to do when it receives it?
basics
~20 sThe client sends headers only and waits before sending the body. The server either replies 100 Continue, telling it to send the body, or answers with a final status such as 401 or 413, letting the client skip the upload entirely.
What does a client actually pay, in round trips and CPU, to open a brand-new HTTPS connection, and why does that cost justify engineering effort to reuse connections?
basics
~20 sA new HTTPS connection costs a DNS lookup, a TCP three-way handshake (1 RTT), and a TLS handshake (1 RTT with TLS 1.3, 2 with TLS 1.2), plus asymmetric-crypto CPU on both ends and a cold TCP congestion window. Reuse skips all of it.
When an HTTP client follows a redirect, which parts of the original request does it send again, and why do clients strip the `Authorization` header when the redirect points to a different origin?
basics
~20 sMost request headers are re-sent to the new URL, and the body is re-sent only when the redirect preserves the method. Host is recomputed. Credentials are the exception: clients drop Authorization (and proxy credentials) on a cross-origin redirect so a redirect cannot leak your token to another host.
HTTP/2 can carry many requests over a single TCP connection at the same time. Explain the mechanism that makes that possible, and what HTTP/1.1 had to do instead.
basics
~20 sHTTP/2 chops every message into binary frames, each tagged with a stream ID. Frames from many streams interleave on one connection, so requests and responses overlap. HTTP/1.1 finished one message per connection at a time, so browsers opened about six connections per host.
HTTP/3 runs over QUIC instead of TCP. What is QUIC, why was it built on UDP, and where does TLS fit into it?
basics
~20 sQUIC is a reliable, multiplexed transport implemented on top of UDP, with TLS 1.3 built into the protocol rather than layered above it. UDP was chosen because it passes through existing networks and lets the transport live in user space, so it can evolve without OS or middlebox changes.
Walk through how HPACK, the header compression format used by HTTP/2, encodes a header field. What do the static table, the dynamic table and Huffman coding each contribute?
basics
~20 sHPACK encodes each field as an index or a literal. A 61-entry static table covers common fields; a per-connection dynamic table (FIFO, byte-bounded) holds fields already seen, so repeats become one index byte. Literal strings are Huffman-coded. Both peers must keep tables in sync.
On an HTTP/2 connection carrying ten concurrent requests, one TCP segment is lost. What happens to the other nine responses, and how does QUIC's per-stream loss recovery change the outcome for HTTP/3?
basics
~20 sTCP delivers one ordered byte stream, so the kernel holds back every byte after the lost segment — all nine other responses stall for a retransmission round trip even though their data arrived. QUIC tracks loss per packet and delivers each stream independently, so only streams with data in the lost packet wait.
A browser opens https://example.com. Explain the mechanism by which it ends up speaking HTTP/2 rather than HTTP/1.1, and how it would ever discover that HTTP/3 is available on that origin.
basics
~20 sHTTP/2 is chosen by ALPN inside the TLS handshake: the client offers h2 and http/1.1, the server picks one, at no extra round trip. HTTP/3 cannot be negotiated that way because it needs a QUIC connection first, so the server advertises it with an Alt-Svc response header or a DNS HTTPS record.
In HTTP, what is the Accept request header for, and what is a server expected to do with it?
basics
~20 sAccept is a request header listing the media types a client can handle, such as application/json or text/html. The server picks one representation of the resource from that list and names its choice in the response Content-Type header.
Walk through how HTTP response compression is negotiated between a client and a server using the Accept-Encoding and Content-Encoding headers.
basics
~20 sThe client sends Accept-Encoding listing codings it can decode, such as gzip, br, zstd. The server may compress the body with one of them and must say which in Content-Encoding. The client decompresses before parsing. Uncompressed is called identity.
In HTTP content negotiation, what does the q= parameter mean in a request header such as 'Accept: text/html;q=0.8, application/json', and what value applies when you leave it out?
basics
~20 sq is a relative preference weight from 0 to 1 (three decimals max). Omitted means q=1, the strongest preference; q=0 means unacceptable. So in that header application/json (q=1) is preferred over text/html (0.8). Header order carries no priority.
What is the difference between HTTP status 406 Not Acceptable and HTTP status 415 Unsupported Media Type?
basics
~20 s406 is about the response: the server cannot produce any representation matching the request's Accept headers. 415 is about the request body: the server cannot process the Content-Type (or Content-Encoding) the client sent. Response side versus request side.
A client POSTs a JSON body but sends no Content-Type header, or sends `Content-Type: text/plain`. Why do many HTTP servers answer 415 Unsupported Media Type, and what should that response include?
basics
~20 sThe server routes a body by its declared Content-Type, not by sniffing the bytes. With no Content-Type or the wrong one, there is no parser to hand it to, so it returns 415 — ideally with an Accept-Post header naming the media types it accepts.
Walk me through exactly what a client puts in the HTTP Authorization header when using Basic authentication, and what protection that encoding gives you.
basics
~20 sThe client sends Authorization: Basic <base64 of userid:password>, recomputed on every request. Base64 is reversible encoding, not encryption or hashing — anyone who captures the header decodes the password instantly, so only TLS provides confidentiality.
How is a bearer token transmitted on an HTTP request per RFC 6750, and what does the word 'bearer' actually mean about how the server treats it?
basics
~20 sSend Authorization: Bearer <token> on each request, over TLS. 'Bearer' means possession alone proves authorization: the request carries no proof of who is holding it, so whoever copies the token can use it exactly like the legitimate client.
Walk through the HTTP challenge-response authentication flow: what does a 401 Unauthorized response carrying a WWW-Authenticate header tell the client, and what exactly does the client send back?
basics
~20 sThe server refuses with 401 and a WWW-Authenticate header naming an authentication scheme, usually plus a realm. The client gets credentials for that scheme and retries the same request with an Authorization header. HTTP is stateless, so the header repeats on every later request.
Why does RFC 7617 require HTTP Basic authentication to be used only over a confidential channel such as TLS, and what concretely goes wrong if a service accepts Basic over plaintext HTTP?
basics
~20 sBasic transmits the reusable password itself, base64-encoded, on every single request. Without TLS any observer — network tap, proxy, log — reads and replays it forever. TLS is the only thing supplying confidentiality; the scheme supplies none.
An API rejects a request that carried an `Authorization: Bearer` header. Explain the difference between answering with `WWW-Authenticate: Bearer error="invalid_token"` and `error="insufficient_scope"`, and which HTTP status code belongs with each.
basics
~20 sinvalid_token goes with 401: the token is expired, revoked or malformed, so a fresh token may work — clients refresh and retry. insufficient_scope goes with 403: the token is valid but lacks the required privilege, so retrying with the same token is pointless.