ruby / webrick

HTTP server toolkit

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

POST/PUT with an empty body hangs forever

davidtaylorhq opened this issue · comments

When making a PUT/POST request with an empty body, we're seeing all requests hang forever. This seems to have started since 069e9b1. Reverting to version 1.6.1 takes us back to the previous behaviour (which is an instant 411 response).

@OsamaSayegh shared some details in #30:

It seems like WEBrick still doesn't allow POST/PUT requests with empty body, but the difference now is that the server doesn't respond with a 411, instead the request is blocked forever because the server gets stuck at the eof call here:

elsif BODY_CONTAINABLE_METHODS.member?(@request_method) && !@socket.eof

I can repro with this script:

require 'webrick'

class Simple < WEBrick::HTTPServlet::AbstractServlet
def do_GET(req, res)
    puts "Hello world!"
    res.status = 200
    res.body = "Hello world!"
  end

  alias do_POST do_GET
end
server = WEBrick::HTTPServer.new(Port: 9988)                                                                                                                                                                                                                                    
server.logger.level = 5
server.mount '/', Simple
server.start

And:

~ » curl -X POST --verbose localhost:9988
*   Trying 127.0.0.1:9988...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 9988 (#0)
> POST / HTTP/1.1
> Host: localhost:9988
> User-Agent: curl/7.68.0
> Accept: */*
>
# blocks forever; I have to Ctrl+C it

I've reverted that commit. I'll see if I can work on an approach that doesn't hang.

Thanks for the quick revert @jeremyevans. Would it be possible to cut a new release which includes the revert? At the moment we are pinning our projects to v1.6.1.

That would be up to @hsbt .