From a0029b21a1665f6e1c22e6b599bce4e92c5ff16e Mon Sep 17 00:00:00 2001 From: Glenn Strauss Date: Mon, 20 Jan 2020 10:56:54 -0500 Subject: [PATCH] [core] remove r->uri.path_raw; generate as needed (r->uri.path_raw previously duplicated from r->target, minus query-part) --- src/connections.c | 4 ---- src/keyvalue.c | 6 +++++- src/mod_accesslog.c | 6 +++++- src/mod_deflate.c | 2 +- src/mod_magnet.c | 1 - src/mod_redirect.c | 2 +- src/mod_rewrite.c | 2 +- src/request.c | 14 ++++++-------- src/request.h | 1 - src/response.c | 2 -- 10 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/connections.c b/src/connections.c index 58a8bb1c..2072d500 100644 --- a/src/connections.c +++ b/src/connections.c @@ -124,7 +124,6 @@ static void connection_close(connection *con) { buffer_reset(&r->target_orig); buffer_reset(&r->target); /*(see comments in connection_reset())*/ buffer_reset(&r->pathinfo); /*(see comments in connection_reset())*/ - buffer_reset(&r->uri.path_raw); /*(see comments in connection_reset())*/ chunkqueue_reset(con->read_queue); con->request_count = 0; @@ -599,7 +598,6 @@ void connections_free(server *srv) { free(r->uri.scheme.ptr); free(r->uri.authority.ptr); free(r->uri.path.ptr); - free(r->uri.path_raw.ptr); free(r->uri.query.ptr); free(r->physical.doc_root.ptr); @@ -660,7 +658,6 @@ static int connection_reset(connection *con) { * is a typical case, the larger buffers are likely to be reused) */ buffer_clear(&r->target); buffer_clear(&r->pathinfo); - buffer_clear(&r->uri.path_raw); /*buffer_clear(&r->target_orig);*/ /* reset later; used by mod_status*/ /*buffer_clear(&r->uri.path);*/ /* reset later; used by mod_status*/ /*buffer_clear(&r->uri.query);*/ /* reset later; used by mod_status*/ @@ -670,7 +667,6 @@ static int connection_reset(connection *con) { else { buffer_reset(&r->target); buffer_reset(&r->pathinfo); - buffer_reset(&r->uri.path_raw); /*buffer_reset(&r->target_orig);*/ /* reset later; used by mod_status*/ /*buffer_reset(&r->uri.path);*/ /* reset later; used by mod_status*/ /*buffer_reset(&r->uri.query);*/ /* reset later; used by mod_status*/ diff --git a/src/keyvalue.c b/src/keyvalue.c index 36aa27b8..7b647b5c 100644 --- a/src/keyvalue.c +++ b/src/keyvalue.c @@ -181,7 +181,11 @@ static int pcre_keyvalue_buffer_subst_ext(buffer *b, const char *pattern, const p+=4; } else if (0 == strncmp((const char *)p, "path}", 5)) { - burl_append(b, CONST_BUF_LEN(ctx->burl->path), flags); + const buffer * const target = ctx->burl->path; + const uint32_t len = buffer_string_length(target); + const char * const ptr = target->ptr; + const char * const qmark = memchr(ptr, '?', len); + burl_append(b, ptr, qmark ? (uint32_t)(qmark-ptr) : len, flags); p+=4; } else if (0 == strncmp((const char *)p, "query}", 6)) { diff --git a/src/mod_accesslog.c b/src/mod_accesslog.c index 922527a9..cd6c4bb7 100644 --- a/src/mod_accesslog.c +++ b/src/mod_accesslog.c @@ -1072,7 +1072,11 @@ static int log_access_record (const request_st * const r, buffer * const b, form accesslog_append_escaped(b, &r->uri.query); break; case FORMAT_URL: - accesslog_append_escaped(b, &r->uri.path_raw); + { + const uint32_t len = buffer_string_length(&r->target); + const char * const qmark = memchr(r->target.ptr, '?', len); + accesslog_append_escaped_str(b, r->target.ptr, qmark ? (uint32_t)(qmark - r->target.ptr) : len); + } break; case FORMAT_CONNECTION_STATUS: if (r->state == CON_STATE_RESPONSE_END) { diff --git a/src/mod_deflate.c b/src/mod_deflate.c index 0dd2dfe9..7d75ee86 100644 --- a/src/mod_deflate.c +++ b/src/mod_deflate.c @@ -746,7 +746,7 @@ static void deflate_compress_cleanup(request_st * const r, handler_ctx * const h #if 1 /* unnecessary if deflate.min-compress-size is set to a reasonable value */ if (hctx->bytes_in < hctx->bytes_out) { log_error(r->conf.errh, __FILE__, __LINE__, - "uri %s in=%lld smaller than out=%lld", r->uri.path_raw.ptr, + "uri %s in=%lld smaller than out=%lld", r->target.ptr, (long long)hctx->bytes_in, (long long)hctx->bytes_out); } #endif diff --git a/src/mod_magnet.c b/src/mod_magnet.c index 55fd1dc2..47b6dc6b 100644 --- a/src/mod_magnet.c +++ b/src/mod_magnet.c @@ -569,7 +569,6 @@ static int magnet_env_set(lua_State *L) { const_buffer val = { NULL, 0 }; if (!lua_isnil(L, 3)) val = magnet_checkconstbuffer(L, 3); - buffer_copy_string_len(&r->uri.path_raw,val.ptr,val.len);/*(temporary)*/ if (NULL != qmark) buffer_copy_string_len(r->tmp_buf, qmark, len - (uint32_t)(qmark - r->target.ptr)); diff --git a/src/mod_redirect.c b/src/mod_redirect.c index 1458e095..45fbb845 100644 --- a/src/mod_redirect.c +++ b/src/mod_redirect.c @@ -165,7 +165,7 @@ URIHANDLER_FUNC(mod_redirect_uri_handler) { burl.scheme = &r->uri.scheme; burl.authority = &r->uri.authority; burl.port = sock_addr_get_port(&r->con->srv_socket->addr); - burl.path = &r->uri.path_raw; + burl.path = &r->target; /*(uri-encoded and includes query-part)*/ burl.query = &r->uri.query; if (buffer_string_is_empty(burl.authority)) burl.authority = r->server_name; diff --git a/src/mod_rewrite.c b/src/mod_rewrite.c index bf527f1f..8a4b595a 100644 --- a/src/mod_rewrite.c +++ b/src/mod_rewrite.c @@ -284,7 +284,7 @@ static handler_t process_rewrite_rules(request_st * const r, plugin_data *p, con burl.scheme = &r->uri.scheme; burl.authority = &r->uri.authority; burl.port = sock_addr_get_port(&r->con->srv_socket->addr); - burl.path = &r->uri.path_raw; + burl.path = &r->target; /*(uri-encoded and includes query-part)*/ burl.query = &r->uri.query; if (buffer_string_is_empty(burl.authority)) burl.authority = r->server_name; diff --git a/src/request.c b/src/request.c index eb151564..a6e270de 100644 --- a/src/request.c +++ b/src/request.c @@ -653,7 +653,6 @@ int http_request_parse_target(request_st * const r, int scheme_port) { /** * prepare strings * - * - uri.path_raw * - uri.path * - uri.query * @@ -693,7 +692,6 @@ int http_request_parse_target(request_st * const r, int scheme_port) { && target->ptr[0] == '*' && target->ptr[1] == '\0')) { /* CONNECT ... (or) OPTIONS * ... */ - buffer_copy_buffer(&r->uri.path_raw, target); buffer_copy_buffer(&r->uri.path, target); buffer_clear(&r->uri.query); return 0; @@ -740,17 +738,18 @@ int http_request_parse_target(request_st * const r, int scheme_port) { } /** extract query string from target */ + const char * const pstr = target->ptr; + const uint32_t rlen = buffer_string_length(target); + uint32_t plen; if (NULL != qstr) { - const char * const pstr = target->ptr; - const size_t plen = (size_t)(qstr - pstr); - const size_t rlen = buffer_string_length(target); + plen = (uint32_t)(qstr - pstr); buffer_copy_string_len(&r->uri.query, qstr + 1, rlen - plen - 1); - buffer_copy_string_len(&r->uri.path_raw, pstr, plen); } else { + plen = rlen; buffer_clear(&r->uri.query); - buffer_copy_buffer(&r->uri.path_raw, target); } + buffer_copy_string_len(&r->uri.path, pstr, plen); /* decode url to path * @@ -758,7 +757,6 @@ int http_request_parse_target(request_st * const r, int scheme_port) { * - remove path-modifiers (e.g. /../) */ - buffer_copy_buffer(&r->uri.path, &r->uri.path_raw); buffer_urldecode_path(&r->uri.path); buffer_path_simplify(&r->uri.path, &r->uri.path); if (r->uri.path.ptr[0] != '/') { diff --git a/src/request.h b/src/request.h index 63b42097..996a6c5a 100644 --- a/src/request.h +++ b/src/request.h @@ -82,7 +82,6 @@ typedef struct { /* path including leading slash ("/" or "/index.html") - urldecoded, and sanitized ( buffer_path_simplify() && buffer_urldecode_path() ) */ buffer path; - buffer path_raw; /* raw path, as sent from client. no urldecoding or path simplifying */ buffer query; /* querystring ( everything after "?", ie: in "/index.php?foo=1", query is "foo=1" ) */ } request_uri; diff --git a/src/response.c b/src/response.c index 096a384c..40d7ec1a 100644 --- a/src/response.c +++ b/src/response.c @@ -355,8 +355,6 @@ handler_t http_response_prepare(request_st * const r) { "URI-scheme : %s", r->uri.scheme.ptr); log_error(r->conf.errh, __FILE__, __LINE__, "URI-authority : %s", r->uri.authority.ptr); - log_error(r->conf.errh, __FILE__, __LINE__, - "URI-path (raw) : %s", r->uri.path_raw.ptr); log_error(r->conf.errh, __FILE__, __LINE__, "URI-path (clean): %s", r->uri.path.ptr); log_error(r->conf.errh, __FILE__, __LINE__,