Net::HTTP does not wait to send request body with Expect: 100-continue
HTTP/1.1 allows a client to determine if the server will accept a request body using the Expect header with a value of 100-continue. If the server finds the request header the client sent acceptable it will return with a 100 Continue response and the client will then send the request body.
Instead of waiting for a 100 Continue response Net::HTTP immediately sends the request body and ignores any 100 Continue responses.
The current behavior defeats the purpose of the Expect: 100-continue value and the 100 Continue response code.
If I am attempting to upload a large file like a photo and to a server that requires HTTP authentication I will have to wait until the upload is complete before I can retrieve a 401 response for incorrect authentication.
I have attached a proposed patch that adds a continue timeout. Net::HTTP will wait up to the continue timeout before sending the request body.
Updated by drbrain (Eric Hodel) over 10 years ago
With your latest patch if you do not set the continue_timeout after the server is started it does not wait for "100 Continue".
h = Net::HTTP.new host, port
h.continue_timeout = 10 # does nothing
With your latest patch Net::HTTP does not send the HTTP header immediately, it waits for the continue timeout first.
Placing wait_for_continue after sending headers fixes this.
Does Net::HTTP require additional RDoc? I think the current comments for the new methods are ok.
Updated by nahi (Hiroshi Nakamura) over 9 years ago
Merged the update from Eric Hodel. Thanks Eric, and I'm sorry for posting the patch which does not include full changes. Can't remember why I thought the tests I added run correctly...