From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id D19BD26BC5 for ; Mon, 19 Aug 2019 08:12:34 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id UaFGOwzCLvxL for ; Mon, 19 Aug 2019 08:12:34 -0400 (EDT) Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 8EBF826B95 for ; Mon, 19 Aug 2019 08:12:34 -0400 (EDT) From: Ilya Kosarev Subject: [tarantool-patches] [PATCH] http: add CURLOPT_ACCEPT_ENCODING option Date: Mon, 19 Aug 2019 15:12:30 +0300 Message-Id: <20190819121230.17621-1-i.kosarev@tarantool.org> Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: tarantool-patches@freelists.org Cc: georgy@tarantool.org, alexander.turenko@tarantool.org, i.kosarev@corp.mail.ru, Ilya Kosarev CURLOPT_ACCEPT_ENCODING option is now supported. This option enables automatic decompression of HTTP downloads. See https://curl.haxx.se/libcurl/c/CURLOPT_ACCEPT_ENCODING.html Closes #4232 --- Branch: https://github.com/tarantool/tarantool/tree/i.kosarev/gh-4232-curlopt-accept-encoding Issue: https://github.com/tarantool/tarantool/issues/4232 src/httpc.c | 13 +++++++++++++ src/httpc.h | 12 ++++++++++++ src/lua/httpc.c | 5 +++++ src/lua/httpc.lua | 2 ++ 4 files changed, 32 insertions(+) diff --git a/src/httpc.c b/src/httpc.c index 54bc785e1..736184b6b 100644 --- a/src/httpc.c +++ b/src/httpc.c @@ -337,6 +337,19 @@ httpc_set_follow_location(struct httpc_request *req, long follow) follow); } +void +httpc_set_accept_encoding(struct httpc_request *req, const char *encoding) +{ +#if LIBCURL_VERSION_NUM >= 0x071506 /* CURLOPT_ACCEPT_ENCODING was called + CURLOPT_ENCODING before libcurl 7.21.6 */ + curl_easy_setopt(req->curl_request.easy, CURLOPT_ACCEPT_ENCODING, + encoding); +#else + curl_easy_setopt(req->curl_request.easy, CURLOPT_ENCODING, + encoding); +#endif +} + int httpc_execute(struct httpc_request *req, double timeout) { diff --git a/src/httpc.h b/src/httpc.h index c6882a534..d5f4320c5 100644 --- a/src/httpc.h +++ b/src/httpc.h @@ -312,6 +312,18 @@ httpc_set_interface(struct httpc_request *req, const char *interface); void httpc_set_follow_location(struct httpc_request *req, long follow); +/** + * Enable automatic decompression of HTTP downloads: set the contents + * of the Accept-Encoding: header sent in an HTTP request, + * and enable decoding of a response + * when a Content-Encoding: header is received. + * @param req request + * @param encoding - specify what encoding you'd like. + * @see https://curl.haxx.se/libcurl/c/CURLOPT_ACCEPT_ENCODING.html + */ +void +httpc_set_accept_encoding(struct httpc_request *req, const char *encoding); + /** * This function does async HTTP request * @param request - reference to request object with filled fields diff --git a/src/lua/httpc.c b/src/lua/httpc.c index e02adb9fb..a57f08c6c 100644 --- a/src/lua/httpc.c +++ b/src/lua/httpc.c @@ -295,6 +295,11 @@ luaT_httpc_request(lua_State *L) httpc_set_follow_location(req, lua_toboolean(L, -1)); lua_pop(L, 1); + lua_getfield(L, 5, "accept_encoding"); + if (!lua_isnil(L, -1)) + httpc_set_accept_encoding(req, lua_tostring(L, -1)); + lua_pop(L, 1); + if (httpc_execute(req, timeout) != 0) { httpc_request_delete(req); return luaT_error(L); diff --git a/src/lua/httpc.lua b/src/lua/httpc.lua index 50ff91a36..4b73187c2 100644 --- a/src/lua/httpc.lua +++ b/src/lua/httpc.lua @@ -287,6 +287,8 @@ end -- 'Location' header that a server sends as part of an -- 3xx response; -- +-- accept_encoding - enables automatic decompression of HTTP downloads; +-- -- Returns: -- { -- status=NUMBER, -- 2.17.1