Repository navigation
Conversation
When the server answers a request that carries Expect: 100-continue with a final status before the body has been sent, or when writing the body fails partway, the announced body never reaches the server in full. Close the connection after reading the response instead of keeping it alive for the next request. This follows the behavior of Java's java.net.http.HttpClient, which closes the connection after any response other than 100 to such a request, and of libcurl, which closes it when the body has not been sent completely. Reported-by: Claude (Anthropic) and Stephan Lipp (Ada Logics) Co-Authored-By: Claude Mythos 5.1 <noreply@anthropic.com>
wait_for_continue treated any response other than 100 Continue as the final response, so an informational response such as 103 Early Hints before 100 Continue made the request return 103 without sending its body. Skip informational responses other than 100 and 101 until 100 Continue, a final response, or the continue timeout. Reported-by: Ashton D (https://hackerone.com/ashdfrkl) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cd419fa to
3ba12ae
Compare
| timeout = sock.continue_timeout | ||
| deadline = Process.clock_gettime(Process::CLOCK_MONOTONIC) + timeout if timeout | ||
| informational_count = 0 | ||
| while sock.io.to_io.wait_readable(timeout) |
There was a problem hiding this comment.
I have one concern.
Sometimes another response (100 Continue or a final response) arrives right after the 103, at the same time. In that case, when Net::HTTPResponse.read_new(sock) reads the 103, the next response is also read into the buffer of Net::BufferedIO.
But read_new only reads the 103 (up to the empty line). So the next response stays in the buffer.
After that, sock.io.to_io.wait_readable(timeout) in the next loop does not check the buffer. The response is already in the buffer, but it waits until the timeout ends.
So I think we should check the buffer before sock.io.to_io.wait_readable(timeout), and go to Net::HTTPResponse.read_new(sock) without waiting if there is unread data.
But Net::BufferedIO has no public method for this check. Net::BufferedIO#rbuf_size is private, so I am not sure if it is OK to call it.
Also, after the timeout, the body is sent. Then HTTPResponse.read_new in Net::HTTP#transport_request reads the response left in the buffer. So I think the final result is correct, although the request waits for continue_timeout when the 103 and the next response arrive together.
There was a problem hiding this comment.
Thank you, good catch! It now checks the buffer size before waiting on the socket, and I added tests for the case you pointed out.
rbuf_size is private, so I call it with __send__ for now. I'd like to add a public Net::BufferedIO#wait_readable to net-protocol later.
…ntinue A 103 response read by Net::BufferedIO could pull the next response into its buffer, and wait_readable on the socket then waited until continue_timeout although the response had already arrived. Check the buffer, and the pending data of an SSL socket, before waiting. Use Net::BufferedIO#wait_readable instead when it is defined. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
8061c62 to
5e78828
Compare
When the server answers a request that carries Expect: 100-continue with a final status before the body has been sent, or when writing the body fails partway, the announced body never reaches the server in full. Close the connection after reading the response instead of keeping it alive for the next request. This follows the behavior of Java's java.net.http.HttpClient, which closes the connection after any response other than 100 to such a request, and of libcurl, which closes it when the body has not been sent completely.
Reported-by: Claude (Anthropic) and Stephan Lipp (Ada Logics)