Move transfer encoding into flags bitfield.

event_stream
Ryan 15 years ago
parent e65dcfbcf2
commit f3214f9764

@ -61,10 +61,6 @@ typedef int (*http_cb) (http_parser*);
#define HTTP_TRACE 0x1000 #define HTTP_TRACE 0x1000
#define HTTP_UNLOCK 0x2000 #define HTTP_UNLOCK 0x2000
/* Transfer Encodings */
#define HTTP_IDENTITY 0x01
#define HTTP_CHUNKED 0x02
enum http_parser_type { HTTP_REQUEST, HTTP_RESPONSE }; enum http_parser_type { HTTP_REQUEST, HTTP_RESPONSE };
#define HTTP_VERSION_OTHER 0x00 #define HTTP_VERSION_OTHER 0x00
@ -98,7 +94,6 @@ struct http_parser {
/** READ-ONLY **/ /** READ-ONLY **/
unsigned short status_code; /* responses only */ unsigned short status_code; /* responses only */
unsigned short method; /* requests only */ unsigned short method; /* requests only */
short transfer_encoding;
short version; short version;
short keep_alive; short keep_alive;
size_t content_length; size_t content_length;

@ -29,6 +29,7 @@
/* parser->flags */ /* parser->flags */
#define EATING 0x01 #define EATING 0x01
#define ERROR 0x02 #define ERROR 0x02
#define CHUNKED 0x04
static int unhex[] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 static int unhex[] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 ,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1
@ -76,7 +77,6 @@ do { \
parser->fragment_mark = NULL; \ parser->fragment_mark = NULL; \
parser->status_code = 0; \ parser->status_code = 0; \
parser->method = 0; \ parser->method = 0; \
parser->transfer_encoding = HTTP_IDENTITY; \
parser->version = HTTP_VERSION_OTHER; \ parser->version = HTTP_VERSION_OTHER; \
parser->keep_alive = -1; \ parser->keep_alive = -1; \
parser->content_length = 0; \ parser->content_length = 0; \
@ -103,7 +103,7 @@ do { \
parser->chunk_size -= tmp; \ parser->chunk_size -= tmp; \
if (0 == parser->chunk_size) { \ if (0 == parser->chunk_size) { \
parser->flags &= ~EATING; \ parser->flags &= ~EATING; \
if (parser->transfer_encoding == HTTP_IDENTITY) { \ if (!(parser->flags & CHUNKED)) { \
END_REQUEST; \ END_REQUEST; \
} \ } \
} else { \ } else { \
@ -239,8 +239,7 @@ do { \
parser->status_code += *p - '0'; parser->status_code += *p - '0';
} }
action use_identity_encoding { parser->transfer_encoding = HTTP_IDENTITY; } action use_chunked_encoding { parser->flags |= CHUNKED; }
action use_chunked_encoding { parser->transfer_encoding = HTTP_CHUNKED; }
action set_keep_alive { parser->keep_alive = 1; } action set_keep_alive { parser->keep_alive = 1; }
action set_not_keep_alive { parser->keep_alive = 0; } action set_not_keep_alive { parser->keep_alive = 0; }
@ -279,7 +278,7 @@ do { \
} }
action body_logic { action body_logic {
if (parser->transfer_encoding == HTTP_CHUNKED) { if (parser->flags & CHUNKED) {
fnext ChunkedBody; fnext ChunkedBody;
} else { } else {
/* this is pretty stupid. i'd prefer to combine this with skip_chunk_data */ /* this is pretty stupid. i'd prefer to combine this with skip_chunk_data */
@ -372,7 +371,7 @@ do { \
| "close"i %set_not_keep_alive | "close"i %set_not_keep_alive
) )
) )
| ("Transfer-Encoding"i %use_chunked_encoding hsep "identity" %use_identity_encoding) | ("Transfer-Encoding" hsep "chunked"i %use_chunked_encoding)
| (Field_Name hsep Field_Value) | (Field_Name hsep Field_Value)
) :> CRLF; ) :> CRLF;

Loading…
Cancel
Save