Closed adstage-david closed 11 years ago
Thanks for the feedback - everything you mentioned should be fixed now.
Looks good now, thanks! :thumbsup:
Looking over this again, I'm really not a fan of the callback-driven body API. I think that Reel should support a Body object that supports a #read
/#readpartial
-style API.
I already landed this and will be keeping it around, but I'll probably try to make that change today.
Okay, I see that API was my fault ;)
Did some refactoring and made it so the request parser can handle pipelining. This closes #69 and #55 and makes #56 obsolete.
All of the specs pass, and I've run most of the examples and they all seem to work as well as they do on master (Rackup handler examples seem to be broken on master?)
Cleanup Changes:
Reel::Connection
delegates all of its work toReel::Request::Parser
(for socket reads) and Reel::Response::Writer (for socket writes).Reel::Connection::StateError
if not. No other objects know the parser/writer exist.Reel::Request
andReel::Websocket
no longer require a direct link to the request parser - they are initialized with a Reel::RequestInfo object that includes the parsed request headers, url, method, http_version.Reel::Response::Writer
knows how to render proper HTTP responses, but will send the socket toResponse#render
if that method exists (for theStreamResponse
subclass) (there was a TODO about extracting this logic).API Changes:
#read
can now only be called on theReel::Request
, not connection, since http_parser may accidentally consume bytes of multiple bodies, eachReel::Request
keeps an internal buffer of bytes parsed but not yet pulled with #read. This buffer is read from before calling@connection#readpartial
#<<
and#write
to Reel::Request so you can call both#read
and#write
on the request itself.Reel::Connection
.Parser Details:
The
Reel::Request::Parser
maintains an internal buffer of incoming requests still reading (if body hasn't been read in yet), one currently awaiting response, and a queue of requests to be responded to after the current request is handled. The underlying http parser calls the callbacks on this class when bytes buffered to it add to headers or body.Reel::Request::Parser
has#current_request
, which will return the current request being read/responded to, or block and read from the raw socket until a full set of headers has been discovered and the body is ready to read.