Skip to content

Commit 593fe6b

Browse files
committed
Ensure :headers is according to Ring spec
Fixes the issue #3
1 parent bd9c493 commit 593fe6b

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/fierycod/holy_lambda_ring_adapter/core.cljc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,12 @@
3333
[{:keys [event ctx]}]
3434
(let [request-ctx (get event :requestContext)
3535
http (get request-ctx :http)
36-
headers (get event :headers)
36+
headers (persistent! (reduce (fn [acc [k v]]
37+
(if (keyword? k)
38+
(assoc! acc (.toLowerCase (name k)) v)
39+
(assoc! acc k v)))
40+
(transient {})
41+
(get event :headers)))
3742
base64? (get event :isBase64Encoded)]
3843
(when-not request-ctx
3944
(throw (ex-info "Incorrect shape of AWS event. The adapter is compatible with following integrations: HttpApi and RestApi on AWS Api Gateway service. If you're testing locally make sure the event shape is valid e.g. use `sam local start-api` instead of `sam local invoke`." {:ctx :hl-ring-adapter})))

test/fierycod/holy_lambda_ring_adapter/core_test.clj

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,22 @@
202202
:body "hello world HTTP/1.1",
203203
:isBase64Encoded false,
204204
:headers {"something" "something"}}
205-
((hra/ring<->hl-middleware basic-ring-handler-async) request2 identity identity))))))
205+
((hra/ring<->hl-middleware basic-ring-handler-async) request2 identity identity)))))
206+
207+
(t/testing "Ensure :headers is a map of downcase strings as keys"
208+
(t/is (= {"content-type" "application/json"}
209+
(:headers (request->ring-request-test {:event {:path "/foo"
210+
:isBase64Encoded false
211+
:headers {:Content-Type "application/json"}
212+
:requestContext {:httpMethod "GET"}}
213+
:ctx nil}#_{:uri "/foo"
214+
:request-method :get
215+
:server-port 80
216+
:server-name "127.0.0.1"
217+
:remote-addr "127.0.0.1"
218+
:scheme "http"
219+
:protocol "HTTP/1.1"
220+
:headers {:Content-Type "application/json"}}))))))
206221

207222
(t/deftest http-api-json-coerce-1
208223
(t/testing "json coercion should work"

0 commit comments

Comments
 (0)