diff options
Diffstat (limited to 'http.c')
-rw-r--r-- | http.c | 33 |
1 files changed, 23 insertions, 10 deletions
@@ -236,7 +236,7 @@ http_client_died(struct mog_fd *mfd, size_t buf_len, int save_err) return MOG_NEXT_CLOSE; } -MOG_NOINLINE static char * +static char * http_rbuf_grow(struct mog_fd *mfd, struct mog_rbuf **rbuf, size_t buf_len) { struct mog_http *http = &mfd->as.http; @@ -246,6 +246,24 @@ http_rbuf_grow(struct mog_fd *mfd, struct mog_rbuf **rbuf, size_t buf_len) return *rbuf ? (*rbuf)->rptr : NULL; } +MOG_NOINLINE static bool +http_parse_continue(struct mog_fd *mfd, struct mog_rbuf **rbuf, + char **buf, size_t buf_len, uint32_t *off) +{ + struct mog_http *http = &mfd->as.http; + + assert(http->wbuf == NULL && + "tried to write (and failed) with partial req"); + if (http->_p.buf_off >= (*rbuf)->rcapa) { + *buf = http_rbuf_grow(mfd, rbuf, buf_len); + if (!*buf) + return false; + } + + *off = http->_p.buf_off; + return true; +} + static enum mog_next __http_queue_step(struct mog_fd *mfd) { struct mog_http *http = &mfd->as.http; @@ -295,15 +313,10 @@ parse: case MOG_PARSER_ERROR: goto err507or400; case MOG_PARSER_CONTINUE: - assert(http->wbuf == NULL && - "tried to write (and failed) with partial req"); - if (http->_p.buf_off >= rbuf->rcapa) { - buf = http_rbuf_grow(mfd, &rbuf, buf_len); - if (!buf) - goto err400; - } - off = http->_p.buf_off; - goto reread; + if (http_parse_continue(mfd, &rbuf, &buf, buf_len, + &off)) + goto reread; + goto err400; case MOG_PARSER_DONE: return http_run(mfd, rbuf, buf, buf_len); } |