Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump to metrics 2.1.0 #351

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 23 additions & 13 deletions README.md
Expand Up @@ -10,7 +10,7 @@ __Version:__ 1.6.1

**hackney** is an HTTP client library for Erlang.

[![Build Status](https://secure.travis-ci.org/benoitc/hackney.svg?branch=master)](https://travis-ci.org/benoitc/hackney)
[![Build Status](https://travis-ci.org/benoitc/hackney.png?branch=master)](https://travis-ci.org/benoitc/hackney)
[![Hex pm](http://img.shields.io/hexpm/v/hackney.svg?style=flat)](https://hex.pm/packages/hackney)

## Main features:
Expand Down Expand Up @@ -172,6 +172,8 @@ read_body(MaxLength, Ref, Acc) when MaxLength > byte_size(Acc) ->
> Note: you can also fetch a multipart response using the functions
> `hackney:stream_multipart/1` and `hackney:skip_multipart/1`.

> Note 2: using the `with_body` option will return the body directy instead of a reference.

### Reuse a connection

By default all connections are created and closed dynamically by
Expand Down Expand Up @@ -214,15 +216,15 @@ NextReq = {NextMethod, NextPath, ReqHeaders, ReqBody}
Here we are posting a JSON payload to '/' on the friendpaste service to
create a paste. Then we close the client connection.

> If your connection supports keepalive the connection will be simply :
> If your connection supports keepalive the connection will be kept open until you close it exclusively.

### Send a body

hackney helps you send different payloads by passing different terms as
the request body:

- `{form, PropList}` : To send a form
- `{multipart, Parts}` : to send you body using the multipart API. Parts
- `{multipart, Parts}` : to send your body using the multipart API. Parts
follow this format:
- `eof`: end the multipart request
- `{file, Path}`: to stream a file
Expand Down Expand Up @@ -316,7 +318,7 @@ LoopFun(LoopFun, ClientRef).
> synchronously using the function `hackney:stop_async/1` See the
> example [test_async_once2](https://github.com/benoitc/hackney/blob/master/examples/test_async_once2.erl) for the usage.

> **Note 4**: When the option `{following_redirect, true}` is passed to
> **Note 4**: When the option `{follow_redirect, true}` is passed to
> the request, you will receive the folllowing messages on valid
> redirection:
> - `{redirect, To, Headers}`
Expand Down Expand Up @@ -436,15 +438,21 @@ automatically upgrading to an SSL connection if needed.

Hackney offers the following metrics

You can enable metrics collection by adding a `mod_metrics` entry to hackney's
app config. Metrics are disabled by default. The module specified must have an
API matching that of the hackney metrics module.
You can enable metrics collection by adding a `metrics` entry to the config.<pre lang="erlang">
{metrics, [
{mod_metrics, metrics_folsom}
]}</pre>

Metrics are disabled by default. The module specified must have an API
matching that of the hackney metrics module.

To use [folsom](https://github.com/boundary/folsom), specify `{mod_metrics,
folsom}`, or if you want to use
To use [folsom](https://github.com/boundary/folsom), specify `{mod_metrics,
metrics_folsom}`, if you want to use
[exometer](https://github.com/feuerlabs/exometer), specify`{mod_metrics,
exometer}` and ensure that folsom or exometer is in your code path and has
been started.
metrics_exometer}`, or if you want to use
[grapherl](https://github.com/processone/grapherl), specify `{mod_metrics,
metrics_grapherl}` and ensure that folsom, exometer or grapherl is in your
code path and has been started.

#### Generic Hackney metrics

Expand Down Expand Up @@ -508,8 +516,8 @@ $ pip install gunicorn httpbin
Running the tests:

```
$ gunicorn -b 127.0.0.1:8000 -b unix:httpbin.sock --daemon --pid httpbin.pid httpbin:appl
$ make test
$ gunicorn -b 127.0.0.1:8000 -b unix:httpbin.sock --daemon --pid httpbin.pid httpbin:app
$ rebar3 as test eunit
$ kill `cat httpbin.pid`
```

Expand All @@ -527,6 +535,7 @@ $ kill `cat httpbin.pid`
<tr><td><a href="http://github.com/benoitc/hackney/blob/master/doc/hackney_headers.md" class="module">hackney_headers</a></td></tr>
<tr><td><a href="http://github.com/benoitc/hackney/blob/master/doc/hackney_http.md" class="module">hackney_http</a></td></tr>
<tr><td><a href="http://github.com/benoitc/hackney/blob/master/doc/hackney_http_connect.md" class="module">hackney_http_connect</a></td></tr>
<tr><td><a href="http://github.com/benoitc/hackney/blob/master/doc/hackney_local_tcp.md" class="module">hackney_local_tcp</a></td></tr>
<tr><td><a href="http://github.com/benoitc/hackney/blob/master/doc/hackney_manager.md" class="module">hackney_manager</a></td></tr>
<tr><td><a href="http://github.com/benoitc/hackney/blob/master/doc/hackney_multipart.md" class="module">hackney_multipart</a></td></tr>
<tr><td><a href="http://github.com/benoitc/hackney/blob/master/doc/hackney_pool.md" class="module">hackney_pool</a></td></tr>
Expand All @@ -541,3 +550,4 @@ $ kill `cat httpbin.pid`
<tr><td><a href="http://github.com/benoitc/hackney/blob/master/doc/hackney_trace.md" class="module">hackney_trace</a></td></tr>
<tr><td><a href="http://github.com/benoitc/hackney/blob/master/doc/hackney_url.md" class="module">hackney_url</a></td></tr>
<tr><td><a href="http://github.com/benoitc/hackney/blob/master/doc/hackney_util.md" class="module">hackney_util</a></td></tr></table>

33 changes: 21 additions & 12 deletions doc/README.md
Expand Up @@ -172,6 +172,8 @@ read_body(MaxLength, Ref, Acc) when MaxLength > byte_size(Acc) ->
> Note: you can also fetch a multipart response using the functions
> `hackney:stream_multipart/1` and `hackney:skip_multipart/1`.

> Note 2: using the `with_body` option will return the body directy instead of a reference.

### Reuse a connection

By default all connections are created and closed dynamically by
Expand Down Expand Up @@ -214,15 +216,15 @@ NextReq = {NextMethod, NextPath, ReqHeaders, ReqBody}
Here we are posting a JSON payload to '/' on the friendpaste service to
create a paste. Then we close the client connection.

> If your connection supports keepalive the connection will be simply :
> If your connection supports keepalive the connection will be kept open until you close it exclusively.

### Send a body

hackney helps you send different payloads by passing different terms as
the request body:

- `{form, PropList}` : To send a form
- `{multipart, Parts}` : to send you body using the multipart API. Parts
- `{multipart, Parts}` : to send your body using the multipart API. Parts
follow this format:
- `eof`: end the multipart request
- `{file, Path}`: to stream a file
Expand Down Expand Up @@ -316,7 +318,7 @@ LoopFun(LoopFun, ClientRef).
> synchronously using the function `hackney:stop_async/1` See the
> example [test_async_once2](https://github.com/benoitc/hackney/blob/master/examples/test_async_once2.erl) for the usage.

> **Note 4**: When the option `{following_redirect, true}` is passed to
> **Note 4**: When the option `{follow_redirect, true}` is passed to
> the request, you will receive the folllowing messages on valid
> redirection:
> - `{redirect, To, Headers}`
Expand Down Expand Up @@ -436,15 +438,21 @@ automatically upgrading to an SSL connection if needed.

Hackney offers the following metrics

You can enable metrics collection by adding a `mod_metrics` entry to hackney's
app config. Metrics are disabled by default. The module specified must have an
API matching that of the hackney metrics module.
You can enable metrics collection by adding a `metrics` entry to the config.<pre lang="erlang">
{metrics, [
{mod_metrics, metrics_folsom}
]}</pre>

Metrics are disabled by default. The module specified must have an API
matching that of the hackney metrics module.

To use [folsom](https://github.com/boundary/folsom), specify `{mod_metrics,
folsom}`, or if you want to use
To use [folsom](https://github.com/boundary/folsom), specify `{mod_metrics,
metrics_folsom}`, if you want to use
[exometer](https://github.com/feuerlabs/exometer), specify`{mod_metrics,
exometer}` and ensure that folsom or exometer is in your code path and has
been started.
metrics_exometer}`, or if you want to use
[grapherl](https://github.com/processone/grapherl), specify `{mod_metrics,
metrics_grapherl}` and ensure that folsom, exometer or grapherl is in your
code path and has been started.

#### Generic Hackney metrics

Expand Down Expand Up @@ -508,8 +516,8 @@ $ pip install gunicorn httpbin
Running the tests:

```
$ gunicorn --daemon --pid httpbin.pid httpbin:app
$ make test
$ gunicorn -b 127.0.0.1:8000 -b unix:httpbin.sock --daemon --pid httpbin.pid httpbin:app
$ rebar3 as test eunit
$ kill `cat httpbin.pid`
```

Expand All @@ -527,6 +535,7 @@ $ kill `cat httpbin.pid`
<tr><td><a href="hackney_headers.md" class="module">hackney_headers</a></td></tr>
<tr><td><a href="hackney_http.md" class="module">hackney_http</a></td></tr>
<tr><td><a href="hackney_http_connect.md" class="module">hackney_http_connect</a></td></tr>
<tr><td><a href="hackney_local_tcp.md" class="module">hackney_local_tcp</a></td></tr>
<tr><td><a href="hackney_manager.md" class="module">hackney_manager</a></td></tr>
<tr><td><a href="hackney_multipart.md" class="module">hackney_multipart</a></td></tr>
<tr><td><a href="hackney_pool.md" class="module">hackney_pool</a></td></tr>
Expand Down
8 changes: 4 additions & 4 deletions doc/edoc-info
Expand Up @@ -2,7 +2,7 @@
{application,hackney}.
{modules,[hackney,hackney_app,hackney_bstr,hackney_connect,hackney_cookie,
hackney_date,hackney_headers,hackney_http,hackney_http_connect,
hackney_manager,hackney_multipart,hackney_pool,hackney_pool_handler,
hackney_request,hackney_response,hackney_socks5,
hackney_ssl,hackney_stream,hackney_sup,
hackney_tcp,hackney_trace,hackney_url,hackney_util]}.
hackney_local_tcp,hackney_manager,hackney_multipart,hackney_pool,
hackney_pool_handler,hackney_request,hackney_response,
hackney_socks5,hackney_ssl,hackney_stream,hackney_sup,hackney_tcp,
hackney_trace,hackney_url,hackney_util]}.
4 changes: 2 additions & 2 deletions doc/hackney.md
Expand Up @@ -83,7 +83,7 @@ options to it.</td></tr><tr><td valign="top"><a href="#setopts-2">setopts/2</a><
### body/1 ###

<pre><code>
body(Ref::<a href="#type-client_ref">client_ref()</a>) -&gt; {ok, binary()} | {error, atom()}
body(Ref::<a href="#type-client_ref">client_ref()</a>) -&gt; {ok, binary()} | {error, atom()} | {error, {closed, binary()}}
</code></pre>
<br />

Expand All @@ -94,7 +94,7 @@ Return the full body sent with the response.
### body/2 ###

<pre><code>
body(Ref::<a href="#type-client_ref">client_ref()</a>, MaxLength::non_neg_integer() | infinity) -&gt; {ok, binary()} | {error, atom()}
body(Ref::<a href="#type-client_ref">client_ref()</a>, MaxLength::non_neg_integer() | infinity) -&gt; {ok, binary()} | {error, atom()} | {error, {closed, binary()}}
</code></pre>
<br />

Expand Down
8 changes: 7 additions & 1 deletion doc/hackney_connect.md
Expand Up @@ -9,7 +9,7 @@
## Function Index ##


<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#check_or_close-1">check_or_close/1</a></td><td></td></tr><tr><td valign="top"><a href="#close-1">close/1</a></td><td>close the client.</td></tr><tr><td valign="top"><a href="#connect-3">connect/3</a></td><td></td></tr><tr><td valign="top"><a href="#connect-4">connect/4</a></td><td></td></tr><tr><td valign="top"><a href="#connect-5">connect/5</a></td><td></td></tr><tr><td valign="top"><a href="#create_connection-4">create_connection/4</a></td><td>create a connection and return a client state.</td></tr><tr><td valign="top"><a href="#create_connection-5">create_connection/5</a></td><td></td></tr><tr><td valign="top"><a href="#is_pool-1">is_pool/1</a></td><td>get current pool pid or name used by a client if needed.</td></tr><tr><td valign="top"><a href="#maybe_connect-1">maybe_connect/1</a></td><td>connect a socket and create a client state.</td></tr><tr><td valign="top"><a href="#reconnect-4">reconnect/4</a></td><td></td></tr><tr><td valign="top"><a href="#set_sockopts-2">set_sockopts/2</a></td><td>add set sockets options in the client.</td></tr><tr><td valign="top"><a href="#ssl_opts-2">ssl_opts/2</a></td><td></td></tr></table>
<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#check_or_close-1">check_or_close/1</a></td><td></td></tr><tr><td valign="top"><a href="#close-1">close/1</a></td><td>close the client.</td></tr><tr><td valign="top"><a href="#connect-3">connect/3</a></td><td></td></tr><tr><td valign="top"><a href="#connect-4">connect/4</a></td><td></td></tr><tr><td valign="top"><a href="#connect-5">connect/5</a></td><td></td></tr><tr><td valign="top"><a href="#create_connection-4">create_connection/4</a></td><td>create a connection and return a client state.</td></tr><tr><td valign="top"><a href="#create_connection-5">create_connection/5</a></td><td></td></tr><tr><td valign="top"><a href="#is_pool-1">is_pool/1</a></td><td>get current pool pid or name used by a client if needed.</td></tr><tr><td valign="top"><a href="#maybe_connect-1">maybe_connect/1</a></td><td>connect a socket and create a client state.</td></tr><tr><td valign="top"><a href="#partial_chain-1">partial_chain/1</a></td><td></td></tr><tr><td valign="top"><a href="#reconnect-4">reconnect/4</a></td><td></td></tr><tr><td valign="top"><a href="#set_sockopts-2">set_sockopts/2</a></td><td>add set sockets options in the client.</td></tr><tr><td valign="top"><a href="#ssl_opts-2">ssl_opts/2</a></td><td></td></tr></table>


<a name="functions"></a>
Expand Down Expand Up @@ -78,6 +78,12 @@ get current pool pid or name used by a client if needed

connect a socket and create a client state.

<a name="partial_chain-1"></a>

### partial_chain/1 ###

`partial_chain(Certs) -> any()`

<a name="reconnect-4"></a>

### reconnect/4 ###
Expand Down
148 changes: 148 additions & 0 deletions doc/hackney_local_tcp.md
@@ -0,0 +1,148 @@


# Module hackney_local_tcp #
* [Function Index](#index)
* [Function Details](#functions)

<a name="index"></a>

## Function Index ##


<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#close-1">close/1</a></td><td>Close a TCP socket.</td></tr><tr><td valign="top"><a href="#connect-3">connect/3</a></td><td></td></tr><tr><td valign="top"><a href="#connect-4">connect/4</a></td><td></td></tr><tr><td valign="top"><a href="#controlling_process-2">controlling_process/2</a></td><td>Assign a new controlling process <em>Pid</em> to <em>Socket</em>.</td></tr><tr><td valign="top"><a href="#messages-1">messages/1</a></td><td>Atoms used to identify messages in {active, once | true} mode.</td></tr><tr><td valign="top"><a href="#peername-1">peername/1</a></td><td>Return the address and port for the other end of a connection.</td></tr><tr><td valign="top"><a href="#recv-2">recv/2</a></td><td></td></tr><tr><td valign="top"><a href="#recv-3">recv/3</a></td><td>Receive a packet from a socket in passive mode.</td></tr><tr><td valign="top"><a href="#send-2">send/2</a></td><td>Send a packet on a socket.</td></tr><tr><td valign="top"><a href="#setopts-2">setopts/2</a></td><td>Set one or more options for a socket.</td></tr><tr><td valign="top"><a href="#shutdown-2">shutdown/2</a></td><td>Immediately close a socket in one or two directions.</td></tr><tr><td valign="top"><a href="#sockname-1">sockname/1</a></td><td>Get the local address and port of a socket.</td></tr></table>


<a name="functions"></a>

## Function Details ##

<a name="close-1"></a>

### close/1 ###

<pre><code>
close(Socket::<a href="inet.md#type-socket">inet:socket()</a>) -&gt; ok
</code></pre>
<br />

Close a TCP socket.

__See also:__ [gen_tcp:close/1](gen_tcp.md#close-1).

<a name="connect-3"></a>

### connect/3 ###

`connect(Host, Port, Opts) -> any()`

<a name="connect-4"></a>

### connect/4 ###

`connect(Host, Port, Opts, Timeout) -> any()`

<a name="controlling_process-2"></a>

### controlling_process/2 ###

<pre><code>
controlling_process(Socket::<a href="inet.md#type-socket">inet:socket()</a>, Pid::pid()) -&gt; ok | {error, closed | not_owner | atom()}
</code></pre>
<br />

Assign a new controlling process _Pid_ to _Socket_.

__See also:__ [gen_tcp:controlling_process/2](gen_tcp.md#controlling_process-2).

<a name="messages-1"></a>

### messages/1 ###

`messages(X1) -> any()`

Atoms used to identify messages in {active, once | true} mode.

<a name="peername-1"></a>

### peername/1 ###

<pre><code>
peername(Socket::<a href="inet.md#type-socket">inet:socket()</a>) -&gt; {ok, {<a href="inet.md#type-ip_address">inet:ip_address()</a>, <a href="inet.md#type-port_number">inet:port_number()</a>}} | {error, atom()}
</code></pre>
<br />

Return the address and port for the other end of a connection.

__See also:__ [inet:peername/1](inet.md#peername-1).

<a name="recv-2"></a>

### recv/2 ###

`recv(Socket, Length) -> any()`

<a name="recv-3"></a>

### recv/3 ###

<pre><code>
recv(Socket::<a href="inet.md#type-socket">inet:socket()</a>, Length::non_neg_integer(), Timeout::timeout()) -&gt; {ok, any()} | {error, closed | atom()}
</code></pre>
<br />

Receive a packet from a socket in passive mode.

__See also:__ [gen_tcp:recv/3](gen_tcp.md#recv-3).

<a name="send-2"></a>

### send/2 ###

<pre><code>
send(Socket::<a href="inet.md#type-socket">inet:socket()</a>, Packet::iolist()) -&gt; ok | {error, atom()}
</code></pre>
<br />

Send a packet on a socket.

__See also:__ [gen_tcp:send/2](gen_tcp.md#send-2).

<a name="setopts-2"></a>

### setopts/2 ###

<pre><code>
setopts(Socket::<a href="inet.md#type-socket">inet:socket()</a>, Opts::list()) -&gt; ok | {error, atom()}
</code></pre>
<br />

Set one or more options for a socket.

__See also:__ [inet:setopts/2](inet.md#setopts-2).

<a name="shutdown-2"></a>

### shutdown/2 ###

<pre><code>
shutdown(Socket::<a href="inet.md#type-socket">inet:socket()</a>, How::read | write | read_write) -&gt; ok
</code></pre>
<br />

Immediately close a socket in one or two directions.

__See also:__ [gen_tcp:shutdown/2](gen_tcp.md#shutdown-2).

<a name="sockname-1"></a>

### sockname/1 ###

<pre><code>
sockname(Socket::<a href="inet.md#type-socket">inet:socket()</a>) -&gt; {ok, {<a href="inet.md#type-ip_address">inet:ip_address()</a>, <a href="inet.md#type-port_number">inet:port_number()</a>}} | {error, atom()}
</code></pre>
<br />

Get the local address and port of a socket

__See also:__ [inet:sockname/1](inet.md#sockname-1).