Skip to content

Commit afa8cc5

Browse files
sacru2redw666
andauthored
Do not set Connection header when forever is not set (#1259)
Co-authored-by: Vasily Martynov <[email protected]>
1 parent 22ffd32 commit afa8cc5

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

src/http.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class HttpClient implements IHttpClient {
6161
'Accept': 'text/html,application/xhtml+xml,application/xml,text/xml;q=0.9,*/*;q=0.8',
6262
'Accept-Encoding': 'none',
6363
'Accept-Charset': 'utf-8',
64-
'Connection': exoptions.forever ? 'keep-alive' : 'close',
64+
...(exoptions.forever && { Connection: 'keep-alive' }),
6565
'Host': host + (isNaN(port) ? '' : ':' + port),
6666
};
6767
const mergeOptions = ['headers'];

test/client-test.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,3 +1833,58 @@ describe('Client posting complex body', () => {
18331833
}, baseUrl);
18341834
});
18351835
});
1836+
1837+
describe('Connection header', () => {
1838+
var server = null;
1839+
var hostname = '127.0.0.1';
1840+
var port = 15099;
1841+
var baseUrl = 'http://' + hostname + ':' + port;
1842+
1843+
before(function (done) {
1844+
server = http.createServer(function (req, res) {
1845+
res.statusCode = 200;
1846+
res.write(JSON.stringify({ tempResponse: 'temp' }), 'utf8');
1847+
res.end();
1848+
}).listen(port, hostname, done);
1849+
});
1850+
1851+
after(function (done) {
1852+
server.close();
1853+
server = null;
1854+
done();
1855+
});
1856+
1857+
it('should set Connection header to keep-alive when forever option is true', function (done) {
1858+
soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', function (err, client) {
1859+
assert.ok(client);
1860+
assert.ifError(err);
1861+
client.MyOperation({}, { forever: true }, function () {
1862+
assert.strictEqual(client.lastRequestHeaders.Connection, 'keep-alive');
1863+
done();
1864+
}, null, null);
1865+
}, baseUrl);
1866+
});
1867+
1868+
it('should not set Connection header when forever option is false', function (done) {
1869+
soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', function (err, client) {
1870+
assert.ok(client);
1871+
assert.ifError(err);
1872+
client.MyOperation({}, { forever: false }, function () {
1873+
assert.strictEqual(client.lastRequestHeaders.Connection, undefined);
1874+
done();
1875+
}, null, null);
1876+
}, baseUrl);
1877+
});
1878+
1879+
it('should not set Connection header when forever option is not set', function (done) {
1880+
soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', function (err, client) {
1881+
assert.ok(client);
1882+
assert.ifError(err);
1883+
1884+
client.MyOperation({}, function () {
1885+
assert.strictEqual(client.lastRequestHeaders.Connection, undefined);
1886+
done();
1887+
}, null, null);
1888+
}, baseUrl);
1889+
});
1890+
});

0 commit comments

Comments
 (0)