From: Dmitry Volyntsev Date: Sat, 13 Sep 2025 02:10:32 +0000 (-0700) Subject: Fetch: added parsing of HTTP version. X-Git-Tag: 0.9.2~4 X-Git-Url: http://www.kaiwu.me/postgresql/commit/static/gitweb.js?a=commitdiff_plain;h=8fcffdc3090985f49e9c2ecb4043d246514bde50;p=njs.git Fetch: added parsing of HTTP version. --- diff --git a/nginx/ngx_js_http.c b/nginx/ngx_js_http.c index 92e7b94b..3f52868e 100644 --- a/nginx/ngx_js_http.c +++ b/nginx/ngx_js_http.c @@ -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; } diff --git a/nginx/ngx_js_http.h b/nginx/ngx_js_http.h index 027d0b21..7adcc130 100644 --- a/nginx/ngx_js_http.h +++ b/nginx/ngx_js_http.h @@ -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;