summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrei Zeliankou <zelenkov@nginx.com>2024-01-25 12:49:47 +0000
committerandrey-zelenkov <xim.andrew@gmail.com>2024-01-26 15:17:00 +0000
commit6452ca111c71188ab2813c763e6a0e86b48fbd56 (patch)
treefc6517df5824a385a506c6830258801f7130834c
parentba56e50ee77d11c45f569ba8fbc95e6dadb323ef (diff)
downloadunit-6452ca111c71188ab2813c763e6a0e86b48fbd56.tar.gz
unit-6452ca111c71188ab2813c763e6a0e86b48fbd56.tar.bz2
Node.js: fixed "httpVersion" variable format
According to the Node.js documenation this variable should only include numbering scheme. Thanks to @dbit-xia. Closes: https://github.com/nginx/unit/issues/1085
-rw-r--r--docs/changes.xml7
-rw-r--r--src/nodejs/unit-http/unit.cpp8
-rw-r--r--test/test_node_application.py2
3 files changed, 15 insertions, 2 deletions
diff --git a/docs/changes.xml b/docs/changes.xml
index 6b1aaf71..f226e4f4 100644
--- a/docs/changes.xml
+++ b/docs/changes.xml
@@ -40,6 +40,13 @@ with Next.js.
</para>
</change>
+<change type="bugfix">
+<para>
+ServerRequest.httpVersion variable format in Node.js module.
+</para>
+</change>
+
+
</changes>
diff --git a/src/nodejs/unit-http/unit.cpp b/src/nodejs/unit-http/unit.cpp
index 7912d0ac..7d9395bb 100644
--- a/src/nodejs/unit-http/unit.cpp
+++ b/src/nodejs/unit-http/unit.cpp
@@ -581,6 +581,7 @@ Unit::get_server_object()
void
Unit::create_headers(nxt_unit_request_info_t *req, napi_value request)
{
+ char *p;
uint32_t i;
napi_value headers, raw_headers;
napi_status status;
@@ -602,7 +603,12 @@ Unit::create_headers(nxt_unit_request_info_t *req, napi_value request)
set_named_property(request, "headers", headers);
set_named_property(request, "rawHeaders", raw_headers);
- set_named_property(request, "httpVersion", r->version, r->version_length);
+
+ // trim the "HTTP/" protocol prefix
+ p = (char *) nxt_unit_sptr_get(&r->version);
+ p += 5;
+
+ set_named_property(request, "httpVersion", create_string_latin1(p, 3));
set_named_property(request, "method", r->method, r->method_length);
set_named_property(request, "url", r->target, r->target_length);
diff --git a/test/test_node_application.py b/test/test_node_application.py
index aaad2bcf..cb775210 100644
--- a/test/test_node_application.py
+++ b/test/test_node_application.py
@@ -80,7 +80,7 @@ def test_node_application_variables(date_to_sec_epoch, sec_epoch):
'Request-Method': 'POST',
'Request-Uri': '/',
'Http-Host': 'localhost',
- 'Server-Protocol': 'HTTP/1.1',
+ 'Server-Protocol': '1.1',
'Custom-Header': 'blah',
}, 'headers'
assert resp['body'] == body, 'body'