Skip to content
This repository was archived by the owner on Nov 16, 2020. It is now read-only.

Commit 3513318

Browse files
markpeekberndtj
authored andcommitted
Modify the kong transformer to support application/cloudevents+json (#399)
The current CloudEvents 0.1 HTTP Transport Binding draft uses the RFC 6839 +json structured syntax suffix. This change allows for accepting both application/json and application/cloudevents+json for Content-Type.
1 parent 87e5056 commit 3513318

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

charts/kong/dispatch-transformer/handler.lua

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,24 @@ local function iter(config_array)
2424
end, config_array, 0
2525
end
2626

27+
function string.starts(String, Start)
28+
return string.sub(String, 1, string.len(Start)) == Start
29+
end
30+
31+
function string.ends(String, End)
32+
return End == '' or string.sub(String, -string.len(End)) == End
33+
end
34+
35+
local function is_json_media_type(header)
36+
return string.starts(header, "application/") and string.ends(header, "+json")
37+
end
38+
2739
local function is_json_body(header)
2840
local content_type = header["content-type"]
29-
return content_type and string.find(string.lower(content_type), "application/json", nil, true)
41+
if not content_type then
42+
return false
43+
end
44+
return string.find(string.lower(content_type), "application/json", nil, true) or is_json_media_type(content_type)
3045
end
3146

3247
local function is_form_urlencoded_body(header)

0 commit comments

Comments
 (0)