diff --git a/Makefile b/Makefile index e2b4b58..2805733 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ B64_OBJS?=b64/cencode.o FORMAT_OBJS?=formats/json.o formats/raw.o formats/common.o formats/custom-type.o HTTP_PARSER_OBJS?=http-parser/http_parser.o -CFLAGS ?= -O0 -ggdb -Wall -Wextra -I. -Ijansson/src -Ihttp-parser +CFLAGS ?= -g3 -O0 -ggdb -Wall -Wextra -I. -Ijansson/src -Ihttp-parser LDFLAGS ?= -levent -pthread # check for MessagePack diff --git a/client.c b/client.c index cdcd762..9987c01 100644 --- a/client.c +++ b/client.c @@ -180,7 +180,9 @@ http_client_on_message_complete(struct http_parser *p) { struct http_client *c = p->data; /* keep-alive detection */ - if(c->parser.http_major == 1 && c->parser.http_minor == 1) { /* 1.1 */ + if (c->parser.flags & F_CONNECTION_CLOSE) { + c->keep_alive = 0; + } else if(c->parser.http_major == 1 && c->parser.http_minor == 1) { /* 1.1 */ c->keep_alive = 1; } c->http_version = c->parser.http_minor; diff --git a/http-parser/http_parser.c b/http-parser/http_parser.c index 5a0972a..7823085 100644 --- a/http-parser/http_parser.c +++ b/http-parser/http_parser.c @@ -288,16 +288,6 @@ enum header_states }; -enum flags - { F_CHUNKED = 1 << 0 - , F_CONNECTION_KEEP_ALIVE = 1 << 1 - , F_CONNECTION_CLOSE = 1 << 2 - , F_TRAILING = 1 << 3 - , F_UPGRADE = 1 << 4 - , F_SKIPBODY = 1 << 5 - }; - - #define CR '\r' #define LF '\n' #define LOWER(c) (unsigned char)(c | 0x20) diff --git a/http-parser/http_parser.h b/http-parser/http_parser.h index c03ec05..30cec8c 100644 --- a/http-parser/http_parser.h +++ b/http-parser/http_parser.h @@ -155,6 +155,17 @@ struct http_parser_settings { }; +enum flags + { F_CHUNKED = 1 << 0 + , F_CONNECTION_KEEP_ALIVE = 1 << 1 + , F_CONNECTION_CLOSE = 1 << 2 + , F_TRAILING = 1 << 3 + , F_UPGRADE = 1 << 4 + , F_SKIPBODY = 1 << 5 + }; + + + void http_parser_init(http_parser *parser, enum http_parser_type type); diff --git a/worker.c b/worker.c index 10294c3..bd32ad7 100644 --- a/worker.c +++ b/worker.c @@ -63,6 +63,8 @@ worker_can_read(int fd, short event, void *p) { if(c->failed_alloc) { slog(c->w->s, WEBDIS_DEBUG, "503", 3); http_send_error(c, 503, "Service Unavailable"); + } else if (c->parser.flags & F_CONNECTION_CLOSE) { + c->broken = 1; } else if(c->is_websocket) { /* we need to use the remaining (unparsed) data as the body. */ if(nparsed < ret) {