From ae2daff04fdf7aca199e799c4f3024519e7d53f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Dimitrov?= Date: Tue, 20 Feb 2018 15:24:46 +0100 Subject: inets: Add unix domain socket support to httpc Change-Id: I44fe2670e36884e09600d17dd71b1e86b9ee75fa --- lib/inets/doc/src/http_client.xml | 15 ++++++++++----- lib/inets/doc/src/httpc.xml | 18 +++++++++++++----- 2 files changed, 23 insertions(+), 10 deletions(-) (limited to 'lib/inets/doc') diff --git a/lib/inets/doc/src/http_client.xml b/lib/inets/doc/src/http_client.xml index 212958f17f..15e383ec77 100644 --- a/lib/inets/doc/src/http_client.xml +++ b/lib/inets/doc/src/http_client.xml @@ -97,27 +97,32 @@ 7 > {ok, {{NewVersion, 200, NewReasonPhrase}, NewHeaders, NewBody}} = httpc:request(get, {"http://www.erlang.org", [{"connection", "close"}]}, [], []). - +

This sends an HTTP request over a unix domain socket (experimental):

+ + 8 > httpc:set_options([{ipfamily, local}, + {unix_socket,"/tmp/unix_socket/consul_http.sock"}]). + 9 > {ok, {{NewVersion, 200, NewReasonPhrase}, NewHeaders, NewBody}} = + httpc:request(put, {"http:///v1/kv/foo", [], [], "hello"}, [], []).

Start an HTTP client profile:

{ok, Pid} = inets:start(httpc, [{profile, foo}]). + 10 > {ok, Pid} = inets:start(httpc, [{profile, foo}]). {ok, <0.45.0>} ]]>

The new profile has no proxy settings, so the connection is refused:

- 9 > httpc:request("http://www.erlang.org", foo). + 11 > httpc:request("http://www.erlang.org", foo). {error, econnrefused}

Stop the HTTP client profile:

- 10 > inets:stop(httpc, foo). + 12 > inets:stop(httpc, foo). ok

Alternative way to stop the HTTP client profile:

- 10 > inets:stop(httpc, Pid). + 13 > inets:stop(httpc, Pid). ok diff --git a/lib/inets/doc/src/httpc.xml b/lib/inets/doc/src/httpc.xml index 29e4b22632..befcd83827 100644 --- a/lib/inets/doc/src/httpc.xml +++ b/lib/inets/doc/src/httpc.xml @@ -210,7 +210,8 @@ ip | port | socket_opts | - verbose + verbose | + unix_socket Profile = profile() | pid() When started stand_alone only the pid can used. Values = [{option_item(), term()}] @@ -298,8 +299,8 @@ {full_result, boolean()} | {headers_as_is, boolean() | {socket_opts, socket_opts()} | - {receiver, receiver()}, - {ipv6_host_with_brackets, boolean()}} + {receiver, receiver()} | + {ipv6_host_with_brackets, boolean()} stream_to() = none | self | {self, once} | filename() socket_opts() = [socket_opt()] receiver() = pid() | function()/1 | {Module, Function, Args} @@ -541,7 +542,8 @@ | {ip, IpAddress} | {port, Port} | {socket_opts, socket_opts()} - | {verbose, VerboseMode} + | {verbose, VerboseMode} + | {unix_socket, UnixSocket} Proxy = {Hostname, Port} Hostname = string() Example: "localhost" or "foo.bar.se" @@ -584,7 +586,7 @@ If option verify is used, function store_cookies/2 has to be called for the cookies to be saved. Default is disabled. - IpFamily = inet | inet6 + IpFamily = inet | inet6 | local Default is inet. IpAddress = ip_address() If the host has several network interfaces, this option specifies @@ -609,6 +611,12 @@ It is a debug feature. Profile = profile() | pid() When started stand_alone only the pid can be used. + UnixSocket = path() + + Experimental option for sending HTTP requests over a unix domain socket. The value + of unix_socket shall be the full path to a unix domain socket file with read/write + permissions for the erlang process. Default is undefined. +

Sets options to be used for subsequent requests.

-- cgit v1.2.3