7

I saw Expect: 100-continue in some PUT request(uploading a file), what does it mean?

user496949
  • 83,087
  • 147
  • 309
  • 426

1 Answers1

15

What is supposed to happen, is you're supposed to send the request headers with an:

Expect: 100-continue

header. Then, after you have sent the headers, but before you send the payload, you should check to see if you get the 100 response, or a 417 response. If you get the 100 response, you can continue sending the payload. If you don't, you should stop.

The premise is that when you're getting ready to send that 10GB file, this gives the server an opportunity to say "Hold on, cowboy" and then you can handle the process more elegantly than the server simply slamming the socket shut on you.

The fact that you got a 100 back, and you weren't expecting it, says you probably got both the 100 and the 200 (or whatever) response. The 100 was sent to you after the headers were sent, then the final response when the request was finished.

That you weren't paying attention to it is really a detail.

But, ideally, in the future your processing can consider the proper mid-request response.

If you did NOT send the Expect header, the server should not have sent you the 100, since you weren't telling it that you were going to process it. If you DID send the Expect header, then the 100 should not have come as a surprise.

Will Hartung
  • 115,893
  • 19
  • 128
  • 203
  • 2
    2 corrections. 1) RFC 2616 says there's an exception, for PUT and POST request, the server can send back 100 continue even if no expecter header is sent from the client. 2) 417 means the server does not understand the expect header, client should retry with no expect header. If the server replies with other error code, such as entity too large, the client should not send the request again. – cyfdecyf Jul 06 '13 at 10:08