Copyright © (C) 1999-2013, Erlang Solutions Ltd
Authors: Oscar Hellström (oscar@hellstrom.st), Diana Parra Corbacho (diana.corbacho@erlang-solutions.com), Ramon Lastres Guerrero (ramon.lastres@erlang-solutions.com).
connect/1 | Starts a Client. |
disconnect/1 | Stops a Client. |
handle_call/3 | This function fills in the Client record used in the requests and obtains the socket. |
init/1 | |
request/6 | Makes a request using a client already connected. |
request/7 | Sends a request with a body. |
start/2 | |
start_link/2 |
connect(Client) -> any()
Starts a Client.
disconnect(Client::pid()) -> ok
Stops a Client.
handle_call(X1, From, Client_state) -> any()
This function fills in the Client record used in the requests and obtains the socket.
init(X1) -> any()
request(Client::pid(), Path::iodata(), Method::method(), Hdrs::headers(), Body::iodata(), Timeout::pos_timeout()) -> result()
Makes a request using a client already connected.
request(Client, Path::Host, Method, Hdrs, Body::RequestBody, SendRetry::RetryCount, Timeout) -> Result
Sends a request with a body.
Instead of building and parsing URLs the target server is specified with
a host, port, weither SSL should be used or not and a path on the server.
For instance, if you want to request http://example.com/foobar you would
use the following:
Host
= "example.com"
Port
= 80
Ssl
= false
Path
= "/foobar"
Path
must begin with a forward slash /
.
Method
is either a string, stating the HTTP method exactly as in the
protocol, i.e: "POST"
or "GET"
. It could also be an atom, which is
then coverted to an uppercase (if it isn't already) string.
Hdrs
is a list of headers to send. Mandatory headers such as
Host
, Content-Length
or Transfer-Encoding
(for some requests)
are added automatically.
Body
is the entity to send in the request. Please don't include entity
bodies where there shouldn't be any (such as for GET
).
Timeout
is the timeout for the request in milliseconds.
Options
is a list of options.
Options:
{connect_timeout, Milliseconds}
specifies how many milliseconds the
client can spend trying to establish a connection to the server. This
doesn't affect the overall request timeout. However, if it's longer than
the overall timeout it will be ignored. Also note that the TCP layer my
choose to give up earlier than the connect timeout, in which case the
client will also give up. The default value is infinity, which means that
it will either give up when the TCP stack gives up, or when the overall
request timeout is reached.
{connect_options, Options}
specifies options to pass to the socket at
connect time. This makes it possible to specify both SSL options and
regular socket options, such as which IP/Port to connect from etc.
Some options must not be included here, namely the mode, binary
or list
, {active, boolean()}
, {active, once}
or {packet, Packet}
.
These options would confuse the client if they are included.
Please note that these options will only have an effect on *new*
connections, and it isn't possible for different requests
to the same host uses different options unless the connection is closed
between the requests. Using HTTP/1.0 or including the "Connection: close"
header would make the client close the connection after the first
response is received.
{send_retry, N}
specifies how many times the client should retry
sending a request if the connection is closed after the data has been
sent. The default value is 1
.
{proxy, ProxyUrl}
if this option is specified, a proxy server is used as
an intermediary for all communication with the destination server. The link
to the proxy server is established with the HTTP CONNECT method (RFC2817).
Example value: {proxy, "http://john:doe@myproxy.com:3128"}
{proxy_ssl_options, SslOptions}
this is a list of SSL options to use for
the SSL session created after the proxy connection is established. For a
list of all available options, please check OTP's ssl module manpage.
start(Destination, Options) -> any()
start_link(Destination, Options) -> any()
Generated by EDoc, May 17 2017, 09:28:02.