This module provides the API to a HTTP/1.1 client according to RFC 2616, however this early version is somewhat limited for instance caching is not supported.
The functions request/4, and set_options/1, will start the inets application if it was not already started. When starting the inets application the client manager process that spawns request handlers, keeps track of proxy options etc will be started. Normaly the application using this API should have started inets application. This is also true for the ssl application when using https. Also note that an application that does not set the pipeline-timeout value will benefit very little from pipelining as the default timeout is 0. |
There are some usage examples in the Inets User's Guide.
Type definitions that are used more than once in this module:
boolean() = true | false
string() = list of ASCII characters
request_id() = ref()
Type definitions that are related to HTTP:
For more information about HTTP see rfc 2616
method() = head | get | put | post | trace | options | delete
request() - {url(), headers()} | {url(), headers(), content_type(), body()}
url() = string() - Syntax according to the URI definition in rfc 2396, ex: "http://www.erlang.org"
status_line() = {http_version(), status_code(), reason_phrase()}
http_version() = string() ex: "HTTP/1.1"
status_code() = integer()
reason_phrase() = string()
content_type() = string()
headers() = [{field(), value()}]
field() = string()
value() = string()
body() = string() | binary()
Some type definitions relevant when using https, for details ssl(3):
ssl_options() = {verify, code()} | {depth, depth()} | {certfile, path()} | {keyfile, path()} | {password, string()} | {cacertfile, path()} | {ciphers, string()}
cancel_request(RequestId) -> ok
Types:
RequestId = request_id() - A unique identifier as
returned by request/4
Cancels an asynchronous HTTP-request.
request(Url) -> {ok, Result} | {error, Reason}
Types:
Url = url()
Result = {status_line(), headers(), body()} |
{status_code(), body()} | request_id()
Reason = term()
Equivalent to http:request(get, {Url, []}, [], []).
request(Method, Request, HTTPOptions, Options) ->
{ok, Result} | {error, Reason}
Types:
Method = method()
Request - request()
HTTPOptions - [HttpOption]
HTTPOption - {timeout, integer()} | {ssl, ssl_options()}
| {autoredirect, boolean()}
Options - [option()]
Option - {sync, boolean()} | {body_format, body_format()} |
{full_result, boolean()}
body_format() = string() | binary()
Result = {status_line(), headers(), body()} |
{status_code(), body()} | request_id()
Reason = term()
Sends a HTTP-request. The function can be both synchronous and asynchronous in the later case the function will return {ok, RequestId} and later on a message will be sent to the calling process on the format {http, {RequestId, Result}} or {http, {RequestId, {error, Reason}}}.
Types:
Options = [Option]
Option = {proxy, {Proxy, NoProxy}} | {max_sessions, MaxSessions}
| {max_pipeline_length, MaxPipeline} |
{pipeline_timeout, PipelineTimeout} | {cookies | CookieMode}
| {ipv6, Ipv6Mode}
Proxy = {Hostname, Port}
Hostname = string()
Port = integer()
NoProxy = [NoProxyDesc]
NoProxyDesc = DomainDesc | HostName | IPDesc
DomainDesc = "*.Domain"
IpDesc = string()
MaxSessions = integer()
MaxPipeline = integer()
PipelineTimeout = integer()
CookieMode = enabled | disabled | verify
ipv6Mode = enabled | disabled
Sets options to be used for subsequent requests. Later implementations may support user profiles, but currently these are global settings for all clients running on the same erlang node.
If possible the client will keep its connections alive and use them to pipeline requests whenever the circumstances allow. The HTTP/1.1 specification does not provide a guideline for how many requests that would be ideal to pipeline, this very much depends on the application. Note that a very long pipeline may cause a user perceived delays as earlier request may take a long time to complete. The HTTP/1.1 specification does suggest a limit of 2 persistent connections per server, which is the default value of the max_sessions option. |
verify_cookie(SetCookieHeaders, Url) -> ok
Types:
SetCookieHeaders = headers() - where field = "set-cookie"
Url = url()
Saves the cookies defined in SetCookieHeaders in the client manager's cookie database. You need to call this function if you set the option cookies to verify.
cookie_header(Url) -> header()
Types:
Url = url()
Returns the cookie header that would be sent when making a request to Url.
RFC 2616, ssl(3)