From 9ddbd04045a833262ff850d63a4e6d6632caea43 Mon Sep 17 00:00:00 2001 From: ILYA Khlopotov Date: Mon, 29 Jun 2015 05:45:37 -0700 Subject: [PATCH] Account for binary keys for headers in CORS We do have headers' keys represented as either lists or binaries. Make sure we don't crash on `string:to_lower`. COUCHDB-2733 --- src/chttpd_cors.erl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/chttpd_cors.erl b/src/chttpd_cors.erl index b109b45..cedb86e 100644 --- a/src/chttpd_cors.erl +++ b/src/chttpd_cors.erl @@ -217,9 +217,13 @@ maybe_apply_headers(CorsHeaders, RequestHeaders) -> simple_headers(Headers) -> - LCHeaders = [string:to_lower(H) || H <- Headers], + LCHeaders = [to_lower(H) || H <- Headers], lists:filter(fun(H) -> lists:member(H, ?SIMPLE_HEADERS) end, LCHeaders). +to_lower(String) when is_binary(String) -> + to_lower(?b2l(String)); +to_lower(String) -> + string:to_lower(String). handle_headers(_Config, _Origin, []) -> [];