From 546f43a7823a59c4bb052e3c4e9bdca6c03a1396 Mon Sep 17 00:00:00 2001 From: Cliff Frey Date: Thu, 10 Jun 2010 20:28:37 -0700 Subject: [PATCH] remove body_read This saves space in the structure (it is now 28 bytes on x86), and makes the handling of content_length more consistent between chunked encoding and non-chunked-encoding. --- http_parser.c | 8 +++----- http_parser.h | 1 - 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/http_parser.c b/http_parser.c index 00e7a76..190041e 100644 --- a/http_parser.c +++ b/http_parser.c @@ -1379,7 +1379,6 @@ size_t http_parser_execute (http_parser *parser, break; } - parser->body_read = 0; nread = 0; if (parser->flags & F_UPGRADE) parser->upgrade = 1; @@ -1440,12 +1439,12 @@ size_t http_parser_execute (http_parser *parser, } case s_body_identity: - to_read = MIN(pe - p, (ssize_t)(parser->content_length - parser->body_read)); + to_read = MIN(pe - p, (ssize_t)parser->content_length); if (to_read > 0) { if (settings->on_body) settings->on_body(parser, p, to_read); p += to_read - 1; - parser->body_read += to_read; - if (parser->body_read == parser->content_length) { + parser->content_length -= to_read; + if (parser->content_length == 0) { CALLBACK2(message_complete); state = NEW_MESSAGE(); } @@ -1458,7 +1457,6 @@ size_t http_parser_execute (http_parser *parser, if (to_read > 0) { if (settings->on_body) settings->on_body(parser, p, to_read); p += to_read - 1; - parser->body_read += to_read; } break; diff --git a/http_parser.h b/http_parser.h index a4abf32..2c9c6d2 100644 --- a/http_parser.h +++ b/http_parser.h @@ -102,7 +102,6 @@ struct http_parser { char flags; size_t nread; - ssize_t body_read; ssize_t content_length; /** READ-ONLY **/