0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-14 20:30:23 +00:00

Optimize Connection header parsing

Still optimizing the critical path.

Removes cowboy_http:connection_to_atom/1.
This commit is contained in:
Loïc Hoguin 2012-09-27 01:31:19 +02:00
parent 681a216a24
commit cd7f37d346
2 changed files with 88 additions and 37 deletions

View file

@ -42,7 +42,6 @@
-export([ce_identity/1]).
%% Interpretation.
-export([connection_to_atom/1]).
-export([version_to_binary/1]).
-export([urldecode/1]).
-export([urldecode/2]).
@ -773,20 +772,6 @@ ce_identity(Data) ->
%% Interpretation.
%% @doc Walk through a tokens list and return whether
%% the connection is keepalive or closed.
%%
%% The connection token is expected to be lower-case.
-spec connection_to_atom([binary()]) -> keepalive | close.
connection_to_atom([]) ->
keepalive;
connection_to_atom([<<"keep-alive">>|_Tail]) ->
keepalive;
connection_to_atom([<<"close">>|_Tail]) ->
close;
connection_to_atom([_Any|Tail]) ->
connection_to_atom(Tail).
%% @doc Convert an HTTP version tuple to its binary form.
-spec version_to_binary(version()) -> binary().
version_to_binary({1, 1}) -> <<"HTTP/1.1">>;
@ -1030,16 +1015,6 @@ asctime_date_test_() ->
],
[{V, fun() -> R = asctime_date(V) end} || {V, R} <- Tests].
connection_to_atom_test_() ->
%% {Tokens, Result}
Tests = [
{[<<"close">>], close},
{[<<"keep-alive">>], keepalive},
{[<<"keep-alive">>, <<"upgrade">>], keepalive}
],
[{lists:flatten(io_lib:format("~p", [T])),
fun() -> R = connection_to_atom(T) end} || {T, R} <- Tests].
content_type_test_() ->
%% {ContentType, Result}
Tests = [