From 2da7106ebb5ad90ff3694c88213b8bc9073c5280 Mon Sep 17 00:00:00 2001 From: Alexey Melnichuk Date: Wed, 3 Sep 2014 11:33:00 +0500 Subject: [PATCH] Change. Unset httppost options with stream also unset readfunction. --- src/lceasy.c | 17 +++++++++++++---- src/lcutils.c | 6 ++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/lceasy.c b/src/lceasy.c index fcb298a..d6bf9e6 100644 --- a/src/lceasy.c +++ b/src/lceasy.c @@ -393,10 +393,19 @@ static int lcurl_easy_unset_HTTPPOST(lua_State *L){ return lcurl_fail_ex(L, p->err_mode, LCURL_ERROR_EASY, code); } - lcurl_storage_remove_i(L, p->storage, CURLOPT_HTTPPOST); - - //! @fixme unset readdata/readfunction for - // curl_easy_setopt(p->curl, CURLOPT_READFUNCTION, 0); + lcurl_storage_get_i(L, p->storage, CURLOPT_HTTPPOST); + if(!lua_isnil(L, -1)){ + lcurl_hpost_t *form = lcurl_gethpost_at(L, -1); + if(form->stream){ + /* with stream we do not set CURLOPT_READDATA but + we also unset it to be sure that there no way to + call default curl reader with our READDATA + */ + curl_easy_setopt(p->curl, CURLOPT_READFUNCTION, 0); + curl_easy_setopt(p->curl, CURLOPT_READDATA, 0); + } + lcurl_storage_remove_i(L, p->storage, CURLOPT_HTTPPOST); + } lua_settop(L, 1); return 1; diff --git a/src/lcutils.c b/src/lcutils.c index aea6519..8b3ef54 100644 --- a/src/lcutils.c +++ b/src/lcutils.c @@ -62,12 +62,10 @@ void lcurl_storage_get_i(lua_State *L, int storage, int i){ lua_rawgeti(L, LCURL_LUA_REGISTRY, storage); lua_rawgeti(L, -1, LCURL_STORAGE_KV); if(lua_istable(L, -1)){ - lua_rawgeti(L, -2, i); - lua_remove(L, -2); + lua_rawgeti(L, -1, i); lua_remove(L, -2); } - else - lua_pop(L, 2); + lua_remove(L, -2); } struct curl_slist* lcurl_storage_remove_slist(lua_State *L, int storage, int idx){