aboutsummaryrefslogtreecommitdiffstats
path: root/lib/inets/src/http_lib/http_response.erl
diff options
context:
space:
mode:
authorHenrik Nord <[email protected]>2015-10-27 12:55:25 +0100
committerHenrik Nord <[email protected]>2015-10-27 12:55:25 +0100
commit1d6f49bfc5222217579540bd13c47a02e61896a9 (patch)
tree235b7e58fdfe6e99886c6367a5a23d7495aca0ec /lib/inets/src/http_lib/http_response.erl
parent4b5853e7865d6a1baab39d7345b1b8d0280a4291 (diff)
parent7dc9eefa341fbfae0ebc55a88b96a375c611e3a4 (diff)
downloadotp-1d6f49bfc5222217579540bd13c47a02e61896a9.tar.gz
otp-1d6f49bfc5222217579540bd13c47a02e61896a9.tar.bz2
otp-1d6f49bfc5222217579540bd13c47a02e61896a9.zip
Merge branch 'maint'
Diffstat (limited to 'lib/inets/src/http_lib/http_response.erl')
-rw-r--r--lib/inets/src/http_lib/http_response.erl30
1 files changed, 21 insertions, 9 deletions
diff --git a/lib/inets/src/http_lib/http_response.erl b/lib/inets/src/http_lib/http_response.erl
index 58b30c4e9e..d13670700c 100644
--- a/lib/inets/src/http_lib/http_response.erl
+++ b/lib/inets/src/http_lib/http_response.erl
@@ -31,16 +31,11 @@
%% Value - string()
%%
%% Description: Creates a http_response_h-record used internally to
-%% handle http-headers.
+%% handle http-headers, assumes reversed list of headers
+%% to unfold multiline headers with obs-folds
%%-------------------------------------------------------------------------
-headers([], Headers) ->
- Headers;
-
-headers([Header | Tail], Headers) ->
- {Key, [$: | Value]} =
- lists:splitwith(fun($:) -> false; (_) -> true end, Header),
- headers(Tail, headers(http_util:to_lower(string:strip(Key)),
- string:strip(Value), Headers)).
+headers(RevLines, Headers) ->
+ fill_headers(RevLines, [], Headers).
%%-------------------------------------------------------------------------
%% headers(#http_response_h{}) -> HeaderList
@@ -68,6 +63,23 @@ header_list(Headers) ->
%%%========================================================================
%%% Internal functions
%%%========================================================================
+fill_headers([], _, Headers) ->
+ Headers;
+fill_headers([[Ch|HeaderFold]|Tail], Folded, Headers)
+ when Ch == $\t; Ch == $\s ->
+ fill_headers(Tail, [HeaderFold|Folded], Headers);
+fill_headers([Header | Tail], Folded, Headers) ->
+ Unfolded = unfold([Header|Folded]),
+ {Key, [$: | Value]} =
+ lists:splitwith(fun($:) -> false; (_) -> true end, Unfolded),
+ fill_headers(Tail, [], headers(http_util:to_lower(string:strip(Key)),
+ string:strip(Value), Headers)).
+
+unfold([L]) ->
+ L;
+unfold(Folded) ->
+ string:join(Folded, " ").
+
headers("cache-control", Value, Headers) ->
Headers#http_response_h{'cache-control'= Value};
headers("connection", Value, Headers) ->