details:   http://freenginx.org/hg/nginx/rev/865956fd7ae6
branches:  
changeset: 9416:865956fd7ae6
user:      Maxim Dounin <[email protected]>
date:      Thu Aug 21 23:49:43 2025 +0300
description:
Updated request line parsing to use if() in IP literals.

Using if() results in more readable code and matches the code used in host
parsing, where it is not convenient to use switch().  Besides, it is slightly
faster than switch() on typical inputs.

diffstat:

 src/http/ngx_http_parse.c |  37 +++++++++++++------------------------
 1 files changed, 13 insertions(+), 24 deletions(-)

diffs (51 lines):

diff --git a/src/http/ngx_http_parse.c b/src/http/ngx_http_parse.c
--- a/src/http/ngx_http_parse.c
+++ b/src/http/ngx_http_parse.c
@@ -450,34 +450,23 @@ ngx_http_parse_request_line(ngx_http_req
                 break;
             }
 
+            if (ch == ':') {
+                break;
+            }
+
+            if (ch == '.' || ch == '-' || ch == '_' || ch == '~'
+                || ch == '!' || ch == '$' || ch == '&' || ch == '\''
+                || ch == '(' || ch == ')' || ch == '*' || ch == '+'
+                || ch == ',' || ch == ';' || ch == '=' || ch == '%')
+            {
+                /* unreserved, sub-delims, pct-encoded */
+                break;
+            }
+
             switch (ch) {
-            case ':':
-                break;
             case ']':
                 state = sw_host_end;
                 break;
-            case '-':
-            case '.':
-            case '_':
-            case '~':
-                /* unreserved */
-                break;
-            case '!':
-            case '$':
-            case '&':
-            case '\'':
-            case '(':
-            case ')':
-            case '*':
-            case '+':
-            case ',':
-            case ';':
-            case '=':
-                /* sub-delims */
-                break;
-            case '%':
-                /* pct-encoded */
-                break;
             default:
                 return NGX_HTTP_PARSE_INVALID_REQUEST;
             }

Reply via email to