diff options
author | Valentin Bartenev <vbart@nginx.com> | 2018-01-15 20:49:59 +0300 |
---|---|---|
committer | Valentin Bartenev <vbart@nginx.com> | 2018-01-15 20:49:59 +0300 |
commit | 3fb140d6d2f8bf0344e7c311923178db808cb437 (patch) | |
tree | 139b1cf0d91895682beb6818136ab2ee6e4831ea /src/nxt_h1proto.c | |
parent | 819b43fc2da414c9132c6061eabf063ae08c36dc (diff) | |
download | unit-3fb140d6d2f8bf0344e7c311923178db808cb437.tar.gz unit-3fb140d6d2f8bf0344e7c311923178db808cb437.tar.bz2 |
HTTP parser: improved error reporting.
Diffstat (limited to '')
-rw-r--r-- | src/nxt_h1proto.c | 27 |
1 files changed, 24 insertions, 3 deletions
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: |