summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrei Zeliankou <zelenkov@nginx.com>2023-11-17 17:27:31 +0000
committerAndrei Zeliankou <zelenkov@nginx.com>2023-11-17 17:27:31 +0000
commit1443d623d4b5d59e4463e025b4125be9a5aa3436 (patch)
tree72207d13dd32510cb40f6586b840921d0bc14bf8
parent919cae7ff95a3ce5878731a8d23f34c75489d3b4 (diff)
downloadunit-1443d623d4b5d59e4463e025b4125be9a5aa3436.tar.gz
unit-1443d623d4b5d59e4463e025b4125be9a5aa3436.tar.bz2
Node.js: ServerResponse.flushHeaders() implemented.
This closes #1006 issue on GitHub. Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
-rw-r--r--docs/changes.xml7
-rw-r--r--src/nodejs/unit-http/http_server.js4
-rw-r--r--test/node/flush_headers/app.js7
-rw-r--r--test/test_node_application.py4
4 files changed, 22 insertions, 0 deletions
diff --git a/docs/changes.xml b/docs/changes.xml
index 2c01a1e0..6b1aaf71 100644
--- a/docs/changes.xml
+++ b/docs/changes.xml
@@ -33,6 +33,13 @@ can be used as a unique request identifier.
</para>
</change>
+<change type="feature">
+<para>
+ServerRequest.flushHeaders() implemented in Node.js module to make it compatible
+with Next.js.
+</para>
+</change>
+
</changes>
diff --git a/src/nodejs/unit-http/http_server.js b/src/nodejs/unit-http/http_server.js
index 0f00b47f..8eb13d7f 100644
--- a/src/nodejs/unit-http/http_server.js
+++ b/src/nodejs/unit-http/http_server.js
@@ -138,6 +138,10 @@ ServerResponse.prototype.removeHeader = function removeHeader(name) {
}
};
+ServerResponse.prototype.flushHeaders = function flushHeaders() {
+ this._sendHeaders();
+};
+
ServerResponse.prototype._removeHeader = function _removeHeader(lc_name) {
let entry = this.headers[lc_name];
let name_len = Buffer.byteLength(entry[0] + "", 'latin1');
diff --git a/test/node/flush_headers/app.js b/test/node/flush_headers/app.js
new file mode 100644
index 00000000..4c0e93bc
--- /dev/null
+++ b/test/node/flush_headers/app.js
@@ -0,0 +1,7 @@
+
+require('http').createServer(function (req, res) {
+ res.setHeader('X-Header', 'blah');
+ res.flushHeaders();
+ res.flushHeaders(); // Should be idempotent.
+ res.end();
+}).listen(8080);
diff --git a/test/test_node_application.py b/test/test_node_application.py
index ab8aa8f8..5077b9cb 100644
--- a/test/test_node_application.py
+++ b/test/test_node_application.py
@@ -303,6 +303,10 @@ def test_node_application_get_header_names():
'x-header',
], 'get header names'
+def test_node_application_flush_headers():
+ client.load('flush_headers')
+
+ assert client.get()['headers']['X-Header'] == 'blah'
def test_node_application_has_header():
client.load('has_header')