Skip to content

Commit

Permalink
Add querystring to request before signing - fixes #5
Browse files Browse the repository at this point in the history
  • Loading branch information
SamVerschueren committed Dec 10, 2020
1 parent 9b3c718 commit 5be6cb4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const got4aws = (awsOptions: GotAWSOptions = {}) => {
const request = {
protocol: url.protocol,
host: url.host,
path: url.pathname,
path: url.pathname + url.search,
headers: signingHeaders,
body: options.json ? JSON.stringify(options.json) : options.body,
service: awsOptions.service,
Expand Down
19 changes: 19 additions & 0 deletions source/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ test.before(() => {
nock('http://www.example.com')
.get('/resource')
.reply(200, '{"unicorn":"🦄"}')
.get('/resource?unicorn=rainbow')
.reply(200, '{"unicorn":"rainbow"}')
.persist();

nock('https://rainbow.execute-api.eu-west-1.amazonaws.com')
Expand Down Expand Up @@ -69,6 +71,23 @@ test('provide service option', async t => {
});
});

test('use querystring', async t => {
const got = got4aws({
service: 'execute-api'
});

const result = await got('http://www.example.com/resource?unicorn=rainbow');

t.deepEqual(extractHeaders(result), {
'X-Amz-Date': '20200701T100000Z',
Authorization: 'AWS4-HMAC-SHA256 Credential=unicorn/20200701/us-east-1/execute-api/aws4_request, SignedHeaders=accept;accept-encoding;host;x-amz-date, Signature=a7367f1443e9ba4cc100382f053ffda70a6f880f010e742aa35a033cf6cf20d4'
});

t.deepEqual(result.body as unknown, {
unicorn: 'rainbow'
});
});

test('provide region option', async t => {
const got = got4aws({
service: 'execute-api',
Expand Down

0 comments on commit 5be6cb4

Please sign in to comment.