diff --git a/src/client/http/PostData.h b/src/client/http/PostData.h index 3ce84cf0b..7a04777c7 100644 --- a/src/client/http/PostData.h +++ b/src/client/http/PostData.h @@ -16,6 +16,7 @@ namespace http ByteString name; ByteString value; std::optional filename; + std::optional contentType; }; using StringData = ByteString; using FormData = std::vector; diff --git a/src/client/http/requestmanager/Libcurl.cpp b/src/client/http/requestmanager/Libcurl.cpp index 976a80fa1..aa3943e7f 100644 --- a/src/client/http/requestmanager/Libcurl.cpp +++ b/src/client/http/requestmanager/Libcurl.cpp @@ -421,6 +421,10 @@ namespace http { HandleCURLcode(curl_mime_filename(part, field.filename->c_str())); } + if (field.contentType.has_value()) + { + HandleCURLcode(curl_mime_type(part, field.contentType->c_str())); + } } HandleCURLcode(curl_easy_setopt(handle->curlEasy, CURLOPT_MIMEPOST, handle->curlPostFields)); #else diff --git a/src/lua/LuaHttp.cpp b/src/lua/LuaHttp.cpp index 0268d3a1a..c9c1ecc30 100644 --- a/src/lua/LuaHttp.cpp +++ b/src/lua/LuaHttp.cpp @@ -255,37 +255,54 @@ static int request(lua_State *L, bool isPost) { for (auto i = 0U; i < size; ++i) { + auto &formItem = formData.emplace_back(); lua_rawgeti(L, 2, i + 1); if (!lua_istable(L, -1)) { luaL_error(L, "form item %i is not a table", i + 1); } - lua_rawgeti(L, -1, 1); - if (!lua_isstring(L, -1)) - { - luaL_error(L, "name of form item %i is not a string", i + 1); - } - auto name = tpt_lua_toByteString(L, -1); - lua_pop(L, 1); - lua_rawgeti(L, -1, 2); - if (!lua_isstring(L, -1)) - { - luaL_error(L, "value of form item %i is not a string", i + 1); - } - auto value = tpt_lua_toByteString(L, -1); - lua_pop(L, 1); - std::optional filename; - lua_rawgeti(L, -1, 3); - if (!lua_isnoneornil(L, -1)) { + lua_rawgeti(L, -1, 1); if (!lua_isstring(L, -1)) { - luaL_error(L, "filename of form item %i is not a string", i + 1); + luaL_error(L, "name of form item %i is not a string", i + 1); } - filename = tpt_lua_toByteString(L, -1); + formItem.name = tpt_lua_toByteString(L, -1); + lua_pop(L, 1); + } + { + lua_rawgeti(L, -1, 2); + if (!lua_isstring(L, -1)) + { + luaL_error(L, "value of form item %i is not a string", i + 1); + } + formItem.value = tpt_lua_toByteString(L, -1); + lua_pop(L, 1); + } + { + lua_rawgeti(L, -1, 3); + if (!lua_isnoneornil(L, -1)) + { + if (!lua_isstring(L, -1)) + { + luaL_error(L, "filename of form item %i is not a string", i + 1); + } + formItem.filename = tpt_lua_toByteString(L, -1); + } + lua_pop(L, 1); + } + { + lua_rawgeti(L, -1, 4); + if (!lua_isnoneornil(L, -1)) + { + if (!lua_isstring(L, -1)) + { + luaL_error(L, "content type of form item %i is not a string", i + 1); + } + formItem.contentType = tpt_lua_toByteString(L, -1); + } + lua_pop(L, 1); } - lua_pop(L, 1); - formData.push_back({ name, value, filename }); lua_pop(L, 1); } } @@ -295,7 +312,9 @@ static int request(lua_State *L, bool isPost) while (lua_next(L, 2)) { lua_pushvalue(L, -2); - formData.push_back({ tpt_lua_toByteString(L, -1), tpt_lua_toByteString(L, -2) }); + auto &formItem = formData.emplace_back(); + formItem.name = tpt_lua_toByteString(L, -1); + formItem.value = tpt_lua_toByteString(L, -2); lua_pop(L, 2); } }