Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added Tamas Host header fix.

--HG--
branch : 1.2
  • Loading branch information...
commit f8299f83e82fb7f5fea9b3f310c5749a7cf30880 1 parent 7cd2a42
@oscarh oscarh authored
Showing with 14 additions and 10 deletions.
  1. +1 −1  src/lhttpc_client.erl
  2. +13 −9 src/lhttpc_lib.erl
View
2  src/lhttpc_client.erl
@@ -82,7 +82,7 @@ request(From, Host, Port, Ssl, Path, Method, Hdrs, Body, Options) ->
execute(Host, Port, Ssl, Path, Method, Hdrs, Body, Options) ->
NormalizedMethod = lhttpc_lib:normalize_method(Method),
Request = lhttpc_lib:format_request(Path, NormalizedMethod, Hdrs, Host,
- Body),
+ Port, Body),
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
View
22 src/lhttpc_lib.erl
@@ -33,7 +33,7 @@
-export([
parse_url/1,
- format_request/5,
+ format_request/6,
header_value/2,
header_value/3,
normalize_method/1
@@ -134,18 +134,19 @@ split_port(_,[$/ | _] = Path, Port) ->
split_port(Scheme, [P | T], Port) ->
split_port(Scheme, T, [P | Port]).
-%% @spec (Path, Method, Headers, Host, Body) -> Request
+%% @spec (Path, Method, Headers, Host, Port, Body) -> Request
%% Path = iolist()
%% Method = atom() | string()
%% Headers = [{atom() | string(), string()}]
%% Host = string()
+%% Port = integer()
%% Body = iolist()
-spec format_request(iolist(), atom() | string(), headers(), string(),
- iolist()) -> iolist().
-format_request(Path, Method, Hdrs, Host, Body) ->
+ integer(), iolist()) -> iolist().
+format_request(Path, Method, Hdrs, Host, Port, Body) ->
[
Method, " ", Path, " HTTP/1.1\r\n",
- format_hdrs(add_mandatory_hdrs(Method, Hdrs, Host, Body), []),
+ format_hdrs(add_mandatory_hdrs(Method, Hdrs, Host, Port, Body), []),
Body
].
@@ -170,8 +171,8 @@ format_hdrs([{Hdr, Value} | T], Acc) ->
format_hdrs([], Acc) ->
[Acc, "\r\n"].
-add_mandatory_hdrs(Method, Hdrs, Host, Body) ->
- add_host(add_content_length(Method, Hdrs, Body), Host).
+add_mandatory_hdrs(Method, Hdrs, Host, Port, Body) ->
+ add_host(add_content_length(Method, Hdrs, Body), Host, Port).
add_content_length("POST", Hdrs, Body) ->
add_content_length(Hdrs, Body);
@@ -189,10 +190,13 @@ add_content_length(Hdrs, Body) ->
Hdrs
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.
+
+host(Host, 80) -> Host;
+host(Host, Port) -> [Host, $:, integer_to_list(Port)].
Please sign in to comment.
Something went wrong with that request. Please try again.