Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

added possibility to add action to content-type header #1073

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ export class Client extends EventEmitter {
this.wsdl.options.overrideRootElement = options.overrideRootElement;
}
this.wsdl.options.forceSoap12Headers = !!options.forceSoap12Headers;
this.wsdl.options.addHeadersAction = !!options.addHeadersAction;
}

private _defineService(service: ServiceElement, endpoint?: string) {
Expand Down Expand Up @@ -351,11 +352,6 @@ export class Client extends EventEmitter {
return finish(obj, body, response);
};

if (this.wsdl.options.forceSoap12Headers) {
headers['Content-Type'] = 'application/soap+xml; charset=utf-8';
xmlnsSoap = 'xmlns:' + envelopeKey + '="http://www.w3.org/2003/05/soap-envelope"';
}

if (this.SOAPAction) {
soapAction = this.SOAPAction;
} else if (method.soapAction !== undefined && method.soapAction !== null) {
Expand All @@ -364,7 +360,13 @@ export class Client extends EventEmitter {
soapAction = ((ns.lastIndexOf('/') !== ns.length - 1) ? ns + '/' : ns) + name;
}

if (!this.wsdl.options.forceSoap12Headers) {
if (this.wsdl.options.forceSoap12Headers) {
headers['Content-Type'] = 'application/soap+xml; charset=utf-8';
if (this.wsdl.options.addHeadersAction) {
Copy link
Contributor

@gbar gbar Jun 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to specification from https://docs.intersystems.com/latest/csp/docbook/DocBook.UI.Page.cls?KEY=ROBJ_method_soapaction action param should be added within forceSoap12Headers flag, not some additional one as because it is required in 1.2 version

headers['Content-Type'] += '; action=' + soapAction;
}
xmlnsSoap = 'xmlns:' + envelopeKey + '="http://www.w3.org/2003/05/soap-envelope"';
} else {
headers.SOAPAction = '"' + soapAction + '"';
}

Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ export interface IWsdlBaseOptions {
wsdl_options?: { [key: string]: any };
/** set proper headers for SOAP v1.2. */
forceSoap12Headers?: boolean;
/** set content type header action for SOAP v1.2 */
addHeadersAction?: boolean;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gbar can you follow up with a PR to add this to the README please?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will add that when I get home. Will create another PR with that

}

/** @deprecated use IOptions */
Expand Down
1 change: 1 addition & 0 deletions src/wsdl/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,7 @@ export class WSDL {

// Works only in client
this.options.forceSoap12Headers = options.forceSoap12Headers;
this.options.addHeadersAction = options.addHeadersAction;
this.options.customDeserializer = options.customDeserializer;

if (options.overrideRootElement !== undefined) {
Expand Down
17 changes: 17 additions & 0 deletions test/client-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,23 @@ var fs = require('fs'),
}, baseUrl);
});

it('should add proper headers for soap12 with action in content type', function (done) {
soap.createClient(__dirname + '/wsdl/default_namespace_soap12.wsdl', _.assign({ forceSoap12Headers: true, addHeadersAction: true}, meta.options), function (err, client) {
assert.ok(client);
assert.ifError(err);

client.MyOperation({}, function (err, result) {
assert.ok(result);
assert.ok(client.lastRequestHeaders);
assert.ok(client.lastRequest);
assert.equal(client.lastRequestHeaders['Content-Type'], 'application/soap+xml; charset=utf-8; action=MyOperation');
assert.notEqual(client.lastRequest.indexOf('xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\"'), -1);
assert(!client.lastRequestHeaders.SOAPAction);
done();
}, null, { 'test-header': 'test' });
}, baseUrl);
});

it('should allow calling the method with args, callback, options and extra headers', function (done) {
soap.createClient(__dirname + '/wsdl/json_response.wsdl', meta.options, function (err, client) {
assert.ok(client);
Expand Down