diff --git a/doc/lcurl.ldoc b/doc/lcurl.ldoc index 243bb4d..86f5b97 100644 --- a/doc/lcurl.ldoc +++ b/doc/lcurl.ldoc @@ -134,13 +134,28 @@ function easy:close() end --- Set options. -- -- @tparam number opt one of `curl.OPT_XXX` constant --- @params ... value +-- @param ... value +-- @treturn easy self -- -- @usage -- c:setopt(curl.OPT_URL, "http://example.com") --- c:setopt(curl.OPT_READFUNCTION, function(t, n) return table.remove(t) end, {"1111", "2222"}) +-- c:setopt(curl.OPT_READFUNCTION, +-- function(t, n) return table.remove(t) end, +-- {"1111", "2222"} +-- ) function easy:setopt() end +--- Get information. +-- +-- @tparam number info one of `curl.INFO_XXX` constant +-- @return value +-- +-- @usage +-- print(c:getinfo(curl.INFO_EFFECTIVE_URL)) +-- print(c:getinfo(curl.INFO_TOTAL_TIME)) +-- print(c:getinfo(curl.INFO_RESPONSE_CODE)) +function easy:getinfo() end + --- Set writer function. -- -- A callback accepting one or two parameters. diff --git a/src/lceasy.c b/src/lceasy.c index 1e09a65..fb0b40e 100644 --- a/src/lceasy.c +++ b/src/lceasy.c @@ -650,6 +650,20 @@ static int lcurl_easy_setopt(lua_State *L){ return lcurl_fail_ex(L, p->err_mode, LCURL_ERROR_EASY, CURLE_UNKNOWN_OPTION); } +static int lcurl_easy_getinfo(lua_State *L){ + lcurl_easy_t *p = lcurl_geteasy(L); + int opt = luaL_checklong(L, 2); + lua_remove(L, 2); + +#define OPT_ENTRY(l, N, T, S) case CURLINFO_##N: return lcurl_easy_get_##N(L); + switch(opt){ + #include "lcinfoeasy.h" + } +#undef OPT_ENTRY + + return lcurl_fail_ex(L, p->err_mode, LCURL_ERROR_EASY, CURLE_UNKNOWN_OPTION); +} + //} static const struct luaL_Reg lcurl_easy_methods[] = { @@ -669,6 +683,7 @@ static const struct luaL_Reg lcurl_easy_methods[] = { #undef OPT_ENTRY { "setopt", lcurl_easy_setopt }, + { "getinfo", lcurl_easy_getinfo }, { "escape", lcurl_easy_escape }, { "unescape", lcurl_easy_unescape }, { "perform", lcurl_easy_perform },