aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_client.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2013-05-16 12:56:01 +0200
committerLoïc Hoguin <[email protected]>2013-05-16 12:56:01 +0200
commit28186a68d0c023987fe7334b0326fb6c87f9447c (patch)
tree732b0da9873c061cdda690973150e7ccbce3b99b /src/cowboy_client.erl
parente0b5526f1e6c0794fc76c77f0fc6a4a95696d23f (diff)
downloadcowboy-28186a68d0c023987fe7334b0326fb6c87f9447c.tar.gz
cowboy-28186a68d0c023987fe7334b0326fb6c87f9447c.tar.bz2
cowboy-28186a68d0c023987fe7334b0326fb6c87f9447c.zip
Make the HTTP version type more practical
Now instead of {1, 1} we have 'HTTP/1.1', and instead of {1, 0} we have 'HTTP/1.0'. This is more efficient, easier to read in crash logs, and clearer in the code.
Diffstat (limited to 'src/cowboy_client.erl')
-rw-r--r--src/cowboy_client.erl18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/cowboy_client.erl b/src/cowboy_client.erl
index 4d958b1..faee904 100644
--- a/src/cowboy_client.erl
+++ b/src/cowboy_client.erl
@@ -40,7 +40,7 @@
timeout = 5000 :: timeout(), %% @todo Configurable.
buffer = <<>> :: binary(),
connection = keepalive :: keepalive | close,
- version = {1, 1} :: cowboy_http:version(),
+ version = 'HTTP/1.1' :: cowboy_http:version(),
response_body = undefined :: undefined | non_neg_integer()
}).
@@ -91,7 +91,7 @@ request(Method, URL, Headers, Body, Client=#client{
wait -> connect(Transport, Host, Port, Client);
request -> {ok, Client}
end,
- VersionBin = cowboy_http:version_to_binary(Version),
+ VersionBin = atom_to_binary(Version, latin1),
%% @todo do keepalive too, allow override...
Headers2 = [
{<<"host">>, FullHost},
@@ -173,7 +173,7 @@ stream_status(Client=#client{state=State, buffer=Buffer})
when State =:= request ->
case binary:split(Buffer, <<"\r\n">>) of
[Line, Rest] ->
- parse_status(Client#client{state=response, buffer=Rest}, Line);
+ parse_version(Client#client{state=response, buffer=Rest}, Line);
_ ->
case recv(Client) of
{ok, Data} ->
@@ -184,11 +184,13 @@ stream_status(Client=#client{state=State, buffer=Buffer})
end
end.
-parse_status(Client, << "HTTP/", High, ".", Low, " ",
- S3, S2, S1, " ", StatusStr/binary >>)
- when High >= $0, High =< $9, Low >= $0, Low =< $9,
- S3 >= $0, S3 =< $9, S2 >= $0, S2 =< $9, S1 >= $0, S1 =< $9 ->
- Version = {High - $0, Low - $0},
+parse_version(Client, << "HTTP/1.1 ", Rest/binary >>) ->
+ parse_status(Client, Rest, 'HTTP/1.1');
+parse_version(Client, << "HTTP/1.0 ", Rest/binary >>) ->
+ parse_status(Client, Rest, 'HTTP/1.0').
+
+parse_status(Client, << S3, S2, S1, " ", StatusStr/binary >>, Version)
+ when S3 >= $0, S3 =< $9, S2 >= $0, S2 =< $9, S1 >= $0, S1 =< $9 ->
Status = (S3 - $0) * 100 + (S2 - $0) * 10 + S1 - $0,
{ok, Status, StatusStr, Client#client{version=Version}}.