changeset 2615:59872fdb9291

Fetch: added parsing of HTTP version.
author Dmitry Volyntsev <xeioex@nginx.com>
date Fri, 12 Sep 2025 19:10:32 -0700
parents 985647d6bdb6
children db32e358a1fd
files nginx/ngx_js_http.c nginx/ngx_js_http.h
diffstat 2 files changed, 24 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/nginx/ngx_js_http.c	Wed Sep 03 22:44:04 2025 -0700
+++ b/nginx/ngx_js_http.c	Fri Sep 12 19:10:32 2025 -0700
@@ -942,6 +942,12 @@
                 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 @@
                 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 @@
                 return NGX_ERROR;
             }
 
+            hp->http_minor = ch - '0';
             state = sw_minor_digit;
             break;
 
@@ -978,6 +991,12 @@
                 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 @@
     b->pos = p + 1;
     hp->state = sw_start;
 
+    hp->http_version = hp->http_major * 1000 + hp->http_minor;
+
     return NGX_OK;
 }
 
--- a/nginx/ngx_js_http.h	Wed Sep 03 22:44:04 2025 -0700
+++ b/nginx/ngx_js_http.h	Fri Sep 12 19:10:32 2025 -0700
@@ -16,6 +16,9 @@
 
 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;