From 3fb140d6d2f8bf0344e7c311923178db808cb437 Mon Sep 17 00:00:00 2001 From: Valentin Bartenev Date: Mon, 15 Jan 2018 20:49:59 +0300 Subject: HTTP parser: improved error reporting. --- src/nxt_h1proto.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'src/nxt_h1proto.c') diff --git a/src/nxt_h1proto.c b/src/nxt_h1proto.c index c3a100a4..5623c019 100644 --- a/src/nxt_h1proto.c +++ b/src/nxt_h1proto.c @@ -190,6 +190,7 @@ nxt_h1p_header_parse(nxt_task_t *task, void *obj, void *data) nxt_buf_t *in, *b; nxt_conn_t *c; nxt_h1proto_t *h1p; + nxt_http_status_t status; nxt_http_request_t *r; nxt_socket_conf_joint_t *joint; @@ -264,7 +265,13 @@ nxt_h1p_header_parse(nxt_task_t *task, void *obj, void *data) return; } - } else if (ret == NXT_AGAIN) { + /* ret == NXT_ERROR */ + + nxt_http_request_error(task, r, NXT_HTTP_BAD_REQUEST); + return; + } + + if (ret == NXT_AGAIN) { in = c->read; if (nxt_buf_mem_free_size(&in->mem) == 0) { @@ -298,9 +305,23 @@ nxt_h1p_header_parse(nxt_task_t *task, void *obj, void *data) return; } - /* ret == NXT_ERROR */ + switch (ret) { - nxt_http_request_error(task, r, NXT_HTTP_BAD_REQUEST); + case NXT_HTTP_PARSE_INVALID: + status = NXT_HTTP_BAD_REQUEST; + break; + + case NXT_HTTP_PARSE_TOO_LARGE_FIELD: + status = NXT_HTTP_REQUEST_HEADER_FIELDS_TOO_LARGE; + break; + + default: + case NXT_ERROR: + status = NXT_HTTP_INTERNAL_SERVER_ERROR; + break; + } + + nxt_http_request_error(task, r, status); return; fail: -- cgit