Skip to content

Commit

Permalink
Merge pull request #136 from puzza007/edoc
Browse files Browse the repository at this point in the history
Edoc and remove session interface
  • Loading branch information
puzza007 authored Apr 6, 2022
2 parents 3aecef5 + 32f7bfa commit 5c9cb31
Show file tree
Hide file tree
Showing 12 changed files with 277 additions and 349 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ jobs:
with:
otp-version: ${{matrix.otp}}
rebar3-version: ${{matrix.rebar3}}
- run: sudo apt update && sudo apt install -y make gcc libevent-dev libcurl4-openssl-dev libssl-dev && rebar3 update && rebar3 ct && rebar3 dialyzer
- run: sudo apt update && sudo apt install -y make gcc libevent-dev libcurl4-openssl-dev libssl-dev && rebar3 update && rebar3 ct && rebar3 dialyzer && rebar3 lint
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ _build
.vagrant/
local/
/rebar3.crashdump
doc
24 changes: 0 additions & 24 deletions Dockerfile.katipo_build

This file was deleted.

62 changes: 12 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,6 @@ Req = #{url => <<"https://example.com">>.
body := RespBody}} = katipo:req(Pool, Req).
```

Session interface. Cookies handled automatically and options merged. Inspired by [Requests sessions](http://docs.python-requests.org/en/latest/user/advanced/#session-objects).

```erlang
{ok, _} = application:ensure_all_started(katipo).
Pool = api_server,
{ok, _} = katipo_pool:start(Pool, 2, [{pipelining, multiplex}]).
ReqHeaders = [{<<"User-Agent">>, <<"katipo">>}].
Opts = #{url => <<"https://example.com">>.
method => post,
headers => ReqHeaders,
connecttimeout_ms => 5000,
proxy => <<"http://127.0.0.1:9000">>,
ssl_verifyhost => false,
ssl_verifypeer => false}.
{ok, Session} = katipo_session:new(Pool, Opts).
{{ok, #{status := 200}}, Session2} =
katipo_session:req(#{body => <<"some data">>}, Session).
{{ok, #{status := 200}}, Session3} =
katipo_session:req(#{body => <<"different payload data">>}, Session2).
```

### Why

We wanted a compatible and high-performance HTTP client so took
Expand Down Expand Up @@ -124,7 +103,7 @@ katipo:Method(Pool :: atom(), URL :: binary(), ReqOptions :: map()).
| `sslkey` | `binary()` | `undefined` | [docs](https://curl.haxx.se/libcurl/c/CURLOPT_SSLKEY.html) |
| `sslkey_blob` | `binary()` (DER format) | `undefined` | [docs](https://curl.haxx.se/libcurl/c/CURLOPT_SSLKEY_BLOB.html) curl >= 7.71.0 |
| `keypasswd` | `binary()` | `undefined` | [docs](https://curl.haxx.se/libcurl/c/CURLOPT_KEYPASSWD.html) |
| `http_auth` | `basic | digest | ntlm | negotiate` | `undefined` | [docs](https://curl.haxx.se/libcurl/c/CURLOPT_HTTPAUTH.html) |
| `http_auth` | `basic` <br> `digest` <br> `ntlm` <br> `negotiate` | `undefined` | [docs](https://curl.haxx.se/libcurl/c/CURLOPT_HTTPAUTH.html) |
| `userpwd` | `binary()` | `undefined` | [docs](https://curl.haxx.se/libcurl/c/CURLOPT_USERPWD.html) |

#### Responses
Expand All @@ -143,7 +122,7 @@ katipo:Method(Pool :: atom(), URL :: binary(), ReqOptions :: map()).

| Option | Type | Default | Note |
|:------------------------|:------------------------------|:-------------|:-----------------------------------------------------------------------------------------------|
| `pipelining` | `nothing | http1 | multiplex` | `nothing` | HTTP pipelining [CURLMOPT_PIPELINING](https://curl.haxx.se/libcurl/c/CURLMOPT_PIPELINING.html) |
| `pipelining` | `nothing` <br> `http1` <br> `multiplex` | `nothing` | HTTP pipelining [CURLMOPT_PIPELINING](https://curl.haxx.se/libcurl/c/CURLMOPT_PIPELINING.html) |
| `max_pipeline_length` | `non_neg_integer()` | 100 | |
| `max_total_connections` | `non_neg_integer()` | 0 (no limit) | [docs](https://curl.haxx.se/libcurl/c/CURLMOPT_MAX_TOTAL_CONNECTIONS.html) |

Expand All @@ -161,37 +140,20 @@ katipo:Method(Pool :: atom(), URL :: binary(), ReqOptions :: map()).
* redirect_time
* starttransfer_time

### Dependencies
### System dependencies

#### Ubuntu Trusty
* libevent-dev
* libcurl4-openssl-dev
* make
* curl
* libssl-dev
* gcc

```sh
sudo apt-get install git libwxgtk2.8-0 libwxbase2.8-0 libevent-dev libcurl4-openssl-dev libcurl4-openssl-dev
## Testing

wget http://packages.erlang-solutions.com/site/esl/esl-erlang/FLAVOUR_1_esl/esl-erlang_18.0-1~ubuntu~trusty_amd64.deb

sudo dpkg -i esl-erlang_18.0-1~ubuntu~trusty_amd64.deb
```
#### Fedora

```sh
sudo dnf install libevent.x86_64 libcurl.x86_64 libevent-devel.x86_64
```

#### OSX

```sh
brew install --with-c-ares --with-nghttp2 curl
brew install libevent
```

### Building

```sh
rebar3 compile
```
The official Erlang Docker [image](https://hub.docker.com/_/erlang)
has everything needed to build and test Katipo

### TODO

* A more structured way to ifdef features based on curl version
* Better session interface
23 changes: 23 additions & 0 deletions elvis.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[{elvis, [
{config, [
#{ dirs => ["src/**"]
, filter => "*.erl"
, ruleset => erl_files
, rules => [{elvis_style, atom_naming_convention, #{ regex => "^([a-z][a-z0-9]*_?)+([a-z0-9_]*)$", enclosed_atoms => ".*"}}
, {elvis_style, god_modules, #{limit => 30}}]
}
, #{ dirs => ["c_src/**"]
, filter => "Makefile"
, ruleset => makefiles
, rules => [] }
, #{ dirs => ["."]
, filter => "rebar.config"
, ruleset => rebar_config
, rules => [] }
, #{ dirs => ["."]
, filter => "elvis.config"
, ruleset => elvis_config
, rules => [] }
]}
, {verbose, true}
]}].
9 changes: 4 additions & 5 deletions rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
[
{test,
[{deps,
[{jsx, "2.9.0"},
{meck, "0.8.10"},
[{jsx, "3.1.0"},
{meck, "0.9.2"},
{cowboy, "2.9.0"},
{ephemeral, "2.0.4"},
{proper, "1.3.0"}
{ephemeral, "2.0.4"}
]}]
}]
}.
Expand All @@ -40,7 +39,7 @@
deprecated_functions]}.

{plugins, [rebar3_hex,
rebar3_proper,
rebar3_lint,
{coveralls, "1.4.0"}]}.
{cover_enabled, true}.
{cover_export_enabled, true}.
Expand Down
3 changes: 1 addition & 2 deletions src/katipo.app.src
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{application, 'katipo',
[{description, "HTTP client based on libcurl"},
{vsn, "1.0.4"},
{vsn, "1.1.0"},
{registered, []},
{mod, {'katipo_app', []}},
{applications,
Expand All @@ -24,6 +24,5 @@
"src/katipo_cow_qs.erl",
"src/katipo_metrics.erl",
"src/katipo_pool.erl",
"src/katipo_session.erl",
"src/katipo_sup.erl"]}
]}.
Loading

0 comments on commit 5c9cb31

Please sign in to comment.