Skip to content

Commit

Permalink
fix: correctly support multiValueHeaders in rust functions during dev…
Browse files Browse the repository at this point in the history
…elopment (#4632)

`multiValueHeaders` was simply not forwarded from the response of the rust function

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
danez and kodiakhq[bot] authored May 29, 2022
1 parent a8bfc66 commit 4d7a15b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/lib/functions/runtimes/rust/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ const invokeFunction = async ({ context, event, func, timeout }) => {
})

try {
const { body, headers, statusCode } = JSON.parse(stdout)
const { body, headers, multiValueHeaders, statusCode } = JSON.parse(stdout)

return {
body,
headers,
multiValueHeaders,
statusCode,
}
} catch {
Expand Down
29 changes: 29 additions & 0 deletions tests/unit/lib/functions/runtimes/rust/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const test = require('ava')
const sinon = require('sinon')

const { rewiremock } = require('../../../../../integration/utils/rewiremock')

const runFunctionsProxySpy = sinon.stub()
// eslint-disable-next-line n/global-require
const { invokeFunction } = rewiremock.proxy(() => require('../../../../../../src/lib/functions/runtimes/rust/index'), {
'../../../../../../src/lib/functions/local-proxy': {
runFunctionsProxy: runFunctionsProxySpy,
},
})

const invokeFunctionMacro = test.macro({
async exec(t, prop, expected) {
runFunctionsProxySpy.resolves({ stdout: JSON.stringify({ [prop]: expected }) })

const match = await invokeFunction({ func: { mainFile: '', buildData: {} } })
t.deepEqual(match[prop], expected)
},
title(providedTitle, prop) {
return `should return ${prop}`
},
})

test(invokeFunctionMacro, 'body', 'thebody')
test(invokeFunctionMacro, 'headers', { 'X-Single': 'A' })
test(invokeFunctionMacro, 'multiValueHeaders', { 'X-Multi': ['B', 'C'] })
test(invokeFunctionMacro, 'statusCode', 200)

1 comment on commit 4d7a15b

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📊 Benchmark results

Package size: 287 MB

Please sign in to comment.