Skip to content

Commit

Permalink
Do not set Connection header when forever is not set, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
w666 committed Oct 30, 2024
1 parent 364cc4e commit a74e838
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class HttpClient implements IHttpClient {
'Accept': 'text/html,application/xhtml+xml,application/xml,text/xml;q=0.9,*/*;q=0.8',
'Accept-Encoding': 'none',
'Accept-Charset': 'utf-8',
'Connection': exoptions.forever ? 'keep-alive' : null,
...(exoptions.forever && { 'Connection': 'keep-alive' }),
'Host': host + (isNaN(port) ? '' : ':' + port),
};
const mergeOptions = ['headers'];
Expand Down
55 changes: 55 additions & 0 deletions test/client-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1833,3 +1833,58 @@ describe('Client posting complex body', () => {
}, baseUrl);
});
});

describe('Connection header', () => {
var server = null;
var hostname = '127.0.0.1';
var port = 15099;
var baseUrl = 'http://' + hostname + ':' + port;

before(function (done) {
server = http.createServer(function (req, res) {
res.statusCode = 200;
res.write(JSON.stringify({ tempResponse: 'temp' }), 'utf8');
res.end();
}).listen(port, hostname, done);
});

after(function (done) {
server.close();
server = null;
done();
});

it('should set Connection header to keep-alive when forever option is true', function (done) {
soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', function (err, client) {
assert.ok(client);
assert.ifError(err);
client.MyOperation({}, { forever: true }, function () {
assert.strictEqual(client.lastRequestHeaders.Connection, 'keep-alive');
done();
}, null, null);
}, baseUrl);
});

it('should not set Connection header when forever option is false', function (done) {
soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', function (err, client) {
assert.ok(client);
assert.ifError(err);
client.MyOperation({}, { forever: false }, function () {
assert.strictEqual(client.lastRequestHeaders.Connection, undefined);
done();
}, null, null);
}, baseUrl);
});

it('should not set Connection header when forever option is not set', function (done) {
soap.createClient(__dirname + '/wsdl/default_namespace.wsdl', function (err, client) {
assert.ok(client);
assert.ifError(err);

client.MyOperation({}, function () {
assert.strictEqual(client.lastRequestHeaders.Connection, undefined);
done();
}, null, null);
}, baseUrl);
});
});

0 comments on commit a74e838

Please sign in to comment.