aboutsummaryrefslogtreecommitdiff
path: root/nginx/t/js_fetch_objects.t
diff options
context:
space:
mode:
authorDmitry Volyntsev <xeioex@nginx.com>2023-06-22 15:40:36 -0700
committerDmitry Volyntsev <xeioex@nginx.com>2023-06-22 15:40:36 -0700
commit5b463b8050377216ad4197cd1e35bb69b35b77e9 (patch)
treeb21ee0e101940cc7af806a184c79d4ec32818e61 /nginx/t/js_fetch_objects.t
parent295213f8a51c3ebaf4e9c4fcedda13477378708b (diff)
downloadnjs-5b463b8050377216ad4197cd1e35bb69b35b77e9.tar.gz
njs-5b463b8050377216ad4197cd1e35bb69b35b77e9.zip
Fetch: fixed setting of Content-Type header.
Previously, Content-Type was set unconditionally to "text/plain;charset=UTF-8" when fetch request contained a string body. This may overlap with user's Content-Type. The fix is to set the header only if it was not set before. This fixes #654 issue on Github.
Diffstat (limited to 'nginx/t/js_fetch_objects.t')
-rw-r--r--nginx/t/js_fetch_objects.t21
1 files changed, 21 insertions, 0 deletions
diff --git a/nginx/t/js_fetch_objects.t b/nginx/t/js_fetch_objects.t
index edc3be57..c8001823 100644
--- a/nginx/t/js_fetch_objects.t
+++ b/nginx/t/js_fetch_objects.t
@@ -373,6 +373,27 @@ $t->write_file('test.js', <<EOF);
var body = await r.text();
return `\${body}: \${r.headers.get('Content-Type')}`;
}, 'ABC: text/plain;charset=UTF-8'],
+ ['user content type', async () => {
+ var r = new Request("http://nginx.org",
+ {body: 'ABC',
+ headers: {'Content-Type': 'text/html'}});
+ return r.headers.get('Content-Type');
+ }, 'text/html'],
+ ['user content type from Headers()', async () => {
+ var h = new Headers();
+ h.append('Content-Type', 'text/html');
+ var r = new Request("http://nginx.org",
+ {body: 'ABC', headers: h});
+ return r.headers.get('Content-Type');
+ }, 'text/html'],
+ ['user content type deleted', async () => {
+ var h = new Headers();
+ h.append('Content-Type', 'text/html');
+ h.delete('Content-Type');
+ var r = new Request("http://nginx.org",
+ {body: 'ABC', headers: h});
+ return r.headers.get('Content-Type');
+ }, 'text/plain;charset=UTF-8'],
['GET body', () => {
try {
var r = new Request("http://nginx.org", {body: 'ABC'});