From: Ilya Kosarev <i.kosarev@tarantool.org> To: tarantool-patches@freelists.org Cc: tarantool-patches@dev.tarantool.org Subject: [Tarantool-patches] [PATCH v4 3/4] http: enrich httpc_request with curl error message buffer Date: Mon, 28 Oct 2019 20:11:14 +0300 [thread overview] Message-ID: <1290bf755e9e93a36be6fe0cb586b91f2d581531.1572282336.git.i.kosarev@tarantool.org> (raw) In-Reply-To: <cover.1572282336.git.i.kosarev@tarantool.org> In-Reply-To: <cover.1572282336.git.i.kosarev@tarantool.org> When processing curl request error code, we are collecting error message using curl_easy_strerror. Now we are providing more info in errmsg, which is obtained using curl_easy_setopt with CURLOPT_ERRORBUFFER option. Test case to confirm it is added. Closes #4578 @TarantoolBot document Title: http: new field in client_object:request return table Update the documentation for client_object:request method to reflect new field errmsg in return table. It contains extended curl request error message obtained using CURLOPT_ERRORBUFFER option. See https://curl.haxx.se/libcurl/c/CURLOPT_ERRORBUFFER.html --- src/httpc.c | 1 + src/httpc.h | 5 +++++ src/lua/httpc.c | 4 ++++ test/app-tap/http_client.test.lua | 4 +++- 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/httpc.c b/src/httpc.c index 22b54d16a..b493a8498 100644 --- a/src/httpc.c +++ b/src/httpc.c @@ -398,6 +398,7 @@ httpc_execute(struct httpc_request *req, double timeout) curl_easy_setopt(req->curl_request.easy, CURLOPT_HEADERDATA, (void *) req); curl_easy_setopt(req->curl_request.easy, CURLOPT_PRIVATE, (void *) &req->curl_request); curl_easy_setopt(req->curl_request.easy, CURLOPT_HTTPHEADER, req->headers); + curl_easy_setopt(req->curl_request.easy, CURLOPT_ERRORBUFFER, req->errmsg); ++env->stat.total_requests; diff --git a/src/httpc.h b/src/httpc.h index f710b3d13..145b59929 100644 --- a/src/httpc.h +++ b/src/httpc.h @@ -105,6 +105,11 @@ struct httpc_request { int status; /** Error message */ const char *reason; + /** + * Buffer for error message obtained using + * CURLOPT_ERRORBUFFER option. + */ + const char errmsg[CURL_ERROR_SIZE]; /** buffer of headers */ struct region resp_headers; /** buffer of body */ diff --git a/src/lua/httpc.c b/src/lua/httpc.c index 6ed4eb788..9fb8e4801 100644 --- a/src/lua/httpc.c +++ b/src/lua/httpc.c @@ -335,6 +335,10 @@ luaT_httpc_request(lua_State *L) lua_pushstring(L, req->reason); lua_settable(L, -3); + lua_pushstring(L, "errmsg"); + lua_pushstring(L, req->errmsg); + lua_settable(L, -3); + size_t headers_len = region_used(&req->resp_headers); if (headers_len > 0) { char *headers = region_join(&req->resp_headers, headers_len); diff --git a/test/app-tap/http_client.test.lua b/test/app-tap/http_client.test.lua index b85b605cf..2fac80115 100755 --- a/test/app-tap/http_client.test.lua +++ b/test/app-tap/http_client.test.lua @@ -171,7 +171,7 @@ local function test_cancel_and_errinj(test, url, opts) end local function test_post_and_get(test, url, opts) - test:plan(21) + test:plan(23) local http = client.new() test:ok(http ~= nil, "client is created") @@ -227,6 +227,7 @@ local function test_post_and_get(test, url, opts) r = responses.absent_get test:is(r.status, 500, "GET: absent method http code page exists") test:is(r.reason, 'Unknown', '500 - Unknown') + test:is(type(r.errmsg), 'string', 'check error message') test:is(r.body, "No such method", "GET: absent method right body") r = responses.empty_post @@ -249,6 +250,7 @@ local function test_post_and_get(test, url, opts) r = responses.bad_get test:is(r.status, 404, "GET: http page not exists") test:is(r.reason, 'Unknown', '404 - Unknown') + test:is(type(r.errmsg), 'string', 'check error message') test:isnt(r.body:len(), 0, "GET: not empty body page not exists") test:ok(string.find(r.body, "Not Found"), "GET: right body page not exists") -- 2.17.1
next prev parent reply other threads:[~2019-10-28 17:11 UTC|newest] Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-10-28 17:11 [Tarantool-patches] [PATCH v4 0/4] http: add CURLOPT_ACCEPT_ENCODING option and following improvements Ilya Kosarev 2019-10-28 17:11 ` [Tarantool-patches] [PATCH v4 1/4] http: add CURLOPT_ACCEPT_ENCODING option Ilya Kosarev 2019-10-28 23:42 ` Alexander Turenko 2019-10-28 17:11 ` [Tarantool-patches] [PATCH v4 2/4] http: remove redundant & incorrect case for curl_request code Ilya Kosarev 2019-10-28 23:42 ` Alexander Turenko 2019-10-28 17:11 ` Ilya Kosarev [this message] 2019-10-28 23:41 ` [Tarantool-patches] [PATCH v4 3/4] http: enrich httpc_request with curl error message buffer Alexander Turenko 2019-11-07 12:07 ` Ilya Kosarev 2019-10-28 17:11 ` [Tarantool-patches] [PATCH v4 4/4] http: add CURLE_BAD_CONTENT_ENCODING case for curl_request code Ilya Kosarev 2019-10-28 23:42 ` Alexander Turenko 2019-10-28 23:43 ` [Tarantool-patches] [PATCH v4 0/4] http: add CURLOPT_ACCEPT_ENCODING option and following improvements Alexander Turenko 2019-11-07 12:07 ` Ilya Kosarev
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1290bf755e9e93a36be6fe0cb586b91f2d581531.1572282336.git.i.kosarev@tarantool.org \ --to=i.kosarev@tarantool.org \ --cc=tarantool-patches@dev.tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='Re: [Tarantool-patches] [PATCH v4 3/4] http: enrich httpc_request with curl error message buffer' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox