Skip to content

Commit f2ac067

Browse files
committed
set "Access-Control-Allow-Headers": "Test-Request" instead of "*"
1 parent fdfed2e commit f2ac067

File tree

6 files changed

+34
-27
lines changed

6 files changed

+34
-27
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html)
66

7+
## [4.4.1]  (2020-11-25)
8+
9+
### Changed
10+
11+
- Set `'Access-Control-Allow-Headers': 'Test-Request'` for support of the test-request header when `cors=true` is specified in API responses
12+
713
## [4.4.0]  (2020-11-24)
814

915
### Changed
@@ -336,6 +342,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/),
336342
- Update older libraries
337343
- Now publish from Git tags instead of master pushes
338344

345+
[4.4.1]: https://github.com/manwaring/lambda-wrapper/compare/v4.4.0...v4.4.1
339346
[4.4.0]: https://github.com/manwaring/lambda-wrapper/compare/v4.3.0...v4.4.0
340347
[4.3.0]: https://github.com/manwaring/lambda-wrapper/compare/v4.2.0...v4.3.0
341348
[4.2.0]: https://github.com/manwaring/lambda-wrapper/compare/v4.1.1...v4.2.0

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@manwaring/lambda-wrapper",
33
"description": "A lambda handler wrapper to abstract common functionality and provide useful defaults",
4-
"version": "4.4.0",
4+
"version": "4.4.1",
55
"scripts": {
66
"publish-please-dry-run": "publish-please --dry-run",
77
"publish-please": "publish-please",

src/api/shared/responses.test.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe("API responses", () => {
1111
body: JSON.stringify("success"),
1212
headers: {
1313
"Access-Control-Allow-Origin": "*",
14-
"Access-Control-Allow-Headers": "*",
14+
"Access-Control-Allow-Headers": "Test-Request",
1515
"Access-Control-Allow-Credentials": true,
1616
"Content-Type": "application/json",
1717
},
@@ -24,7 +24,7 @@ describe("API responses", () => {
2424
expect(response).toEqual({
2525
headers: {
2626
"Access-Control-Allow-Origin": "*",
27-
"Access-Control-Allow-Headers": "*",
27+
"Access-Control-Allow-Headers": "Test-Request",
2828
"Access-Control-Allow-Credentials": true,
2929
},
3030
statusCode: 200,
@@ -49,7 +49,7 @@ describe("API responses", () => {
4949
body,
5050
headers: {
5151
"Access-Control-Allow-Origin": "*",
52-
"Access-Control-Allow-Headers": "*",
52+
"Access-Control-Allow-Headers": "Test-Request",
5353
"Access-Control-Allow-Credentials": true,
5454
"Content-Type": "image/svg+xml",
5555
},
@@ -80,7 +80,7 @@ describe("API responses", () => {
8080
expect(response).toEqual({
8181
headers: {
8282
"Access-Control-Allow-Origin": "*",
83-
"Access-Control-Allow-Headers": "*",
83+
"Access-Control-Allow-Headers": "Test-Request",
8484
"Access-Control-Allow-Credentials": true,
8585
"Content-Type": "application/json",
8686
},
@@ -96,7 +96,7 @@ describe("API responses", () => {
9696
expect(response).toEqual({
9797
headers: {
9898
"Access-Control-Allow-Origin": "*",
99-
"Access-Control-Allow-Headers": "*",
99+
"Access-Control-Allow-Headers": "Test-Request",
100100
"Access-Control-Allow-Credentials": true,
101101
"Content-Type": "application/json",
102102
Custom: "header",
@@ -111,7 +111,7 @@ describe("API responses", () => {
111111
expect(response).toEqual({
112112
headers: {
113113
"Access-Control-Allow-Origin": "*",
114-
"Access-Control-Allow-Headers": "*",
114+
"Access-Control-Allow-Headers": "Test-Request",
115115
"Access-Control-Allow-Credentials": true,
116116
},
117117
statusCode: 500,
@@ -123,7 +123,7 @@ describe("API responses", () => {
123123
expect(response).toEqual({
124124
headers: {
125125
"Access-Control-Allow-Origin": "*",
126-
"Access-Control-Allow-Headers": "*",
126+
"Access-Control-Allow-Headers": "Test-Request",
127127
"Access-Control-Allow-Credentials": true,
128128
"Content-Type": "application/json",
129129
},
@@ -138,7 +138,7 @@ describe("API responses", () => {
138138
body: JSON.stringify("invalid"),
139139
headers: {
140140
"Access-Control-Allow-Origin": "*",
141-
"Access-Control-Allow-Headers": "*",
141+
"Access-Control-Allow-Headers": "Test-Request",
142142
"Access-Control-Allow-Credentials": true,
143143
"Content-Type": "application/json",
144144
},
@@ -151,7 +151,7 @@ describe("API responses", () => {
151151
expect(response).toEqual({
152152
headers: {
153153
"Access-Control-Allow-Origin": "*",
154-
"Access-Control-Allow-Headers": "*",
154+
"Access-Control-Allow-Headers": "Test-Request",
155155
"Access-Control-Allow-Credentials": true,
156156
},
157157
statusCode: 400,
@@ -163,7 +163,7 @@ describe("API responses", () => {
163163
expect(response).toEqual({
164164
headers: {
165165
"Access-Control-Allow-Origin": "*",
166-
"Access-Control-Allow-Headers": "*",
166+
"Access-Control-Allow-Headers": "Test-Request",
167167
"Access-Control-Allow-Credentials": true,
168168
},
169169
statusCode: 418,
@@ -176,7 +176,7 @@ describe("API responses", () => {
176176
body: JSON.stringify("not found"),
177177
headers: {
178178
"Access-Control-Allow-Origin": "*",
179-
"Access-Control-Allow-Headers": "*",
179+
"Access-Control-Allow-Headers": "Test-Request",
180180
"Access-Control-Allow-Credentials": true,
181181
"Content-Type": "application/json",
182182
},
@@ -189,7 +189,7 @@ describe("API responses", () => {
189189
expect(response).toEqual({
190190
headers: {
191191
"Access-Control-Allow-Origin": "*",
192-
"Access-Control-Allow-Headers": "*",
192+
"Access-Control-Allow-Headers": "Test-Request",
193193
"Access-Control-Allow-Credentials": true,
194194
},
195195
statusCode: 401,
@@ -202,7 +202,7 @@ describe("API responses", () => {
202202
body: JSON.stringify("not found"),
203203
headers: {
204204
"Access-Control-Allow-Origin": "*",
205-
"Access-Control-Allow-Headers": "*",
205+
"Access-Control-Allow-Headers": "Test-Request",
206206
"Access-Control-Allow-Credentials": true,
207207
"Content-Type": "application/json",
208208
},
@@ -215,7 +215,7 @@ describe("API responses", () => {
215215
expect(response).toEqual({
216216
headers: {
217217
"Access-Control-Allow-Origin": "*",
218-
"Access-Control-Allow-Headers": "*",
218+
"Access-Control-Allow-Headers": "Test-Request",
219219
"Access-Control-Allow-Credentials": true,
220220
Location: "url",
221221
},

src/api/shared/responses.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Metrics, logger } from "../../common";
33
const CORS_HEADERS = {
44
"Access-Control-Allow-Origin": "*",
55
"Access-Control-Allow-Credentials": true,
6-
"Access-Control-Allow-Headers": "*",
6+
"Access-Control-Allow-Headers": "Test-Request",
77
};
88

99
const metrics = new Metrics("API Gateway");

src/api/v2-http/parser.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { parse } from 'querystring';
2-
import { HttpApiEvent } from './payload';
3-
import { Metrics, logger } from '../../common';
1+
import { parse } from "querystring";
2+
import { HttpApiEvent } from "./payload";
3+
import { Metrics, logger } from "../../common";
44

5-
const metrics = new Metrics('API Gateway');
5+
const metrics = new Metrics("API Gateway");
66

77
export class Request {
88
constructor(private event: HttpApiEvent) {}
@@ -25,7 +25,7 @@ export class Request {
2525
const auth = this.getAuth();
2626
const headers = event.headers || undefined;
2727
const body = new Body(event.body, headers).getParsedBody();
28-
const TEST_REQUEST_HEADER = process.env.TEST_REQUEST_HEADER || 'Test-Request';
28+
const TEST_REQUEST_HEADER = process.env.TEST_REQUEST_HEADER || "Test-Request";
2929
const testRequest = headers && headers[TEST_REQUEST_HEADER] ? JSON.parse(headers[TEST_REQUEST_HEADER]) : false;
3030
const parsed = { body, path, rawPath, query, rawQueryString, auth, headers, testRequest };
3131
metrics.common(parsed, event);
@@ -51,11 +51,11 @@ export class Body {
5151
} else if (this.isJSON(contentType)) {
5252
parsedBody = JSON.parse(this.body);
5353
} else {
54-
logger.error('Content-Type header not found, attempting to parse as JSON');
54+
logger.error("Content-Type header not found, attempting to parse as JSON");
5555
parsedBody = JSON.parse(this.body);
5656
}
5757
} catch (err) {
58-
logger.error('Error parsing body, returning as-is', err, this.body);
58+
logger.error("Error parsing body, returning as-is", err, this.body);
5959
parsedBody = this.body;
6060
}
6161
}
@@ -64,15 +64,15 @@ export class Body {
6464

6565
private getContentType(): string {
6666
return (
67-
this.headers && (this.headers['Content-Type'] || this.headers['CONTENT-TYPE'] || this.headers['content-type'])
67+
this.headers && (this.headers["Content-Type"] || this.headers["CONTENT-TYPE"] || this.headers["content-type"])
6868
);
6969
}
7070

7171
private isFormUrlEncoded(contentType?: string): boolean {
72-
return contentType?.toUpperCase().includes('APPLICATION/X-WWW-FORM-URLENCODED');
72+
return contentType?.toUpperCase().includes("APPLICATION/X-WWW-FORM-URLENCODED");
7373
}
7474

7575
private isJSON(contentType: string): boolean {
76-
return contentType?.toUpperCase().includes('APPLICATION/JSON');
76+
return contentType?.toUpperCase().includes("APPLICATION/JSON");
7777
}
7878
}

0 commit comments

Comments
 (0)