Skip to content

Commit

Permalink
#157 send query params in node http requests
Browse files Browse the repository at this point in the history
  • Loading branch information
ffendt committed May 27, 2021
1 parent 75b61ab commit 8342534
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion javascript/lib/node/src/node-http.ts
Expand Up @@ -92,14 +92,15 @@ export class NodeRequester implements HttpRequester {
if (body !== undefined && body !== '') {
header.set('Content-Length', Buffer.byteLength(body).toString());
}
const pathWithQueryParams = `${parsedUrl.pathname}${parsedUrl.search}`;
const headers: { [key: string]: any } = {};
header.forEach((v, k) => headers[k] = v);
return {
method,
headers,
hostname: parsedUrl.hostname,
port: parsedUrl.port,
path: parsedUrl.pathname,
path: pathWithQueryParams,
agent: this.getAgentForRequestType(isSecureRequest)
};
}
Expand Down
20 changes: 20 additions & 0 deletions javascript/lib/node/tests/node-http.spec.ts
Expand Up @@ -107,4 +107,24 @@ describe('NodeHttp', () => {
});
});

it('sends query params', () => {
const payload = 'hello';
const expectedResponsePayload = { foo: 'bar' };


nock('https://localhost:8080')
.get('/get?bum=baz', payload)
.reply(200, expectedResponsePayload);

const underTest = new NodeRequester(new ProxyAgent({}));

const request = underTest.doRequest('GET', 'https://localhost:8080/get?bum=baz', new Map(), payload);
return request
.then(response => {
expect(response.body).toEqual(expectedResponsePayload);
}, rejected => {
fail(rejected);
});
});

});

0 comments on commit 8342534

Please sign in to comment.