-
-
Notifications
You must be signed in to change notification settings - Fork 798
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Support ALB Event response headers (#1756)
* fix: Support ALB Event response headers * fix: Run prettier:fix
- Loading branch information
Showing
7 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const { stringify } = JSON | ||
|
||
export async function responseHeader(event, context) { | ||
return { | ||
body: stringify( | ||
{ | ||
context, | ||
event, | ||
}, | ||
null, | ||
2, | ||
), | ||
headers: { | ||
"Content-Type": "text/plain", | ||
"Set-Cookie": "alb-cookie=works", | ||
}, | ||
statusCode: 200, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import assert from "node:assert" | ||
import { join } from "desm" | ||
import { setup, teardown } from "../../_testHelpers/index.js" | ||
import { BASE_URL } from "../../config.js" | ||
|
||
describe("ALB Headers Tests", function desc() { | ||
beforeEach(() => | ||
setup({ | ||
noPrependStageInUrl: false, | ||
servicePath: join(import.meta.url), | ||
}), | ||
) | ||
|
||
afterEach(() => teardown()) | ||
|
||
// | ||
;["GET", "POST"].forEach((method) => { | ||
it(`${method} response headers`, async () => { | ||
const url = new URL("/dev/response-headers", BASE_URL) | ||
url.port = url.port ? "3003" : url.port | ||
const options = { | ||
method, | ||
} | ||
|
||
const response = await fetch(url, options) | ||
|
||
assert.equal(response.status, 200) | ||
|
||
const body = await response.text() | ||
|
||
assert.equal(body, "Plain text") | ||
assert.equal(response.headers.get("Content-Type"), "text/plain") | ||
assert.equal(response.headers.get("Set-Cookie"), "alb-cookie=works") | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
service: alb-headers | ||
|
||
configValidationMode: error | ||
deprecationNotificationMode: error | ||
|
||
plugins: | ||
- ../../../src/index.js | ||
|
||
provider: | ||
architecture: arm64 | ||
deploymentMethod: direct | ||
memorySize: 1024 | ||
name: aws | ||
region: us-east-1 | ||
runtime: nodejs18.x | ||
stage: dev | ||
versionFunctions: false | ||
|
||
functions: | ||
response-headers: | ||
events: | ||
- alb: | ||
conditions: | ||
path: response-headers | ||
listenerArn: arn:aws:elasticloadbalancing:us-east-1:12345:listener/app/my-load-balancer/50dc6c495c0c9188/50dc6c495c0c9188 | ||
priority: 1 | ||
handler: src/handler.responseHeader |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export async function responseHeader() { | ||
return { | ||
body: "Plain text", | ||
headers: { | ||
"Content-Type": "text/plain", | ||
"Set-Cookie": "alb-cookie=works", | ||
}, | ||
statusCode: 200, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"type": "module" | ||
} |