diff options
author | Valentin Bartenev <vbart@nginx.com> | 2019-09-30 19:11:17 +0300 |
---|---|---|
committer | Valentin Bartenev <vbart@nginx.com> | 2019-09-30 19:11:17 +0300 |
commit | f7d3db314da88be47eeed0a3509368cbe4c5f04f (patch) | |
tree | 05e6f11157599241e9ce83a7ea90246dde3a6a81 | |
parent | 2dbda125db743f71d4dd104b29fa58620eb49de2 (diff) | |
download | unit-f7d3db314da88be47eeed0a3509368cbe4c5f04f.tar.gz unit-f7d3db314da88be47eeed0a3509368cbe4c5f04f.tar.bz2 |
HTTP parser: removed unused "exten" field.
This field was intended for MIME type lookup by file extension when serving
static files, but this use case is too narrow; only a fraction of requests
targets static content, and the URI presumably isn't rewritten. Moreover,
current implementation uses the entire filename for MIME type lookup if the
file has no extension.
Instead of extracting filenames and extensions when parsing requests, it's
easier to obtain them right before serving static content; this behavior is
already implemented. Thus, we can drop excessive logic from parser.
Diffstat (limited to '')
-rw-r--r-- | src/nxt_http_parse.c | 23 | ||||
-rw-r--r-- | src/nxt_http_parse.h | 1 | ||||
-rw-r--r-- | src/test/nxt_http_parse_test.c | 22 |
3 files changed, 2 insertions, 44 deletions
diff --git a/src/nxt_http_parse.c b/src/nxt_http_parse.c index 63fd5130..e6e91454 100644 --- a/src/nxt_http_parse.c +++ b/src/nxt_http_parse.c @@ -162,7 +162,7 @@ static nxt_int_t nxt_http_parse_request_line(nxt_http_request_parse_t *rp, u_char **pos, u_char *end) { - u_char *p, ch, *after_slash, *exten, *args; + u_char *p, ch, *after_slash, *args; nxt_int_t rc; nxt_bool_t rest; nxt_http_ver_t ver; @@ -255,7 +255,6 @@ nxt_http_parse_request_line(nxt_http_request_parse_t *rp, u_char **pos, rp->target_start = p; after_slash = p + 1; - exten = NULL; args = NULL; rest = 0; @@ -274,7 +273,6 @@ continue_target: } after_slash = p + 1; - exten = NULL; continue; case NXT_HTTP_TARGET_DOT: @@ -283,7 +281,6 @@ continue_target: goto rest_of_target; } - exten = p + 1; continue; case NXT_HTTP_TARGET_ARGS_MARK: @@ -459,11 +456,6 @@ space_after_target: rp->path.length = rp->target_end - rp->target_start; } - if (exten != NULL) { - rp->exten.length = (rp->path.start + rp->path.length) - exten; - rp->exten.start = exten; - } - return nxt_http_parse_field_name(rp, pos, end); } @@ -846,7 +838,7 @@ static const uint8_t nxt_http_normal[32] nxt_aligned(32) = { static nxt_int_t nxt_http_parse_complex_target(nxt_http_request_parse_t *rp) { - u_char *p, *u, c, ch, high, *exten, *args; + u_char *p, *u, c, ch, high, *args; enum { sw_normal = 0, @@ -872,7 +864,6 @@ nxt_http_parse_complex_target(nxt_http_request_parse_t *rp) rp->path.start = u; high = '\0'; - exten = NULL; args = NULL; while (p < rp->target_end) { @@ -892,7 +883,6 @@ nxt_http_parse_complex_target(nxt_http_request_parse_t *rp) switch (ch) { case '/': - exten = NULL; state = sw_slash; *u++ = ch; continue; @@ -905,10 +895,6 @@ nxt_http_parse_complex_target(nxt_http_request_parse_t *rp) goto args; case '#': goto done; - case '.': - exten = u + 1; - *u++ = ch; - continue; default: *u++ = ch; continue; @@ -1138,11 +1124,6 @@ done: rp->path.length = u - rp->path.start; - if (exten) { - rp->exten.length = u - exten; - rp->exten.start = exten; - } - return NXT_OK; } diff --git a/src/nxt_http_parse.h b/src/nxt_http_parse.h index a307ea73..d7ce5e4f 100644 --- a/src/nxt_http_parse.h +++ b/src/nxt_http_parse.h @@ -44,7 +44,6 @@ struct nxt_http_request_parse_s { nxt_str_t path; nxt_str_t args; - nxt_str_t exten; nxt_http_ver_t version; diff --git a/src/test/nxt_http_parse_test.c b/src/test/nxt_http_parse_test.c index 5498cb1f..8dcbc061 100644 --- a/src/test/nxt_http_parse_test.c +++ b/src/test/nxt_http_parse_test.c @@ -11,7 +11,6 @@ typedef struct { nxt_str_t method; nxt_str_t target; - nxt_str_t exten; nxt_str_t args; u_char version[8]; @@ -66,7 +65,6 @@ static nxt_http_parse_test_case_t nxt_http_test_cases[] = { nxt_string("GET"), nxt_string("/"), nxt_null_string, - nxt_null_string, "HTTP/1.0", 0, 0, 0 }} @@ -78,7 +76,6 @@ static nxt_http_parse_test_case_t nxt_http_test_cases[] = { { .request_line = { nxt_string("XXX-METHOD"), nxt_string("/d.ir/fi+le.ext?key=val"), - nxt_string("ext"), nxt_string("key=val"), "HTTP/1.2", 0, 0, 0 @@ -91,7 +88,6 @@ static nxt_http_parse_test_case_t nxt_http_test_cases[] = { { .request_line = { nxt_string("GET"), nxt_string("/di.r/?"), - nxt_null_string, nxt_string(""), "HTTP/1.0", 0, 0, 0 @@ -135,7 +131,6 @@ static nxt_http_parse_test_case_t nxt_http_test_cases[] = { nxt_string("GET"), nxt_string("/."), nxt_null_string, - nxt_null_string, "HTTP/1.0", 1, 0, 0 }} @@ -148,7 +143,6 @@ static nxt_http_parse_test_case_t nxt_http_test_cases[] = { nxt_string("GET"), nxt_string("/#"), nxt_null_string, - nxt_null_string, "HTTP/1.0", 1, 0, 0 }} @@ -160,7 +154,6 @@ static nxt_http_parse_test_case_t nxt_http_test_cases[] = { { .request_line = { nxt_string("GET"), nxt_string("/?#"), - nxt_null_string, nxt_string(""), "HTTP/1.0", 1, 0, 0 @@ -174,7 +167,6 @@ static nxt_http_parse_test_case_t nxt_http_test_cases[] = { nxt_string("GET"), nxt_string("//"), nxt_null_string, - nxt_null_string, "HTTP/1.0", 1, 0, 0 }} @@ -187,7 +179,6 @@ static nxt_http_parse_test_case_t nxt_http_test_cases[] = { nxt_string("GET"), nxt_string("/%20"), nxt_null_string, - nxt_null_string, "HTTP/1.0", 0, 1, 0 }} @@ -200,7 +191,6 @@ static nxt_http_parse_test_case_t nxt_http_test_cases[] = { nxt_string("GET"), nxt_string("/ a"), nxt_null_string, - nxt_null_string, "HTTP/1.0", 0, 0, 1 }} @@ -212,7 +202,6 @@ static nxt_http_parse_test_case_t nxt_http_test_cases[] = { { .request_line = { nxt_string("GET"), nxt_string("/na %20me.ext?args"), - nxt_string("ext"), nxt_string("args"), "HTTP/1.0", 0, 1, 1 @@ -225,7 +214,6 @@ static nxt_http_parse_test_case_t nxt_http_test_cases[] = { { .request_line = { nxt_string("GET"), nxt_string("/ HTTP/1.0"), - nxt_string("0"), nxt_null_string, "HTTP/1.1", 0, 0, 1 @@ -740,16 +728,6 @@ nxt_http_parse_test_request_line(nxt_http_request_parse_t *rp, return NXT_ERROR; } - if (rp->exten.start != test->exten.start - && !nxt_strstr_eq(&rp->exten, &test->exten)) - { - nxt_log_alert(log, "http parse test case failed:\n" - " - request:\n\"%V\"\n" - " - exten: \"%V\" (expected: \"%V\")", - request, &rp->exten, &test->exten); - return NXT_ERROR; - } - if (rp->args.start != test->args.start && !nxt_strstr_eq(&rp->args, &test->args)) { |