Skip to content

Commit 1e6f101

Browse files
authored
Jsonata: Fix CloudEvent response handler (#72)
Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
1 parent 98eb037 commit 1e6f101

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

transform-jsonata/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ npm dev-zipkin
3333
Assuming current working directory is `transform-jsonata`
3434

3535
```shell
36-
IMAGE_NAME=...
36+
IMAGE_NAME="${KO_DOCKER_REPO}/transform-jsonata"
3737
docker build -t "${IMAGE_NAME}" -f Dockerfile .
3838
docker push "${IMAGE_NAME}"
3939
```

transform-jsonata/jsonata.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,18 +321,16 @@ app.post("/", async (req, res) => {
321321
try {
322322
const response_headers = {}
323323
response.headers.forEach((value, key) => {
324-
if (key in response_headers) {
325-
response_headers[key].push(value)
326-
return
327-
}
328-
response_headers[key] = [value]
324+
// Technically headers can have multiple values, however the JS SDK doesn't handle that case.
325+
response_headers[key] = value
329326
})
330327
const ce_input = HTTP.toEvent({headers: response_headers, body: response_buf});
331328
input = JSON.parse(HTTP.structured(ce_input).body)
332329
} catch (error) {
333330
const body = response_buf.toString('utf-8')
334331
try {
335332
input = JSON.parse(body)
333+
logDebug(`Response is not a CloudEvent, falling back to raw JSON parsing`, JSON.stringify(input, null, 2), error)
336334
} catch (error) {
337335
input = body
338336
}

0 commit comments

Comments
 (0)