Skip to content
This repository was archived by the owner on Feb 11, 2022. It is now read-only.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,17 @@ successfully executed an instruction that brought data from the Internet.

## API reference

The `curl` package contains one component, `http()`, which contains following
functions:
The `curl` package contains one component, `http()`, which has three options:

* `max_conn` - number (default 10000)
* `pipeline` - 0 or 1 (default 0)
* `pool_size`- number (default 5)

This component contains following functions:

* `VERSION` -- a version as string

* `request(method, url [, options])` -- Asynchronous data transfer
* `request(method, url [, options])` -- Synchronous data transfer
request. See details below.

* `get(url [, options])` -- This is the same as `request('GET',
Expand Down Expand Up @@ -142,8 +147,8 @@ functions:
http_other_responses -- this is a total number of requests which have requests not a HTTP 200

failed_requests -- this is a total number of requests which have
-- failed (included systeme erros, curl errors, HTTP
-- erros and so on)
-- failed (included system erros, curl errors,
-- but not HTTP errors)
}
```

Expand Down
26 changes: 21 additions & 5 deletions curl/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,21 +265,37 @@ async_request(lua_State *L)

/* Method {{{ */

if (*method == 'G') {
curl_easy_setopt(r->easy, CURLOPT_HTTPGET, 1);
if (strncmp(method, "GET", 3) == 0) {
curl_easy_setopt(r->easy, CURLOPT_HTTPGET, 1L);
}
else if (strcmp(method, "POST") == 0) {
else if (strncmp(method, "HEAD", 4) == 0){
curl_easy_setopt(r->easy, CURLOPT_NOBODY, 1L);
}
else if (strncmp(method, "POST", 4) == 0) {
if (!request_set_post(r)) {
reason = "can't allocate memory (request_set_post)";
goto error_exit;
}
}
else if (strcmp(method, "PUT") == 0) {
else if (strncmp(method, "PUT", 3) == 0) {
if (!request_set_put(r)) {
reason = "can't allocate memory (request_set_put)";
goto error_exit;
}
} else {
}
else if (strncmp(method, "OPTIONS", 7) == 0){
curl_easy_setopt(r->easy, CURLOPT_CUSTOMREQUEST, "OPTIONS");
}
else if (strncmp(method, "DELETE", 6) == 0){
curl_easy_setopt(r->easy, CURLOPT_CUSTOMREQUEST, "DELETE");
}
else if (strncmp(method, "TRACE", 5) == 0){
curl_easy_setopt(r->easy, CURLOPT_CUSTOMREQUEST, "TRACE");
}
else if (strncmp(method, "CONNECT", 6) == 0){
curl_easy_setopt(r->easy, CURLOPT_CUSTOMREQUEST, "CONNECT");
}
else {
reason = "method does not supported";
goto error_exit;
}
Expand Down
66 changes: 66 additions & 0 deletions curl/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,38 @@ curl_mt = {
end,

--
-- <http_options> see <sync_request>
--
http_options = function(self, url, options)
return self:request('OPTIONS', url, '', options)
end,

--
-- <head> see <sync_request>
--
head = function(self, url, options)
return self:request('HEAD', url, '', options)
end,
--
-- <delete> see <sync_request>
--
delete = function(self, url, options)
return self:request('DELETE', url, '', options)
end,

--
-- <trace> see <sync_request>
--
trace = function(self, url, options)
return self:request('TRACE', url, '', options)
end,

--
-- <http_connect> see <sync_request>
--
http_connect = function(self, url, options)
return self:request('CONNECT', url, '', options)
end,
-- <async_request> This function does HTTP request
--
-- Parameters:
Expand Down Expand Up @@ -302,6 +334,40 @@ curl_mt = {
return self:async_request('PUT', url, options)
end,

--
-- <async_http_options> see <async_request>
--
async_http_options = function(self, url, options)
return self:async_request('OPTIONS', url, options)
end,

--
-- <async_head> see <async_request>
--
async_head = function(self, url, options)
return self:async_request('HEAD', url, options)
end,
--
-- <async_delete> see <async_request>
--
async_delete = function(self, url, options)
return self:async_request('DELETE', url, options)
end,

--
-- <async_trace> see <async_request>
--
async_trace = function(self, url, options)
return self:async_request('TRACE', url, options)
end,

--
-- <async_http_connect> see <async_request>
--
async_http_connect = function(self, url, options)
return self:async_request('CONNECT', url, options)
end,

--
-- <stat> - this function returns a table with many values of statistic.
--
Expand Down
Loading