Permalink
Browse files

Move request generation to separate function.

  • Loading branch information...
1 parent 2d6fa82 commit 4282ae6e132e9a5c1c09e67055a9be729c912d84 @archaelus archaelus committed Jun 8, 2012
Showing with 13 additions and 7 deletions.
  1. +13 −7 src/cowboy_client.erl
View
@@ -32,6 +32,7 @@
-export([stream_header/1]).
-export([stream_body/1]).
+-export([request_to_iolist/6]).
-record(client, {
state = wait :: wait | request | response | response_body,
opts = [] :: [any()],
@@ -99,18 +100,23 @@ request(Method, URL, Headers, Body, Client=#client{
wait -> connect(Transport, Host, Port, Client);
request -> {ok, Client}
end,
+ Data = request_to_iolist(Method, Headers, Body, Version, FullHost,
+ Path),
+ raw_request(Data, Client2).
+
+request_to_iolist(Method, Headers, Body, Version, FullHost, Path) ->
VersionBin = cowboy_http:version_to_binary(Version),
%% @todo do keepalive too, allow override...
Headers2 = [{<<"host">>, FullHost} | Headers],
Headers3 = case iolist_size(Body) of
- 0 -> Headers2;
- Length -> [{<<"content-length">>, integer_to_list(Length)}|Headers2]
- end,
+ 0 -> Headers2;
+ Length -> [{<<"content-length">>, integer_to_list(Length)}
+ | Headers2]
+ end,
HeadersData = [[Name, <<": ">>, Value, <<"\r\n">>]
- || {Name, Value} <- Headers3],
- Data = [Method, <<" ">>, Path, <<" ">>, VersionBin, <<"\r\n">>,
- HeadersData, <<"\r\n">>, Body],
- raw_request(Data, Client2).
+ || {Name, Value} <- Headers3],
+ [Method, <<" ">>, Path, <<" ">>, VersionBin, <<"\r\n">>,
+ HeadersData, <<"\r\n">>, Body].
parse_url(<< "https://", Rest/binary >>) ->
parse_url(Rest, cowboy_ssl_transport);

0 comments on commit 4282ae6

Please sign in to comment.