Skip to content

Commit

Permalink
Look for parsed headers in the cache before trying to parse
Browse files Browse the repository at this point in the history
  • Loading branch information
essen committed Jul 22, 2012
1 parent f212caf commit adc3639
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/cowboy_http_req.erl
Expand Up @@ -307,8 +307,15 @@ parse_header(Name, Req, Default) ->
{Value, Req2} = header(Name, Req, Default),
{undefined, Value, Req2}.

%% @todo This doesn't look in the cache.
parse_header(Name, Req=#http_req{p_headers=PHeaders}, Default, Fun) ->
case lists:keyfind(Name, 1, PHeaders) of
{Name, P} ->
{P, Req};
false ->
parse_header_no_cache(Name, Req, Default, Fun)
end.

parse_header_no_cache(Name, Req=#http_req{p_headers=PHeaders}, Default, Fun) ->
case header(Name, Req) of
{undefined, Req2} ->
{Default, Req2#http_req{p_headers=[{Name, Default}|PHeaders]}};
Expand Down

0 comments on commit adc3639

Please sign in to comment.