aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cowboy_http_protocol.erl40
1 files changed, 38 insertions, 2 deletions
diff --git a/src/cowboy_http_protocol.erl b/src/cowboy_http_protocol.erl
index 55ecd34..6242fdd 100644
--- a/src/cowboy_http_protocol.erl
+++ b/src/cowboy_http_protocol.erl
@@ -97,7 +97,7 @@ wait_header(Req, State=#state{socket=Socket,
Value::string()} | http_eoh, Req::#http_req{}, State::#state{}) -> ok.
header({http_header, _I, 'Host', _R, RawHost}, Req=#http_req{path=Path,
host=undefined}, State=#state{dispatch=Dispatch}) ->
- RawHost2 = string:to_lower(RawHost),
+ RawHost2 = string_to_lower(RawHost),
Host = cowboy_dispatcher:split_host(RawHost2),
%% @todo We probably want to filter the Host and Path here to allow
%% things like url rewriting.
@@ -220,7 +220,43 @@ connection_to_atom("keep-alive") ->
connection_to_atom("close") ->
close;
connection_to_atom(Connection) ->
- case string:to_lower(Connection) of
+ case string_to_lower(Connection) of
"close" -> close;
_Any -> keepalive
end.
+
+%% More efficient implementation of string:to_lower.
+%% We are excluding a few characters on purpose.
+-spec string_to_lower(string()) -> string().
+string_to_lower(L) ->
+ [char_to_lower(C) || C <- L].
+
+%% We gain noticeable speed by matching each value directly.
+-spec char_to_lower(char()) -> char().
+char_to_lower($A) -> $a;
+char_to_lower($B) -> $b;
+char_to_lower($C) -> $c;
+char_to_lower($D) -> $d;
+char_to_lower($E) -> $e;
+char_to_lower($F) -> $f;
+char_to_lower($G) -> $g;
+char_to_lower($H) -> $h;
+char_to_lower($I) -> $i;
+char_to_lower($J) -> $j;
+char_to_lower($K) -> $k;
+char_to_lower($L) -> $l;
+char_to_lower($M) -> $m;
+char_to_lower($N) -> $n;
+char_to_lower($O) -> $o;
+char_to_lower($P) -> $p;
+char_to_lower($Q) -> $q;
+char_to_lower($R) -> $r;
+char_to_lower($S) -> $s;
+char_to_lower($T) -> $t;
+char_to_lower($U) -> $u;
+char_to_lower($V) -> $v;
+char_to_lower($W) -> $w;
+char_to_lower($X) -> $x;
+char_to_lower($Y) -> $y;
+char_to_lower($Z) -> $z;
+char_to_lower(Ch) -> Ch.