Skip to content

Commit 87e7113

Browse files
committed
updated header integration
1 parent 2b4ee2c commit 87e7113

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@chadkluck/cache-data",
3-
"version": "1.0.5",
3+
"version": "1.0.6",
44
"description": "Cache data from an API endpoint or application process using AWS S3 and DynamoDb",
55
"author": "Chad Leigh Kluck (https://chadkluck.net)",
66
"license": "MIT",

src/lib/tools.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,11 @@ class APIRequest {
233233
if ( "method" in request && request.method !== "" && request.method !== null) { req.method = request.method.toUpperCase(); }
234234
if ( "protocol" in request && request.protocol !== "" && request.protocol !== null) { req.protocol = request.protocol.toLowerCase(); }
235235

236+
if ("body" in request) { req.body = request.body; }
237+
if ("headers" in request) { req.headers = request.headers; }
238+
if ("note" in request) { req.note = request.note; }
239+
if ("options" in request) { req.options = request.options; }
240+
236241
/* if we have a uri, set it, otherwise form one using host and path */
237242
if ( "uri" in request && request.uri !== null && request.uri !== "" ) {
238243
req.uri = request.uri;

test/test.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,37 @@ describe("Call test endpoint", () => {
5252
&& expect(obj.hiddengames[0]).to.equal("Tic-Tac-Toe")
5353
})
5454

55+
it('Headers were passed along', async () => {
56+
57+
let headers = {
58+
Authorization: "Basic somerandomExampleKey",
59+
'if-none-match': "528cd81ca4",
60+
'if-modified-since': "Mon, 14 Feb 2022 03:44:00 GMT",
61+
'x-my-custom-header': "hello world"
62+
};
63+
let req = new tools.APIRequest({
64+
method: "POST",
65+
host: "labkit.api.63klabs.net",
66+
path: "/echo/",
67+
headers: headers,
68+
uri: "",
69+
protocol: "https",
70+
body: null,
71+
parameters: {}
72+
})
73+
const result = await req.send()
74+
const obj = JSON.parse(result.body);
75+
76+
expect(result.statusCode).to.equal(200)
77+
&& expect(result.success).to.equal(true)
78+
&& expect((typeof result.headers)).to.equal('object')
79+
&& expect(result.message).to.equal("SUCCESS")
80+
&& expect(obj.headers.Authorization).to.equal(headers.Authorization)
81+
&& expect(obj.headers['if-none-match']).to.equal(headers['if-none-match'])
82+
&& expect(obj.headers['if-modified-since']).to.equal(headers['if-modified-since'])
83+
&& expect(obj.headers['x-my-custom-header']).to.equal(headers['x-my-custom-header'])
84+
});
85+
5586
it('Passing host and path and an empty uri results in success with a hidden game listed', async () => {
5687
let req = new tools.APIRequest({host: 'api.chadkluck.net', path: '/games/', uri: ''})
5788
const result = await req.send()

0 commit comments

Comments
 (0)