Commits

Anonymous committed 3cc3d1a Merge

Merged in fix for #9 to default branch

  • Participants
  • Parent commits d7d1032, a8ed785

Comments (0)

Files changed (2)

src/lhttpc_client.erl

     PartialDownloadOptions = proplists:get_value(partial_download, Options, []),
     NormalizedMethod = lhttpc_lib:normalize_method(Method),
     {ChunkedUpload, Request} = lhttpc_lib:format_request(Path, NormalizedMethod,
-        Hdrs, Host, Body, PartialUpload),
+        Hdrs, Host, Port, Body, PartialUpload),
     SocketRequest = {socket, self(), Host, Port, Ssl},
     Socket = case gen_server:call(lhttpc_manager, SocketRequest, infinity) of
         {ok, S}   -> S; % Re-using HTTP/1.1 connections

src/lhttpc_lib.erl

 
 -export([
         parse_url/1,
-        format_request/6,
+        format_request/7,
         header_value/2,
         header_value/3,
         normalize_method/1
 split_port(Scheme, [P | T], Port) ->
     split_port(Scheme, T, [P | Port]).
 
-%% @spec (Path, Method, Headers, Host, Body, PartialUpload) -> Request
+%% @spec (Path, Method, Headers, Host, Port, Body, PartialUpload) -> Request
 %% Path = iolist()
 %% Method = atom() | string()
 %% Headers = [{atom() | string(), string()}]
 %% Host = string()
+%% Port = integer()
 %% Body = iolist()
 %% PartialUpload = true | false
 -spec format_request(iolist(), atom() | string(), headers(), string(),
-    iolist(), true | false ) -> {true | false, iolist()}.
-format_request(Path, Method, Hdrs, Host, Body, PartialUpload) ->
-    AllHdrs = add_mandatory_hdrs(Method, Hdrs, Host, Body, PartialUpload),
+    integer(), iolist(), true | false ) -> {true | false, iolist()}.
+format_request(Path, Method, Hdrs, Host, Port, Body, PartialUpload) ->
+    AllHdrs = add_mandatory_hdrs(Method, Hdrs, Host, Port, Body, PartialUpload),
     IsChunked = is_chunked(AllHdrs),
     {
         IsChunked,
             ]
     end.
 
-add_mandatory_hdrs(Method, Hdrs, Host, Body, PartialUpload) ->
-    add_host(add_content_headers(Method, Hdrs, Body, PartialUpload), Host).
+add_mandatory_hdrs(Method, Hdrs, Host, Port, Body, PartialUpload) ->
+    NewHdrs = add_content_headers(Method, Hdrs, Body, PartialUpload),
+    add_host(NewHdrs, Host, Port).
 
 add_content_headers("POST", Hdrs, Body, PartialUpload) ->
     add_content_headers(Hdrs, Body, PartialUpload);
             erlang:error({error, bad_header})
     end.
 
-
-
-add_host(Hdrs, Host) ->
+add_host(Hdrs, Host, Port) ->
     case header_value("host", Hdrs) of
         undefined ->
-            [{"Host", Host } | Hdrs];
+            [{"Host", host(Host, Port) } | Hdrs];
         _ -> % We have a host
             Hdrs
     end.
 dec(Num) when is_integer(Num) -> Num - 1;
 dec(Else)                     -> Else.
 
+host(Host, 80)   -> Host;
+host(Host, Port) -> [Host, $:, integer_to_list(Port)].