summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/nxt_http_parse.c58
-rw-r--r--src/nxt_http_parse.h2
-rw-r--r--src/test/nxt_http_parse_test.c24
3 files changed, 37 insertions, 47 deletions
diff --git a/src/nxt_http_parse.c b/src/nxt_http_parse.c
index 945f4e93..9d591b86 100644
--- a/src/nxt_http_parse.c
+++ b/src/nxt_http_parse.c
@@ -163,7 +163,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;
+ u_char *p, ch, *after_slash, *exten, *args;
nxt_int_t rc;
nxt_http_ver_t ver;
nxt_http_target_traps_e trap;
@@ -255,6 +255,8 @@ 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;
for ( ;; ) {
p++;
@@ -269,8 +271,7 @@ nxt_http_parse_request_line(nxt_http_request_parse_t *rp, u_char **pos,
}
after_slash = p + 1;
-
- rp->exten_start = NULL;
+ exten = NULL;
continue;
case NXT_HTTP_TARGET_DOT:
@@ -279,11 +280,11 @@ nxt_http_parse_request_line(nxt_http_request_parse_t *rp, u_char **pos,
goto rest_of_target;
}
- rp->exten_start = p + 1;
+ exten = p + 1;
continue;
case NXT_HTTP_TARGET_ARGS_MARK:
- rp->args_start = p + 1;
+ args = p + 1;
goto rest_of_target;
case NXT_HTTP_TARGET_SPACE:
@@ -437,20 +438,19 @@ space_after_target:
rp->path.start = rp->target_start;
- if (rp->args_start != NULL) {
- rp->path.length = rp->args_start - rp->target_start - 1;
+ if (args != NULL) {
+ rp->path.length = args - rp->target_start - 1;
- rp->args.start = rp->args_start;
- rp->args.length = rp->target_end - rp->args_start;
+ rp->args.length = rp->target_end - args;
+ rp->args.start = args;
} else {
rp->path.length = rp->target_end - rp->target_start;
}
- if (rp->exten_start) {
- rp->exten.length = rp->path.start + rp->path.length
- - rp->exten_start;
- rp->exten.start = rp->exten_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);
@@ -835,7 +835,8 @@ 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;
+ u_char *p, *u, c, ch, high, *exten, *args;
+
enum {
sw_normal = 0,
sw_slash,
@@ -852,7 +853,6 @@ nxt_http_parse_complex_target(nxt_http_request_parse_t *rp)
p = rp->target_start;
u = nxt_mp_alloc(rp->mem_pool, rp->target_end - p + 1);
-
if (nxt_slow_path(u == NULL)) {
return NXT_ERROR;
}
@@ -861,8 +861,8 @@ nxt_http_parse_complex_target(nxt_http_request_parse_t *rp)
rp->path.start = u;
high = '\0';
- rp->exten_start = NULL;
- rp->args_start = NULL;
+ exten = NULL;
+ args = NULL;
while (p < rp->target_end) {
@@ -881,7 +881,7 @@ nxt_http_parse_complex_target(nxt_http_request_parse_t *rp)
switch (ch) {
case '/':
- rp->exten_start = NULL;
+ exten = NULL;
state = sw_slash;
*u++ = ch;
continue;
@@ -890,12 +890,12 @@ nxt_http_parse_complex_target(nxt_http_request_parse_t *rp)
state = sw_quoted;
continue;
case '?':
- rp->args_start = p;
+ args = p;
goto args;
case '#':
goto done;
case '.':
- rp->exten_start = u + 1;
+ exten = u + 1;
*u++ = ch;
continue;
case '+':
@@ -928,7 +928,7 @@ nxt_http_parse_complex_target(nxt_http_request_parse_t *rp)
state = sw_quoted;
continue;
case '?':
- rp->args_start = p;
+ args = p;
goto args;
case '#':
goto done;
@@ -965,7 +965,7 @@ nxt_http_parse_complex_target(nxt_http_request_parse_t *rp)
state = sw_quoted;
continue;
case '?':
- rp->args_start = p;
+ args = p;
goto args;
case '#':
goto done;
@@ -1009,7 +1009,7 @@ nxt_http_parse_complex_target(nxt_http_request_parse_t *rp)
state = sw_quoted;
continue;
case '?':
- rp->args_start = p;
+ args = p;
goto args;
case '#':
goto done;
@@ -1114,18 +1114,18 @@ args:
}
}
- if (rp->args_start != NULL) {
- rp->args.length = p - rp->args_start;
- rp->args.start = rp->args_start;
+ if (args != NULL) {
+ rp->args.length = p - args;
+ rp->args.start = args;
}
done:
rp->path.length = u - rp->path.start;
- if (rp->exten_start) {
- rp->exten.length = u - rp->exten_start;
- rp->exten.start = rp->exten_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 e42ec9a4..29e3688e 100644
--- a/src/nxt_http_parse.h
+++ b/src/nxt_http_parse.h
@@ -43,8 +43,6 @@ struct nxt_http_request_parse_s {
u_char *target_start;
u_char *target_end;
- u_char *exten_start;
- u_char *args_start;
nxt_str_t path;
nxt_str_t args;
diff --git a/src/test/nxt_http_parse_test.c b/src/test/nxt_http_parse_test.c
index 572e91b2..3e86f6ef 100644
--- a/src/test/nxt_http_parse_test.c
+++ b/src/test/nxt_http_parse_test.c
@@ -80,7 +80,7 @@ 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?key=val"),
+ nxt_string("ext"),
nxt_string("key=val"),
"HTTP/1.2",
0, 0, 0, 1
@@ -163,7 +163,7 @@ static nxt_http_parse_test_case_t nxt_http_test_cases[] = {
nxt_string("GET"),
nxt_string("/?#"),
nxt_null_string,
- nxt_string("#"),
+ nxt_string(""),
"HTTP/1.0",
1, 0, 0, 0
}}
@@ -729,31 +729,23 @@ nxt_http_parse_test_request_line(nxt_http_request_parse_t *rp,
return NXT_ERROR;
}
- str.length = (rp->exten_start != NULL) ? rp->target_end - rp->exten_start
- : 0;
- str.start = rp->exten_start;
-
- if (str.start != test->exten.start
- && !nxt_strstr_eq(&str, &test->exten))
+ 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, &str, &test->exten);
+ request, &rp->exten, &test->exten);
return NXT_ERROR;
}
- str.length = (rp->args_start != NULL) ? rp->target_end - rp->args_start
- : 0;
- str.start = rp->args_start;
-
- if (str.start != test->args.start
- && !nxt_strstr_eq(&str, &test->args))
+ if (rp->args.start != test->args.start
+ && !nxt_strstr_eq(&rp->args, &test->args))
{
nxt_log_alert(log, "http parse test case failed:\n"
" - request:\n\"%V\"\n"
" - args: \"%V\" (expected: \"%V\")",
- request, &str, &test->args);
+ request, &rp->args, &test->args);
return NXT_ERROR;
}