aboutsummaryrefslogtreecommitdiffstats
path: root/src/cowboy_client.erl
diff options
context:
space:
mode:
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}}.