mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-neutrino.git
synced 2025-08-27 07:22:57 +02:00
lua_curl: add option to modify header; example: httpheaders={'Accept:application/json', 'authorization:Bearer ' .. token}
Origin commit data
------------------
Commit: 6a4956a0c6
Author: Jacek Jendrzej <overx300@gmail.com>
Date: 2021-04-05 (Mon, 05 Apr 2021)
This commit is contained in:
@@ -4,4 +4,4 @@
|
||||
* to luainstance.h changes
|
||||
*/
|
||||
#define LUA_API_VERSION_MAJOR 1
|
||||
#define LUA_API_VERSION_MINOR 89
|
||||
#define LUA_API_VERSION_MINOR 90
|
||||
|
@@ -237,6 +237,22 @@ Example:
|
||||
bool pass_header = false;//pass headers to the data stream
|
||||
tableLookup(L, "header", pass_header);
|
||||
|
||||
/* httpheader */
|
||||
curl_slist* hlist = NULL;
|
||||
lua_pushstring(L, "httpheader");
|
||||
lua_gettable(L, -2);
|
||||
if (lua_istable(L, -1)) {
|
||||
for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 2)) {
|
||||
lua_pushvalue(L, -2);
|
||||
const char *val = lua_tostring(L, -2);
|
||||
if (val){
|
||||
hlist = curl_slist_append(hlist, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
/* httpheader end*/
|
||||
|
||||
lua_Integer connectTimeout = 20;
|
||||
tableLookup(L, "connectTimeout", connectTimeout);
|
||||
|
||||
@@ -299,7 +315,10 @@ Example:
|
||||
curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, (silent)?1L:0L);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, (verbose)?1L:0L);
|
||||
curl_easy_setopt(curl_handle, CURLOPT_HEADER, (pass_header)?1L:0L);
|
||||
|
||||
if (hlist) {
|
||||
/* set our custom set of headers */
|
||||
curl_easy_setopt(curl_handle, CURLOPT_HTTPHEADER, hlist);
|
||||
}
|
||||
progressData pgd;
|
||||
|
||||
if (!silent) {
|
||||
@@ -353,7 +372,8 @@ Example:
|
||||
if ((res2 == CURLE_OK) && dredirect)
|
||||
msg += std::string("\n redirect to: ") + dredirect;
|
||||
}
|
||||
|
||||
if(hlist)
|
||||
curl_slist_free_all(hlist);
|
||||
curl_easy_cleanup(curl_handle);
|
||||
if (toFile)
|
||||
fclose(fp);
|
||||
|
Reference in New Issue
Block a user