How-To Guide

How to Handle Expect: 100-continue

Use the Expect: 100-continue handshake to avoid uploading a body a server will reject, and implement it correctly on both client and server.

On this page

  1. Introduction
  2. The Handshake
  3. Why It Saves Work
  4. Client Implementation
  5. Server Implementation
  6. Proxies and Hop-by-Hop
  7. Interaction with Timeouts and Retries
  8. Common Pitfalls and Conclusion

Introduction

A client that uploads a large body before the server validates the headers wastes bandwidth and time when the server would have rejected the request. The Expect: 100-continue handshake lets the client ask first: it sends the headers with the Expect header, waits for a 100 Continue (or a final error), and only then sends the body. The server can reject early, saving the upload. It is a small protocol detail that matters most for large uploads on slow connections, and it has enough edge cases that both ends must implement it correctly.

The Handshake

The client sends the request headers with Expect: 100-continue and pauses before the body. The server, if it wants the body, responds with an interim 100 Continue and the client sends the body, then the server sends the final response. If the server would reject the request, it sends the final error immediately and the client never uploads.

Sending an interim 100 Continue is optional for the server, and a client must not wait forever for it: after a short timeout the client should send the body anyway, because the server may not implement the handshake. The handshake is an optimisation, not a requirement.

# the flow
client -> headers (Expect: 100-continue), then WAITS
server -> 100 Continue (interim)      -> client sends the body -> final response
server -> 4xx/5xx (final, immediate)  -> client does NOT send the body
# a client that gets no interim within a short timeout sends the body anyway

Why It Saves Work

For a large upload, the body can be the bulk of the request. If the server will reject it, for example the authentication failed or the content length is over a limit, uploading first wastes that bandwidth and the client’s time. The handshake moves the decision before the body.

The saving is largest on slow connections and large bodies. On a fast internal connection with a small body, the extra round trip may cost more than it saves, which is why clients often use the handshake only for large uploads.

# where 100-continue pays off
[ ] large body (upload)
[ ] slow client connection (the upload would be costly)
[ ] a server that can reject on headers (auth, size, content-type)
# where it may not
[ ] small body on a fast link (extra round trip costs more)
# clients often enable it only above a size threshold

Client Implementation

The client sends the headers, sets a timer (typically a second or two), and either proceeds on 100 Continue, proceeds on the timer expiring, or aborts on a final error response. It must handle all three: the interim status, the timeout, and the error that arrives instead of the interim.

A client that does not handle the timeout hangs waiting for an interim that may never come; one that does not handle the early error uploads anyway. Both cases are common bugs. The client must also handle a server that sends 100 Continue and then a final error after the body, which is a normal flow for servers that accept the body and fail later.

// Sketch: headers first, body only after 100 Continue or a timeout.
async function uploadWithExpect(url: string, headers: Headers, body: Readable) {
  const res = await sendHeadersOnly(url, { ...headers, Expect: '100-continue' });
  if (res.status === 100) return sendBody(res, body);      // server wants it
  if (res.status >= 200) return res;                        // final error, no body
  // no interim: wait a bounded time, then send the body anyway
  const interim = await waitForInterim(res, 1000);
  return interim ? sendBody(res, body) : sendBody(res, body);
}

Server Implementation

The server reads the headers and decides: if it will handle the request, send 100 Continue then read the body and respond; if it will reject, send the final error without reading the body. It must not read the body until it has sent 100 Continue, and it must handle a client that sends the body without waiting.

The server should reject on headers where it can: authentication, content-length limits, unsupported content types. Rejecting before the body is the point. But it must also be prepared for the client to send the body immediately (an old client or one that timed out), so it should not assume the handshake completed.

# server decision
will handle -> send "100 Continue" (interim), then read body, then respond
will reject -> send the final error (e.g. 401/413) WITHOUT reading the body
# must tolerate a client that sends the body without waiting
# must not read the body before sending 100 Continue

Proxies and Hop-by-Hop

Expect: 100-continue is hop-by-hop: a proxy must handle it for its own hop, not blindly forward it. A proxy that forwards Expect to the next hop and relays the 100 Continue is fine, but a proxy (or HTTP/2 layer) that does not support it must not stall the connection. This is where support is inconsistent and clients see unexpected behaviour.

HTTP/2 and HTTP/3 handle the equivalent without the Expect mechanism, using flow control and the response before the request body completes. A client on HTTP/2 may not need the handshake at all, and a server supporting both must handle either.

# hop-by-hop
Expect: 100-continue applies per hop; a proxy handles it for its hop
# a proxy that does not support it must not stall the connection
# HTTP/2/3: flow control + early response replace the Expect handshake
#   the client can abort the body when the server responds early

Interaction with Timeouts and Retries

The client’s wait for 100 Continue is bounded by a timeout, and that timeout must be shorter than the overall request deadline, or a non-implementing server makes the request hang. A retry of a request that used the handshake must repeat the handshake, not send the body directly, if the body is large.

On a retry, the client may know from a previous attempt that the server does not implement 100 Continue and skip the handshake. Remembering that per host avoids the wasted wait on every subsequent upload to a server that ignores the header.

# client timeout discipline
[ ] the 100-continue wait < the overall request deadline
[ ] on a server that ignores it: send the body after the short timeout
[ ] on retry: repeat the handshake for a large body (or cache "server ignores it")
# a wait longer than the deadline => the request hangs

Common Pitfalls and Conclusion

Do not wait for 100 Continue indefinitely; use a bounded timeout. Do not upload the body when the server already sent a final error. On the server, do not read the body before sending the interim, and do not assume the handshake completed. And do not forget that it is hop-by-hop and that HTTP/2+ handle it differently.

Expect: 100-continue lets a client avoid uploading a body the server will reject, by sending headers first and the body only on a 100 Continue or after a short timeout. Implement both ends: the client with a bounded wait and early-error handling, the server with the interim response and an early reject, and account for proxies and HTTP/2 where the mechanism differs. It saves the upload on the requests that would have been rejected.

Sources: RFC 9110: Expect header, MDN: 100 Continue, RFC 9113: HTTP/2.

FAQ

What if the server never sends 100 Continue?
The client should wait only a short bounded time, then send the body anyway, because the interim response is optional and the server may not implement it. Waiting indefinitely hangs the request on a server that ignores the header.
Does HTTP/2 use Expect: 100-continue?
No. HTTP/2 and HTTP/3 handle the case differently: flow control and the ability to respond before the request body completes let the server reject early without the Expect handshake, and the client can abort the body when it receives an early response.

Related Examples