Skip to content

Commit

Permalink
Allow empty output from header command (#308)
Browse files Browse the repository at this point in the history
  • Loading branch information
davo-canva authored Jun 25, 2024
1 parent 4c1cbd3 commit 6363dd4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/headers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ it("should return no headers", async () => {
await expect(getHeaders("", "command", logger)).resolves.toStrictEqual({})
await expect(getHeaders("localhost", " ", logger)).resolves.toStrictEqual({})
await expect(getHeaders(" ", "command", logger)).resolves.toStrictEqual({})
await expect(getHeaders("localhost", "printf ''", logger)).resolves.toStrictEqual({})
})

it("should return headers", async () => {
Expand All @@ -43,7 +44,6 @@ it("should error on malformed or empty lines", async () => {
await expect(getHeaders("localhost", "printf ' =foo'", logger)).rejects.toMatch(/Malformed/)
await expect(getHeaders("localhost", "printf 'foo =bar'", logger)).rejects.toMatch(/Malformed/)
await expect(getHeaders("localhost", "printf 'foo foo=bar'", logger)).rejects.toMatch(/Malformed/)
await expect(getHeaders("localhost", "printf ''", logger)).rejects.toMatch(/Malformed/)
})

it("should have access to environment variables", async () => {
Expand Down
4 changes: 4 additions & 0 deletions src/headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ export async function getHeaders(
}
throw new Error(`Header command exited unexpectedly: ${error}`)
}
if (!result.stdout) {
// Allow no output for parity with the Coder CLI.
return headers
}
const lines = result.stdout.replace(/\r?\n$/, "").split(/\r?\n/)
for (let i = 0; i < lines.length; ++i) {
const [key, value] = lines[i].split(/=(.*)/)
Expand Down

0 comments on commit 6363dd4

Please sign in to comment.