Browse Source

Added host_header option

pull/16/head
chandrusf 18 years ago
parent
commit
9d7a637066
5 changed files with 44 additions and 12 deletions
  1. +4
    -1
      README
  2. +13
    -2
      doc/ibrowse.html
  3. +15
    -2
      src/ibrowse.erl
  4. +11
    -6
      src/ibrowse_http_client.erl
  5. +1
    -1
      vsn.mk

+ 4
- 1
README View File

@ -1,4 +1,4 @@
$Id: README,v 1.9 2007/04/20 00:36:29 chandrusf Exp $
$Id: README,v 1.10 2007/06/28 22:29:00 chandrusf Exp $
ibrowse is a HTTP client. The following are a list of features. ibrowse is a HTTP client. The following are a list of features.
- RFC2616 compliant (AFAIK) - RFC2616 compliant (AFAIK)
@ -22,6 +22,9 @@ Comments to : Chandrashekhar.Mullaparthi@t-mobile.co.uk
CONTRIBUTIONS & CHANGE HISTORY CONTRIBUTIONS & CHANGE HISTORY
============================== ==============================
28-06-2007 - Added host_header option to enable connection to secure sites
via stunnel
20-04-2007 - Geoff Cant sent a patch to remove URL encoding for digits in 20-04-2007 - Geoff Cant sent a patch to remove URL encoding for digits in
ibrowse_lib:url_encode/1. ibrowse_lib:url_encode/1.
ibrowse had a dependency on the inets application because the ibrowse had a dependency on the inets application because the

+ 13
- 2
doc/ibrowse.html View File

@ -8,8 +8,11 @@
<h1>Module ibrowse</h1> <h1>Module ibrowse</h1>
The ibrowse application implements an HTTP 1.1 client. The ibrowse application implements an HTTP 1.1 client.
<p>Copyright © 2005-2007 Chandrashekhar Mullaparthi</p>
<ul><li><a href="#description">Description</a></li><li><a href="#index">Function Index</a></li><li><a href="#functions">Function Details</a></li></ul> <ul><li><a href="#description">Description</a></li><li><a href="#index">Function Index</a></li><li><a href="#functions">Function Details</a></li></ul>
<p><b>Version:</b> 1.2.7</p>
<p><b>Behaviours:</b> <a href="gen_server.html"><tt>gen_server</tt></a>.</p> <p><b>Behaviours:</b> <a href="gen_server.html"><tt>gen_server</tt></a>.</p>
<p><b>Authors:</b> Chandrashekhar Mullaparthi (<a href="mailto:chandrashekhar dot mullaparthi at gmail dot com"><tt>chandrashekhar dot mullaparthi at gmail dot com</tt></a>).</p>
<h2><a name="description">Description</a></h2><p>The ibrowse application implements an HTTP 1.1 client. This <h2><a name="description">Description</a></h2><p>The ibrowse application implements an HTTP 1.1 client. This
module implements the API of the HTTP client. There is one named module implements the API of the HTTP client. There is one named
@ -136,10 +139,18 @@ send_req/4, send_req/5, send_req/6.

<h3><a name="send_req-5">send_req/5</a></h3> <h3><a name="send_req-5">send_req/5</a></h3>
<p><tt>send_req(Url::string(), Headers::<a href="#type-headerList">headerList()</a>, Method::<a href="#type-method">method()</a>, Body::<a href="#type-body">body()</a>, Options::<a href="#type-optionList">optionList()</a>) -&gt; <a href="#type-response">response()</a></tt> <p><tt>send_req(Url::string(), Headers::<a href="#type-headerList">headerList()</a>, Method::<a href="#type-method">method()</a>, Body::<a href="#type-body">body()</a>, Options::<a href="#type-optionList">optionList()</a>) -&gt; <a href="#type-response">response()</a></tt>
<ul><li><tt><a name="type-optionList">optionList()</a> = [<a href="#type-option">option()</a>]</tt></li><li><tt><a name="type-option">option()</a> = {max_sessions, integer()} | {max_pipeline_size, integer()} | {trace, <a href="#type-boolean">boolean()</a>} | {is_ssl, <a href="#type-boolean">boolean()</a>} | {ssl_options, [SSLOpt]} | {pool_name, atom()} | {proxy_host, string()} | {proxy_port, integer()} | {proxy_user, string()} | {proxy_password, string()} | {use_absolute_uri, <a href="#type-boolean">boolean()</a>} | {basic_auth, {<a href="#type-username">username()</a>, <a href="#type-password">password()</a>}} | {cookie, string()} | {content_length, integer()} | {content_type, string()} | {save_response_to_file, <a href="#type-boolean">boolean()</a>} | {stream_to, <a href="#type-process">process()</a>} | {http_vsn, {MajorVsn, MinorVsn}} | {transfer_encoding, {chunked, ChunkSize}}</tt></li><li><tt><a name="type-process">process()</a> = pid() | atom()</tt></li><li><tt><a name="type-username">username()</a> = string()</tt></li><li><tt><a name="type-password">password()</a> = string()</tt></li><li><tt>SSLOpt = term()</tt></li><li><tt>ChunkSize = integer()</tt></li></ul></p>
<ul><li><tt><a name="type-optionList">optionList()</a> = [<a href="#type-option">option()</a>]</tt></li><li><tt><a name="type-option">option()</a> = {max_sessions, integer()} | {max_pipeline_size, integer()} | {trace, <a href="#type-boolean">boolean()</a>} | {is_ssl, <a href="#type-boolean">boolean()</a>} | {ssl_options, [SSLOpt]} | {pool_name, atom()} | {proxy_host, string()} | {proxy_port, integer()} | {proxy_user, string()} | {proxy_password, string()} | {use_absolute_uri, <a href="#type-boolean">boolean()</a>} | {basic_auth, {<a href="#type-username">username()</a>, <a href="#type-password">password()</a>}} | {cookie, string()} | {content_length, integer()} | {content_type, string()} | {save_response_to_file, <a href="#type-boolean">boolean()</a>} | {stream_to, <a href="#type-process">process()</a>} | {http_vsn, {MajorVsn, MinorVsn}} | {host_header, string()} | {transfer_encoding, {chunked, ChunkSize}}</tt></li><li><tt><a name="type-process">process()</a> = pid() | atom()</tt></li><li><tt><a name="type-username">username()</a> = string()</tt></li><li><tt><a name="type-password">password()</a> = string()</tt></li><li><tt>SSLOpt = term()</tt></li><li><tt>ChunkSize = integer()</tt></li></ul></p>
<p>Same as send_req/4. <p>Same as send_req/4.
For a description of SSL Options, look in the ssl manpage. If the For a description of SSL Options, look in the ssl manpage. If the
HTTP Version to use is not specified, the default is 1.1</p>
HTTP Version to use is not specified, the default is 1.1.
<br>
<p>The <code>host_header</code> is useful in the case where ibrowse is
connecting to a component such as <a href="http://www.stunnel.org">stunnel</a> which then sets up a
secure connection to a webserver. In this case, the URL supplied to
ibrowse must have the stunnel host/port details, but that won't
make sense to the destination webserver. This option can then be
used to specify what should go in the <code>Host</code> header in
the request.</p></p>
<h3><a name="send_req-6">send_req/6</a></h3> <h3><a name="send_req-6">send_req/6</a></h3>
<p><tt>send_req(Url, Headers::<a href="#type-headerList">headerList()</a>, Method::<a href="#type-method">method()</a>, Body::<a href="#type-body">body()</a>, Options::<a href="#type-optionList">optionList()</a>, Timeout) -&gt; <a href="#type-response">response()</a></tt> <p><tt>send_req(Url, Headers::<a href="#type-headerList">headerList()</a>, Method::<a href="#type-method">method()</a>, Body::<a href="#type-body">body()</a>, Options::<a href="#type-optionList">optionList()</a>, Timeout) -&gt; <a href="#type-response">response()</a></tt>

+ 15
- 2
src/ibrowse.erl View File

@ -5,6 +5,9 @@
%%% %%%
%%% Created : 11 Oct 2003 by Chandrashekhar Mullaparthi <chandrashekhar.mullaparthi@t-mobile.co.uk> %%% Created : 11 Oct 2003 by Chandrashekhar Mullaparthi <chandrashekhar.mullaparthi@t-mobile.co.uk>
%%%------------------------------------------------------------------- %%%-------------------------------------------------------------------
%% @author Chandrashekhar Mullaparthi <chandrashekhar dot mullaparthi at gmail dot com>
%% @copyright 2005-2007 Chandrashekhar Mullaparthi
%% @version 1.2.7
%% @doc The ibrowse application implements an HTTP 1.1 client. This %% @doc The ibrowse application implements an HTTP 1.1 client. This
%% module implements the API of the HTTP client. There is one named %% module implements the API of the HTTP client. There is one named
%% process called 'ibrowse' which acts as a load balancer. There is %% process called 'ibrowse' which acts as a load balancer. There is
@ -58,7 +61,7 @@
%% driver isn't actually used.</p> %% driver isn't actually used.</p>
-module(ibrowse). -module(ibrowse).
-vsn('$Id: ibrowse.erl,v 1.3 2007/03/21 00:26:41 chandrusf Exp $ ').
-vsn('$Id: ibrowse.erl,v 1.4 2007/06/28 22:29:01 chandrusf Exp $ ').
-behaviour(gen_server). -behaviour(gen_server).
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
@ -178,7 +181,16 @@ send_req(Url, Headers, Method, Body) ->
%% @doc Same as send_req/4. %% @doc Same as send_req/4.
%% For a description of SSL Options, look in the ssl manpage. If the %% For a description of SSL Options, look in the ssl manpage. If the
%% HTTP Version to use is not specified, the default is 1.1
%% HTTP Version to use is not specified, the default is 1.1.
%% <br/>
%% <p>The <code>host_header</code> is useful in the case where ibrowse is
%% connecting to a component such as <a
%% href="http://www.stunnel.org">stunnel</a> which then sets up a
%% secure connection to a webserver. In this case, the URL supplied to
%% ibrowse must have the stunnel host/port details, but that won't
%% make sense to the destination webserver. This option can then be
%% used to specify what should go in the <code>Host</code> header in
%% the request.</p>
%% @spec send_req(Url::string(), Headers::headerList(), Method::method(), Body::body(), Options::optionList()) -> response() %% @spec send_req(Url::string(), Headers::headerList(), Method::method(), Body::body(), Options::optionList()) -> response()
%% optionList() = [option()] %% optionList() = [option()]
%% option() = {max_sessions, integer()} | %% option() = {max_sessions, integer()} |
@ -199,6 +211,7 @@ send_req(Url, Headers, Method, Body) ->
%% {save_response_to_file, boolean()} | %% {save_response_to_file, boolean()} |
%% {stream_to, process()} | %% {stream_to, process()} |
%% {http_vsn, {MajorVsn, MinorVsn}} | %% {http_vsn, {MajorVsn, MinorVsn}} |
%% {host_header, string()} |
%% {transfer_encoding, {chunked, ChunkSize}} %% {transfer_encoding, {chunked, ChunkSize}}
%% %%
%% process() = pid() | atom() %% process() = pid() | atom()

+ 11
- 6
src/ibrowse_http_client.erl View File

@ -6,7 +6,7 @@
%%% Created : 11 Oct 2003 by Chandrashekhar Mullaparthi <chandrashekhar.mullaparthi@t-mobile.co.uk> %%% Created : 11 Oct 2003 by Chandrashekhar Mullaparthi <chandrashekhar.mullaparthi@t-mobile.co.uk>
%%%------------------------------------------------------------------- %%%-------------------------------------------------------------------
-module(ibrowse_http_client). -module(ibrowse_http_client).
-vsn('$Id: ibrowse_http_client.erl,v 1.11 2007/04/20 00:36:30 chandrusf Exp $ ').
-vsn('$Id: ibrowse_http_client.erl,v 1.12 2007/06/28 22:29:01 chandrusf Exp $ ').
-behaviour(gen_server). -behaviour(gen_server).
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
@ -459,12 +459,17 @@ send_req_1(Url, Headers, Method, Body, Options, Sock, State) ->
port = Port, port = Port,
path = RelPath} = Url_1 = parse_url(Url), path = RelPath} = Url_1 = parse_url(Url),
Headers_1 = add_auth_headers(Url_1, Options, Headers, State), Headers_1 = add_auth_headers(Url_1, Options, Headers, State),
HostString = case Port of
80 -> Host;
_ -> [Host, ":", integer_to_list(Port)]
end,
HostHeaderValue = case lists:keysearch(host_header, 1, Options) of
false ->
case Port of
80 -> Host;
_ -> [Host, ":", integer_to_list(Port)]
end;
{value, {_, Host_h_val}} ->
Host_h_val
end,
Req = make_request(Method, Req = make_request(Method,
[{"Host", HostString} | Headers_1],
[{"Host", HostHeaderValue} | Headers_1],
AbsPath, RelPath, Body, Options, State#state.use_proxy), AbsPath, RelPath, Body, Options, State#state.use_proxy),
case get(my_trace_flag) of %%Avoid the binary operations if trace is not on... case get(my_trace_flag) of %%Avoid the binary operations if trace is not on...
true -> true ->

+ 1
- 1
vsn.mk View File

@ -1,2 +1,2 @@
IBROWSE_VSN = 1.2.6
IBROWSE_VSN = 1.2.7

Loading…
Cancel
Save