Skip to content
This repository has been archived by the owner on Jan 31, 2024. It is now read-only.

Commit

Permalink
Added Tamas Host header fix.
Browse files Browse the repository at this point in the history
--HG--
branch : 1.2
  • Loading branch information
oscarh committed Dec 18, 2009
1 parent 7cd2a42 commit f8299f8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/lhttpc_client.erl
Expand Up @@ -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
Expand Down
22 changes: 13 additions & 9 deletions src/lhttpc_lib.erl
Expand Up @@ -33,7 +33,7 @@

-export([
parse_url/1,
format_request/5,
format_request/6,
header_value/2,
header_value/3,
normalize_method/1
Expand Down Expand Up @@ -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
].

Expand All @@ -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);
Expand All @@ -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)].

0 comments on commit f8299f8

Please sign in to comment.