Skip to content

Commit

Permalink
Merge 0d6b8d8 into 7d44f3a
Browse files Browse the repository at this point in the history
  • Loading branch information
puzza007 committed Sep 7, 2018
2 parents 7d44f3a + 0d6b8d8 commit 41a8eed
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 83 deletions.
37 changes: 19 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,24 +102,25 @@ katipo:Method(Pool :: atom(), URL :: binary(), ReqOptions :: map()).

#### Request options

| Option | Type | Default | Notes |
|:--------------------|:------------------------------|:------------|:------------------------------------------------------------------------------------|
| `headers` | `[{binary(), iodata()}]` | `[]` | |
| `cookiejar` | opaque (returned in response) | `[]` | |
| `body` | `iodata()` | `<<>>` | |
| `connecttimeout_ms` | `pos_integer()` | 30000 | [docs](https://curl.haxx.se/libcurl/c/CURLOPT_CONNECTTIMEOUT.html) |
| `followlocation` | `boolean()` | `false` | [docs](https://curl.haxx.se/libcurl/c/CURLOPT_FOLLOWLOCATION.html) |
| `ssl_verifyhost` | `boolean()` | `true` | [docs](https://curl.haxx.se/libcurl/c/CURLOPT_SSL_VERIFYHOST.html) |
| `ssl_verifypeer` | `boolean()` | `true` | [docs](https://curl.haxx.se/libcurl/c/CURLOPT_SSL_VERIFYPEER.html) |
| `capath` | `binary()` | `undefined` | |
| `cacert` | `binary()` | `undefined` | |
| `timeout_ms` | `pos_integer()` | 30000 | |
| `maxredirs` | `non_neg_integer()` | 9 | |
| `proxy` | `binary()` | `undefined` | [docs](https://curl.haxx.se/libcurl/c/CURLOPT_PROXY.html) |
| `return_metrics` | `boolean()` | `false` | |
| `tcp_fastopen` | `boolean()` | `false` | [docs](https://curl.haxx.se/libcurl/c/CURLOPT_TCP_FASTOPEN.html) curl >= 7.49.0 |
| `interface` | `binary()` | `undefined` | [docs](https://curl.haxx.se/libcurl/c/CURLOPT_INTERFACE.html) |
| `unix_socket_path` | `binary()` | `undefined` | [docs](https://curl.haxx.se/libcurl/c/CURLOPT_UNIX_SOCKET_PATH.html) curl >= 7.40.0 |
| Option | Type | Default | Notes |
|:------------------------|:------------------------------|:------------|:------------------------------------------------------------------------------------|
| `headers` | `[{binary(), iodata()}]` | `[]` | |
| `cookiejar` | opaque (returned in response) | `[]` | |
| `body` | `iodata()` | `<<>>` | |
| `connecttimeout_ms` | `pos_integer()` | 30000 | [docs](https://curl.haxx.se/libcurl/c/CURLOPT_CONNECTTIMEOUT.html) |
| `followlocation` | `boolean()` | `false` | [docs](https://curl.haxx.se/libcurl/c/CURLOPT_FOLLOWLOCATION.html) |
| `ssl_verifyhost` | `boolean()` | `true` | [docs](https://curl.haxx.se/libcurl/c/CURLOPT_SSL_VERIFYHOST.html) |
| `ssl_verifypeer` | `boolean()` | `true` | [docs](https://curl.haxx.se/libcurl/c/CURLOPT_SSL_VERIFYPEER.html) |
| `capath` | `binary()` | `undefined` | |
| `cacert` | `binary()` | `undefined` | |
| `timeout_ms` | `pos_integer()` | 30000 | |
| `maxredirs` | `non_neg_integer()` | 9 | |
| `proxy` | `binary()` | `undefined` | [docs](https://curl.haxx.se/libcurl/c/CURLOPT_PROXY.html) |
| `return_metrics` | `boolean()` | `false` | |
| `tcp_fastopen` | `boolean()` | `false` | [docs](https://curl.haxx.se/libcurl/c/CURLOPT_TCP_FASTOPEN.html) curl >= 7.49.0 |
| `interface` | `binary()` | `undefined` | [docs](https://curl.haxx.se/libcurl/c/CURLOPT_INTERFACE.html) |
| `unix_socket_path` | `binary()` | `undefined` | [docs](https://curl.haxx.se/libcurl/c/CURLOPT_UNIX_SOCKET_PATH.html) curl >= 7.40.0 |
| `lock_data_ssl_session` | `boolean()` | `false` | [docs](https://curl.haxx.se/libcurl/c/curl_share_setopt.html) curl >= 7.23.0 |

#### Responses

Expand Down
17 changes: 17 additions & 0 deletions c_src/katipo.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#define K_CURLOPT_TCP_FASTOPEN 17
#define K_CURLOPT_INTERFACE 18
#define K_CURLOPT_UNIX_SOCKET_PATH 19
#define K_CURLOPT_LOCK_DATA_SSL_SESSION 20

#define K_CURLAUTH_BASIC 100
#define K_CURLAUTH_DIGEST 101
Expand All @@ -49,6 +50,7 @@ typedef struct _GlobalInfo {
struct event_base *evbase;
struct event *timer_event;
CURLM *multi;
CURLSH *shobject;
int still_running;
size_t to_get;
} GlobalInfo;
Expand Down Expand Up @@ -105,6 +107,7 @@ typedef struct _EasyOpts {
long curlopt_tcp_fastopen;
char *curlopt_interface;
char *curlopt_unix_socket_path;
long curlopt_lock_data_ssl_session;
} EasyOpts;

static const char *curl_error_code(CURLcode error) {
Expand Down Expand Up @@ -802,6 +805,9 @@ static void new_conn(long method, char *url, struct curl_slist *req_headers,
curl_easy_setopt(conn->easy, CURLOPT_COOKIELIST, nc->data);
nc = nc->next;
}
if (eopts.curlopt_lock_data_ssl_session) {
curl_easy_setopt(conn->easy, CURLOPT_SHARE, global->shobject);
}

if (eopts.curlopt_capath != NULL) {
free(eopts.curlopt_capath);
Expand Down Expand Up @@ -973,6 +979,7 @@ static void erl_input(struct bufferevent *ev, void *arg) {
eopts.curlopt_tcp_fastopen = 0;
eopts.curlopt_interface = NULL;
eopts.curlopt_unix_socket_path = NULL;
eopts.curlopt_lock_data_ssl_session = 0;

if (ei_decode_list_header(buf, &index, &num_eopts)) {
errx(2, "Couldn't decode eopts length");
Expand Down Expand Up @@ -1023,6 +1030,9 @@ static void erl_input(struct bufferevent *ev, void *arg) {
errx(2, "Unknown curlopt_http_auth value %ld", eopt_long);
}
break;
case K_CURLOPT_LOCK_DATA_SSL_SESSION:
eopts.curlopt_lock_data_ssl_session = eopt_long;
break;
default:
errx(2, "Unknown eopt long value %ld", eopt);
}
Expand Down Expand Up @@ -1125,6 +1135,13 @@ int main(int argc, char **argv) {
if (!global.multi) {
errx(2, "curl_multi_init failed");
}
global.shobject = curl_share_init();
if (!global.shobject) {
errx(2, "curl_share_init failed");
}
if (CURLSHE_OK != curl_share_setopt(global.shobject, CURLSHOPT_SHARE, CURL_LOCK_DATA_SSL_SESSION)) {
errx(2, "curl_share_setopt failed");
}
global.timer_event = evtimer_new(global.evbase, timer_cb, &global);
global.to_get = 0;

Expand Down
17 changes: 14 additions & 3 deletions src/katipo.erl
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
-define(tcp_fastopen, 17).
-define(interface, 18).
-define(unix_socket_path, 19).
-define(lock_data_ssl_session, 20).

-define(DEFAULT_REQ_TIMEOUT, 30000).
-define(FOLLOWLOCATION_TRUE, 1).
Expand All @@ -73,6 +74,8 @@
-define(CURLAUTH_UNDEFINED, 102).
-define(TCP_FASTOPEN_FALSE, 0).
-define(TCP_FASTOPEN_TRUE, 1).
-define(LOCK_DATA_SSL_SESSION_FALSE, 0).
-define(LOCK_DATA_SSL_SESSION_TRUE, 1).

-define(METHODS, [get, post, put, head, options, patch, delete]).

Expand Down Expand Up @@ -259,7 +262,9 @@
return_metrics = false :: boolean(),
tcp_fastopen = ?TCP_FASTOPEN_FALSE :: ?TCP_FASTOPEN_FALSE | ?TCP_FASTOPEN_TRUE,
interface = undefined :: undefined | binary(),
unix_socket_path = undefined :: undefined | binary()
unix_socket_path = undefined :: undefined | binary(),
lock_data_ssl_session = ?LOCK_DATA_SSL_SESSION_FALSE ::
?LOCK_DATA_SSL_SESSION_FALSE | ?LOCK_DATA_SSL_SESSION_TRUE
}).

-ifdef(tcp_fastopen_available).
Expand Down Expand Up @@ -384,7 +389,8 @@ handle_call(#req{method = Method,
proxy = Proxy,
tcp_fastopen = TCPFastOpen,
interface = Interface,
unix_socket_path = UnixSocketPath},
unix_socket_path = UnixSocketPath,
lock_data_ssl_session = LockDataSslSession},
From,
State=#state{port=Port, reqs=Reqs}) ->
{Self, Ref} = From,
Expand All @@ -402,7 +408,8 @@ handle_call(#req{method = Method,
{?proxy, Proxy},
{?tcp_fastopen, TCPFastOpen},
{?interface, Interface},
{?unix_socket_path, UnixSocketPath}],
{?unix_socket_path, UnixSocketPath},
{?lock_data_ssl_session, LockDataSslSession}],
Command = {Self, Ref, Method, Url, Headers, CookieJar, Body, Opts},
true = port_command(Port, term_to_binary(Command)),
Tref = erlang:start_timer(Timeout, self(), {req_timeout, From}),
Expand Down Expand Up @@ -573,6 +580,10 @@ opt(interface, Interface, {Req, Errors}) when is_binary(Interface) ->
opt(unix_socket_path, UnixSocketPath, {Req, Errors})
when is_binary(UnixSocketPath) andalso ?UNIX_SOCKET_PATH_AVAILABLE ->
{Req#req{unix_socket_path=UnixSocketPath}, Errors};
opt(lock_data_ssl_session, true, {Req, Errors}) ->
{Req#req{lock_data_ssl_session=?LOCK_DATA_SSL_SESSION_TRUE}, Errors};
opt(lock_data_ssl_session, false, {Req, Errors}) ->
{Req#req{lock_data_ssl_session=?LOCK_DATA_SSL_SESSION_FALSE}, Errors};
opt(K, V, {Req, Errors}) ->
{Req, [{K, V} | Errors]}.

Expand Down
Loading

0 comments on commit 41a8eed

Please sign in to comment.