]> git.kaiwu.me - njs.git/commitdiff
Fetch: added parsing of HTTP version.
authorDmitry Volyntsev <xeioex@nginx.com>
Sat, 13 Sep 2025 02:10:32 +0000 (19:10 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Tue, 16 Sep 2025 23:07:47 +0000 (16:07 -0700)
nginx/ngx_js_http.c
nginx/ngx_js_http.h

index 92e7b94b59c91dc71ca34d08ee266551adf5dd19..3f52868e23a0a20c8e7220070215805a93a7e48b 100644 (file)
@@ -942,6 +942,12 @@ ngx_js_http_parse_status_line(ngx_js_http_parse_t *hp, ngx_buf_t *b)
                 return NGX_ERROR;
             }
 
+            hp->http_major = ch - '0';
+
+            if (hp->http_major > 1) {
+                return NGX_ERROR;
+            }
+
             state = sw_major_digit;
             break;
 
@@ -956,6 +962,12 @@ ngx_js_http_parse_status_line(ngx_js_http_parse_t *hp, ngx_buf_t *b)
                 return NGX_ERROR;
             }
 
+            hp->http_major = hp->http_major * 10 + (ch - '0');
+
+            if (hp->http_major > 1) {
+                return NGX_ERROR;
+            }
+
             break;
 
         /* the first digit of minor HTTP version */
@@ -964,6 +976,7 @@ ngx_js_http_parse_status_line(ngx_js_http_parse_t *hp, ngx_buf_t *b)
                 return NGX_ERROR;
             }
 
+            hp->http_minor = ch - '0';
             state = sw_minor_digit;
             break;
 
@@ -978,6 +991,12 @@ ngx_js_http_parse_status_line(ngx_js_http_parse_t *hp, ngx_buf_t *b)
                 return NGX_ERROR;
             }
 
+            if (hp->http_minor > 99) {
+                return NGX_ERROR;
+            }
+
+            hp->http_minor = hp->http_minor * 10 + (ch - '0');
+
             break;
 
         /* HTTP status code */
@@ -1055,6 +1074,8 @@ done:
     b->pos = p + 1;
     hp->state = sw_start;
 
+    hp->http_version = hp->http_major * 1000 + hp->http_minor;
+
     return NGX_OK;
 }
 
index 027d0b2180e1763458a70cd970ec7fc32e0aaa4a..7adcc1308a9732c25f7dba6e48c1b0e53187302b 100644 (file)
@@ -16,6 +16,9 @@ typedef struct ngx_js_http_s  ngx_js_http_t;
 
 typedef struct {
     ngx_uint_t                     state;
+    unsigned                       http_major:16;
+    unsigned                       http_minor:16;
+    ngx_uint_t                     http_version;
     ngx_uint_t                     code;
     u_char                        *status_text;
     u_char                        *status_text_end;