From: Ben Noordhuis <i...@bnoordhuis.nl>
Date: Sat, 10 Nov 2012 18:07:44 +0100
Local: Sat, Nov 10 2012 12:07 pm
Subject: Re: [libuv] How to correctly & efficiently handle http/1.1 style pipelines requests using libuv & http-parser?
On Sat, Nov 10, 2012 at 3:44 PM, Dhruv Matani <dhruvb...@gmail.com> wrote:
No, http_parser never buffers and yes, the on_message_complete
> Hello, > I'm trying to implement a custom http/1.1 in-process web server using libuv
> Currently, I am calling http_parser_execute() every time the on_read
callback is called synchronously. In fact, all callbacks are. It's something of an API design flaw. Callbacks only make sense when
> Subsequently, in the on_message_complete callback, I call uv_read_stop(),
You check the 'bytes parsed' count that http_parser_execute() returns.
> which supposedly stops invoking callbacks. However, the thing I am unable to > understand is what happens when data for multiple HTTP requests is passed to > the http parser since I reinitialize the parser using http_parser_init() in > the after_write callback. I am pretty sure that there can be cases where the > parser has parsed 2 requests, but the on_message_complete handler has been > invoked for just 1 (since I return 1 from that callback), and once I > re-initialize the parser, the 2nd request is lost. If it's less than the size of the input but there's no error, the buffer contains a message boundary. The basic logic looks something like this: void read_cb(uv_stream_t* handle, ssize_t nread, uv_buf_t buf)
if (nread == -1) {
for (;;) {
if (nparsed == len)
if (parser->http_errno != HPE_OK) {
// buffer contains two messages, we've parsed
> I am thinking that http_parser_pause() is the right method to be calling in
> the on_message_complete callback (instead of calling uv_read_stop or maybe > both depending on the use-case??), and subsequently resuming it in the > after_write callback. However, in this case, I am having a problem > understanding what happens to the rest of the requests in the pipeline, and > how does the http parser ensure that the callbacks are correctly invoked for > them all? Does the http parser return a short read count if you call > http_parser_execute() on a paused parser? > Confused as hell,
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||