Created
July 28, 2017 13:54
-
-
Save guoxiaoqiao/5b0b7a679a95cf8eaef510cf3716cc24 to your computer and use it in GitHub Desktop.
nginx日志支持中文URL显示的补丁
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -Nur nginx-1.12.1/src/http/ngx_http_request.c nginx-1.12.1-unescape/src/http/ngx_http_request.c | |
--- nginx-1.12.1/src/http/ngx_http_request.c 2017-07-11 21:24:09.000000000 +0800 | |
+++ nginx-1.12.1-unescape/src/http/ngx_http_request.c 2017-07-19 12:35:57.345284961 +0800 | |
@@ -924,6 +924,13 @@ | |
ngx_str_t host; | |
ngx_connection_t *c; | |
ngx_http_request_t *r; | |
+ /* 允许取消转义的最大URL长度 */ | |
+ #define ALLOW_LEN 512 | |
+ char tmp[ALLOW_LEN] = {0}; | |
+ char* tmp_p = &tmp; | |
+ int old_len, new_len; | |
+ u_char* url_start_pos; | |
+ char* url_end_pos; | |
c = rev->data; | |
r = c->data; | |
@@ -950,6 +957,19 @@ | |
} | |
} | |
+ url_end_pos = strstr((char*)r->header_in->start, " HTTP/1.1"); | |
+ old_len = url_end_pos - (char*)r->header_in->start; | |
+ if (url_end_pos && old_len <= ALLOW_LEN) { | |
+ url_start_pos = r->header_in->start; | |
+ ngx_unescape_uri(&tmp_p, &url_start_pos, old_len, 0); | |
+ new_len = strlen(tmp); | |
+ if (new_len != old_len) { | |
+ r->header_in->start = r->header_in->start + (old_len - new_len); | |
+ r->header_in->pos = r->header_in->start; | |
+ memcpy(r->header_in->start, tmp, new_len); | |
+ } | |
+ } | |
+ | |
rc = ngx_http_parse_request_line(r, r->header_in); | |
if (rc == NGX_OK) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment