Skip to content

Commit

Permalink
http: Ensure REQUEST_URI immutability
Browse files Browse the repository at this point in the history
Previously, the REQUEST_URI within Unit could be modified,
for example, during uri rewriting. We decide to make $request_uri
immutable and pass constant REQUEST_URI to applications.
Based on the new requirement, we remove `r->target` rewriting
in the rewrite module.

Closes: #916
Reviewed-by: Andrew Clayton <[email protected]>
Signed-off-by: Zhidao HONG <[email protected]>
  • Loading branch information
hongzhidao committed May 9, 2024
1 parent 05a8229 commit 87077ec
Showing 1 changed file with 2 additions and 27 deletions.
29 changes: 2 additions & 27 deletions src/nxt_http_rewrite.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ nxt_http_rewrite_init(nxt_router_conf_t *rtcf, nxt_http_action_t *action,
nxt_int_t
nxt_http_rewrite(nxt_task_t *task, nxt_http_request_t *r)
{
u_char *p;
nxt_int_t ret;
nxt_str_t str, encoded_path, target;
nxt_str_t str;
nxt_router_conf_t *rtcf;
nxt_http_action_t *action;
nxt_http_request_parse_t rp;
Expand Down Expand Up @@ -72,30 +71,6 @@ nxt_http_rewrite(nxt_task_t *task, nxt_http_request_t *r)
return NXT_ERROR;
}

p = (rp.args.length > 0) ? rp.args.start - 1 : rp.target_end;

encoded_path.start = rp.target_start;
encoded_path.length = p - encoded_path.start;

if (r->args->length == 0) {
r->target = encoded_path;

} else {
target.length = encoded_path.length + 1 + r->args->length;

target.start = nxt_mp_alloc(r->mem_pool, target.length);
if (target.start == NULL) {
return NXT_ERROR;
}

p = nxt_cpymem(target.start, encoded_path.start, encoded_path.length);
*p++ = '?';
nxt_memcpy(p, r->args->start, r->args->length);

r->target = target;
r->args->start = p;
}

r->path = nxt_mp_alloc(r->mem_pool, sizeof(nxt_str_t));
if (nxt_slow_path(r->path == NULL)) {
return NXT_ERROR;
Expand All @@ -107,7 +82,7 @@ nxt_http_rewrite(nxt_task_t *task, nxt_http_request_t *r)
r->quoted_target = rp.quoted_target;

if (nxt_slow_path(r->log_route)) {
nxt_log(task, NXT_LOG_NOTICE, "URI rewritten to \"%V\"", &r->target);
nxt_log(task, NXT_LOG_NOTICE, "URI rewritten to \"%V\"", r->path);
}

return NXT_OK;
Expand Down

0 comments on commit 87077ec

Please sign in to comment.