Handle Connection:close header

When the client sends a connection close, the server now returns
the same header, and the socket is closed. Instead of a 400 Bad Request
clients should get a socket read error.
master
James Booth 9 years ago
parent 00ab5518c3
commit f85c64c94b

@ -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

@ -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;

@ -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)

@ -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);

@ -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) {

Loading…
Cancel
Save