From patchwork Thu Jan 10 19:33:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masaya Suzuki X-Patchwork-Id: 10756691 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4CE0A159A for ; Thu, 10 Jan 2019 19:34:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3BC4429A42 for ; Thu, 10 Jan 2019 19:34:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2FE2429AF2; Thu, 10 Jan 2019 19:34:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5781129A42 for ; Thu, 10 Jan 2019 19:34:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728527AbfAJTeY (ORCPT ); Thu, 10 Jan 2019 14:34:24 -0500 Received: from mail-pl1-f201.google.com ([209.85.214.201]:51502 "EHLO mail-pl1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728112AbfAJTeX (ORCPT ); Thu, 10 Jan 2019 14:34:23 -0500 Received: by mail-pl1-f201.google.com with SMTP id 12so6755233plb.18 for ; Thu, 10 Jan 2019 11:34:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=aGfJ78pC8oaTrc2XYhM4yj5669sebfTIeY/InoN6ijQ=; b=UdQgusasnr439EYu7PIROuXpm6CT2+HOx1tkIRpKRhD6gBIr7vhsSpF0k5uncBoeK+ toeXCfhq/Tmm5+eYxdyirN7hEkB0gMaCHNC4HjGI3LFDiaiq1HXhN7aTCDv4ghGebjWS tn6VmMYUZ4DgS+rEU8ClxzY8Jgw5fnUPdzBDNq1ULawLLWN3BuC4rohUjLUP7jtlGnB2 tgl1EJnW4bvYB12GGVIDlQ/scuBUmtEjylVZat9rEAOP0I4rdXffrY6UPJXTu1Hf/j9l 8zqzVlp1TrZoln8SRgTuWsZ+t6YluVYkGN7wtf7aDF1y0npUn2vfopsvX9tQoPprRtzi Hlhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=aGfJ78pC8oaTrc2XYhM4yj5669sebfTIeY/InoN6ijQ=; b=DRUE2v3b3s6QOBI2qsnjtt4B0DlKEnXhZidikejlQ5FZebJxuURV3AcQx3dzIslPzE JtY7OHkPq4BC7QM/7p2UvhVc+iHvwE0lxWb6aLBcQMXYbQL1MG9Jp1IeS7SosNLZcTiY Z5PXMnX3NdiQezFUsovrV4Pdm4Ib6L2+Nme++NIFT4rShzmiylT2MyhHJPXFUUxolg7o pk4FJYZUuJkQZGYk0NogZYq/iDDGjNgW7iX+eEyS90r0QZoDMtxVhX/XCiq4WMwoe35r E/BWNg/G4Z0HA0kfHA3yYOLFWBBHMuTtii4gAXBs6+DYzbKmCXcWw7DzuZlfS+yhTHLp ej7g== X-Gm-Message-State: AJcUukdsRKgZJma07JPdtppmydGpLF7U/InxdDHg7oAxyVXG27zvP9xn 8GApywDWndllYqt8nrV6q91EH8LUON02vqR8Afs= X-Google-Smtp-Source: ALg8bN64ptiWZts+T7zDhzeLTdI1jsByR8f/134EQTg2gu5FiWopXE0xMFIy2xLRILQRZ11oAnYigVCacmUaxB+rHB8= X-Received: by 2002:a62:9687:: with SMTP id s7mr3103957pfk.56.1547148863134; Thu, 10 Jan 2019 11:34:23 -0800 (PST) Date: Thu, 10 Jan 2019 11:33:46 -0800 In-Reply-To: <20190110193350.213327-1-masayasuzuki@google.com> Message-Id: <20190110193350.213327-2-masayasuzuki@google.com> Mime-Version: 1.0 References: <20190108024741.62176-1-masayasuzuki@google.com> <20190110193350.213327-1-masayasuzuki@google.com> X-Mailer: git-send-email 2.20.1.97.g81188d93c3-goog Subject: [PATCH v4 1/5] http: support file handles for HTTP_KEEP_ERROR From: Masaya Suzuki To: masayasuzuki@google.com Cc: git@vger.kernel.org, jrnieder@gmail.com, peff@peff.net, sunshine@sunshineco.com, szeder.dev@gmail.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP HTTP_KEEP_ERROR makes it easy to debug HTTP transport errors. In order to make HTTP_KEEP_ERROR enabled for all requests, file handles need to be supported. Signed-off-by: Masaya Suzuki --- http.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/http.c b/http.c index 0b6807cef9..4eccf4c5d8 100644 --- a/http.c +++ b/http.c @@ -1991,16 +1991,26 @@ static int http_request_reauth(const char *url, /* * If we are using KEEP_ERROR, the previous request may have * put cruft into our output stream; we should clear it out before - * making our next request. We only know how to do this for - * the strbuf case, but that is enough to satisfy current callers. + * making our next request. */ if (options && options->keep_error) { switch (target) { case HTTP_REQUEST_STRBUF: strbuf_reset(result); break; + case HTTP_REQUEST_FILE: + if (fflush(result)) { + error_errno("unable to flush a file"); + return HTTP_START_FAILED; + } + rewind(result); + if (ftruncate(fileno(result), 0) < 0) { + error_errno("unable to truncate a file"); + return HTTP_START_FAILED; + } + break; default: - BUG("HTTP_KEEP_ERROR is only supported with strbufs"); + BUG("Unknown http_request target"); } } From patchwork Thu Jan 10 19:33:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masaya Suzuki X-Patchwork-Id: 10756695 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 11BC213B5 for ; Thu, 10 Jan 2019 19:34:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0008D29A41 for ; Thu, 10 Jan 2019 19:34:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E80CA29AE9; Thu, 10 Jan 2019 19:34:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 812FB29A41 for ; Thu, 10 Jan 2019 19:34:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728715AbfAJTe1 (ORCPT ); Thu, 10 Jan 2019 14:34:27 -0500 Received: from mail-pg1-f201.google.com ([209.85.215.201]:54619 "EHLO mail-pg1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728650AbfAJTe0 (ORCPT ); Thu, 10 Jan 2019 14:34:26 -0500 Received: by mail-pg1-f201.google.com with SMTP id p4so6896513pgj.21 for ; Thu, 10 Jan 2019 11:34:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=eY6em6pDgr6rn0D5HhNUuT2zomHY3meun22ng88lr68=; b=EOcNQA4zuEUkyiGZqY8X9aRWazTdSmrS6m5ZFiXPkp8iTGsXL+FaPYWBa5TVVEDRxD 9GnHaXUPpE9uXF8JibM7jt1EAN0S6htsaBhLNtaowtmr+vZaxC6lEBlIZw6sfPElfa4R ezFJkroiR3U90nlVlcRJtMqp9nurbbP5GiK7OCOTtTtJY1sUJvZtm9d9yQgMNpbrEjEL dxxy4cIvj1stk0gSkp2D6QYxNdisLGVUsjjbTmNgUnCqurliP2xtoxg2uyiYfbHMwoJW YSOFmmXRi+NELuxSGAa7pA9DZF0uVBc0xU9zWdXzvUWcI1xHgFrtn5n7/oe1ngKQDDkj 75HQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=eY6em6pDgr6rn0D5HhNUuT2zomHY3meun22ng88lr68=; b=Ay/ez2eQhZKbpIDqFLqS8iiivumcrXY4zP8Wo5WBkrmIsPKWf8Rhw3Kvma+0OoMqIW BCcttSC2ghjZEnEudpaRoXqwW42XEhvjhqqaor4XcEKKaAxGldNToqEfJ6x+XZ4vrfaI kt+u5wVPtKJE05a8kQVgjKE6DX01MoEb3Fy/axtpOrpZvuMESxj6fST1ScAVHB85SbWD DBCYP/aWV9fJtCvLqtR0XQYzJlX3EzeaJxY+xkkEghpaaGQJtChYMoZjzvx/TFAcUbrI Duv0NvcaXsFTLjnWVx5GQJ3AztdzVcQbwaX0jeprsws8Pc5fLhX+XD+MVqp0PWSGNzjZ hAsw== X-Gm-Message-State: AJcUukf3c0aYfyqoMWYipw02W5pY1C4NHicGur8oNLRWGS+mZaTaKtGE zDJcjww1YSYtAgQ/voG1lHWUNkO5xNgXi7Ck8IQ= X-Google-Smtp-Source: ALg8bN7Afdx6OuR35LefRmtoXAU72kaH3W6MhLcYnlCW3AymxtnBFw3ogIzmUggZKobMIzaktmjSkTRiDzQcMr1Tav8= X-Received: by 2002:a65:5b0d:: with SMTP id y13mr3197766pgq.3.1547148865682; Thu, 10 Jan 2019 11:34:25 -0800 (PST) Date: Thu, 10 Jan 2019 11:33:47 -0800 In-Reply-To: <20190110193350.213327-1-masayasuzuki@google.com> Message-Id: <20190110193350.213327-3-masayasuzuki@google.com> Mime-Version: 1.0 References: <20190108024741.62176-1-masayasuzuki@google.com> <20190110193350.213327-1-masayasuzuki@google.com> X-Mailer: git-send-email 2.20.1.97.g81188d93c3-goog Subject: [PATCH v4 2/5] http: enable keep_error for HTTP requests From: Masaya Suzuki To: masayasuzuki@google.com Cc: git@vger.kernel.org, jrnieder@gmail.com, peff@peff.net, sunshine@sunshineco.com, szeder.dev@gmail.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP curl stops parsing a response when it sees a bad HTTP status code and it has CURLOPT_FAILONERROR set. This prevents GIT_CURL_VERBOSE to show HTTP headers on error. keep_error is an option to receive the HTTP response body for those error responses. By enabling this option, curl will process the HTTP response headers, and they're shown if GIT_CURL_VERBOSE is set. Signed-off-by: Masaya Suzuki --- http.c | 42 +++++++++++++++++++----------------------- http.h | 1 - remote-curl.c | 1 - 3 files changed, 19 insertions(+), 25 deletions(-) diff --git a/http.c b/http.c index 4eccf4c5d8..954bebf684 100644 --- a/http.c +++ b/http.c @@ -1876,8 +1876,6 @@ static int http_request(const char *url, strbuf_addstr(&buf, "Pragma:"); if (options && options->no_cache) strbuf_addstr(&buf, " no-cache"); - if (options && options->keep_error) - curl_easy_setopt(slot->curl, CURLOPT_FAILONERROR, 0); if (options && options->initial_request && http_follow_config == HTTP_FOLLOW_INITIAL) curl_easy_setopt(slot->curl, CURLOPT_FOLLOWLOCATION, 1); @@ -1895,6 +1893,7 @@ static int http_request(const char *url, curl_easy_setopt(slot->curl, CURLOPT_URL, url); curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(slot->curl, CURLOPT_ENCODING, ""); + curl_easy_setopt(slot->curl, CURLOPT_FAILONERROR, 0); ret = run_one_slot(slot, &results); @@ -1989,29 +1988,26 @@ static int http_request_reauth(const char *url, return ret; /* - * If we are using KEEP_ERROR, the previous request may have - * put cruft into our output stream; we should clear it out before - * making our next request. + * The previous request may have put cruft into our output stream; we + * should clear it out before making our next request. */ - if (options && options->keep_error) { - switch (target) { - case HTTP_REQUEST_STRBUF: - strbuf_reset(result); - break; - case HTTP_REQUEST_FILE: - if (fflush(result)) { - error_errno("unable to flush a file"); - return HTTP_START_FAILED; - } - rewind(result); - if (ftruncate(fileno(result), 0) < 0) { - error_errno("unable to truncate a file"); - return HTTP_START_FAILED; - } - break; - default: - BUG("Unknown http_request target"); + switch (target) { + case HTTP_REQUEST_STRBUF: + strbuf_reset(result); + break; + case HTTP_REQUEST_FILE: + if (fflush(result)) { + error_errno("unable to flush a file"); + return HTTP_START_FAILED; } + rewind(result); + if (ftruncate(fileno(result), 0) < 0) { + error_errno("unable to truncate a file"); + return HTTP_START_FAILED; + } + break; + default: + BUG("Unknown http_request target"); } credential_fill(&http_auth); diff --git a/http.h b/http.h index d305ca1dc7..eebf40688c 100644 --- a/http.h +++ b/http.h @@ -146,7 +146,6 @@ extern char *get_remote_object_url(const char *url, const char *hex, /* Options for http_get_*() */ struct http_get_options { unsigned no_cache:1, - keep_error:1, initial_request:1; /* If non-NULL, returns the content-type of the response. */ diff --git a/remote-curl.c b/remote-curl.c index 1220dffcdc..d8eda2380a 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -380,7 +380,6 @@ static struct discovery *discover_refs(const char *service, int for_push) http_options.extra_headers = &extra_headers; http_options.initial_request = 1; http_options.no_cache = 1; - http_options.keep_error = 1; http_ret = http_get_strbuf(refs_url.buf, &buffer, &http_options); switch (http_ret) { From patchwork Thu Jan 10 19:33:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masaya Suzuki X-Patchwork-Id: 10756697 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2397C159A for ; Thu, 10 Jan 2019 19:34:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1291C29A41 for ; Thu, 10 Jan 2019 19:34:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 066F429AE9; Thu, 10 Jan 2019 19:34:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A0F4729A41 for ; Thu, 10 Jan 2019 19:34:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728737AbfAJTea (ORCPT ); Thu, 10 Jan 2019 14:34:30 -0500 Received: from mail-vk1-f202.google.com ([209.85.221.202]:40222 "EHLO mail-vk1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728493AbfAJTe3 (ORCPT ); Thu, 10 Jan 2019 14:34:29 -0500 Received: by mail-vk1-f202.google.com with SMTP id s196so2382220vke.7 for ; Thu, 10 Jan 2019 11:34:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=TT45UDm9g2rUYvv+kMOZm9eoLtFQ5YsQseNzc46jSto=; b=t3JJlxHYQz+oSR4Dqu/4ukQej27NrBPrElT31+BIE7HQfnjbim2lP0HjgTRSH8Psyh P15g9VmGWgIP1jBFb7CCyphhGksh/6ITcmbSNYvOraLo2wkn4/0Oc2+6Cqag/qr/1P4v b9zaOUnnBmUcepLQWd9ssyzkhsRju7xCXU+ehzQwvYWD+9yu5nxran1spc99Ms8Mwe/b riac/TdGA3j0EV0l4PkVa49vwGs3edZFegkAaPdBHqYF9wIc2wyttkCbL86acF83T4l4 y36KBuI1nUAe9tTKJSsJTGyMOsAA/vgrIFgia2O9+dSg4XSZxh1XeIV6Wb86lLBGcQda zMAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=TT45UDm9g2rUYvv+kMOZm9eoLtFQ5YsQseNzc46jSto=; b=Jrh7ZXJjrhiHCjwTcwgzhK4yKDLRgFRs1dV9iw5kwwtl56LG6AjfVUMrMjiV+O0q1S tHH7W5JsdQXp7bD1ykZp2Wl6BZtahVTOKEuwm2jak0/h4jzZPgBYNk2HdyF/WOL2nFv7 NwO+fO20WdjOAly+qRii1TYkcyINdorTmxoA30rdQUV5P0LwKGhzATURECQnNxZVoJKl 3TV0MWb5CYjjGW3xdrVM/KlbELsJrQBm1NOZa/nkaFzZWHpn1u2bZ3AtAa2nEyNvQRkx DKRGktQ/jLtYeDTHH+bKrLbo4BlOAuYs7Wz+OzcXJVpjh8S/An2oAMRfQK9iOapwBdPX cyPQ== X-Gm-Message-State: AJcUukcsNie6dA7awWUa7beRl7wF0HBkXL3agtlLkGV7IPGaNWXyJKQU BgnNABFC937tGNimgDOpMSly9BYQCXQtGyqm73o= X-Google-Smtp-Source: ALg8bN62liOC57+ZugvaAgRJlLEaDBAP9ltT1wzDUqlfIgGDXJ+079bP1eDFDSjkEvAqlh59mP5FEm4nxDysqTv1jfA= X-Received: by 2002:a67:4950:: with SMTP id w77mr5247179vsa.40.1547148868033; Thu, 10 Jan 2019 11:34:28 -0800 (PST) Date: Thu, 10 Jan 2019 11:33:48 -0800 In-Reply-To: <20190110193350.213327-1-masayasuzuki@google.com> Message-Id: <20190110193350.213327-4-masayasuzuki@google.com> Mime-Version: 1.0 References: <20190108024741.62176-1-masayasuzuki@google.com> <20190110193350.213327-1-masayasuzuki@google.com> X-Mailer: git-send-email 2.20.1.97.g81188d93c3-goog Subject: [PATCH v4 3/5] remote-curl: define struct for CURLOPT_WRITEFUNCTION From: Masaya Suzuki To: masayasuzuki@google.com Cc: git@vger.kernel.org, jrnieder@gmail.com, peff@peff.net, sunshine@sunshineco.com, szeder.dev@gmail.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In order to pass more values for rpc_in, define a struct and pass it as an additional value. Signed-off-by: Masaya Suzuki --- remote-curl.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/remote-curl.c b/remote-curl.c index d8eda2380a..d4673b6e8c 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -545,14 +545,22 @@ static curlioerr rpc_ioctl(CURL *handle, int cmd, void *clientp) } #endif +struct rpc_in_data { + struct rpc_state *rpc; +}; + +/* + * A callback for CURLOPT_WRITEFUNCTION. The return value is the bytes consumed + * from ptr. + */ static size_t rpc_in(char *ptr, size_t eltsize, size_t nmemb, void *buffer_) { size_t size = eltsize * nmemb; - struct rpc_state *rpc = buffer_; + struct rpc_in_data *data = buffer_; if (size) - rpc->any_written = 1; - write_or_die(rpc->in, ptr, size); + data->rpc->any_written = 1; + write_or_die(data->rpc->in, ptr, size); return size; } @@ -632,6 +640,7 @@ static int post_rpc(struct rpc_state *rpc) size_t gzip_size = 0; int err, large_request = 0; int needs_100_continue = 0; + struct rpc_in_data rpc_in_data; /* Try to load the entire request, if we can fit it into the * allocated buffer space we can use HTTP/1.0 and avoid the @@ -764,7 +773,8 @@ static int post_rpc(struct rpc_state *rpc) curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, rpc_in); - curl_easy_setopt(slot->curl, CURLOPT_FILE, rpc); + rpc_in_data.rpc = rpc; + curl_easy_setopt(slot->curl, CURLOPT_FILE, &rpc_in_data); rpc->any_written = 0; From patchwork Thu Jan 10 19:33:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masaya Suzuki X-Patchwork-Id: 10756699 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7CED9159A for ; Thu, 10 Jan 2019 19:34:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6BB2029A42 for ; Thu, 10 Jan 2019 19:34:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6007529AEA; Thu, 10 Jan 2019 19:34:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0B74B29A42 for ; Thu, 10 Jan 2019 19:34:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728789AbfAJTec (ORCPT ); Thu, 10 Jan 2019 14:34:32 -0500 Received: from mail-qt1-f202.google.com ([209.85.160.202]:45029 "EHLO mail-qt1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728493AbfAJTeb (ORCPT ); Thu, 10 Jan 2019 14:34:31 -0500 Received: by mail-qt1-f202.google.com with SMTP id j5so12317678qtk.11 for ; Thu, 10 Jan 2019 11:34:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=WkPbmKE4EqFhKWYosAbesHk6+aKw8BGy9ySnI9h5PBA=; b=FXDFTbHj8XH+6xjY/uDnhotou43eydZGLdI/ozxA/ThpPDZ3vHRFKnas+TntLq24Uw yQrLIl6+BFfLGVDoTPLhVjU2X+8xuJZ7j0pe2B5285YKWV9aj/KAwnrnli+8gi8wD4bg riiSxgj9qp3xKQFZqTz2Taf/j74ju6mau0WAL1NJmttsE3tlLfFgcxmEak8a+pMRmLmG wkZBf5cwah5YT0bePFHDIe+D4kPUB+rOo68S49ckzvWmuN7VFBglh46QcjG0kpi/bHzZ m2qJw43mSyt+vToFHV/J5Ja9Qo6Q5pYaaa6tiYIgIrY/0UHRpnLeAnsTIkinYvboF/eM mliQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=WkPbmKE4EqFhKWYosAbesHk6+aKw8BGy9ySnI9h5PBA=; b=SndDjAJ9DNcsZcLgOeKZn7wh6aWxYaTplPx9q0tR6UpdItXg9ALY8spiWETuzZHzVo 9wBYyQ+kI4rAN9OPe1GHqQlCXhSplkn1jKUcn3tHXHUXaAmM7Ytl84X4LbfcnphedYjv EDjYQaMkmA720uIsamFqCxRbv1sxS6GBXMGs2G98AjT04aSgD3a1eyIuwrNkcJ/LFuqs kwRJkMQ3EfhtxcXith4xUNDyNHwNaG4LhAhKJcaEn6WI2g59U5MlC4EBVRYOEIssLosc Y2HJ9V9e0K0+nb/guLRr4C0+Uh2yLNy5bPew1/T3uoxiDCe0QW9QBOPHqyRqSIAAGSz9 HNig== X-Gm-Message-State: AJcUukeb5Vt0Te9GcvoybjVM6C5SYnTRCmI8TON72NplW64AGhdiX8B9 BGa2ld6zEhaf52vtSViJrmJXWwKvkippQkhtEI8= X-Google-Smtp-Source: ALg8bN6bzmZavegMtGchlUfYZ0NikYRNYfbs5W6YpsBxrdU0Gr3DZ8LS63Azd1O3utZAA9xPon55ZGB2/L7FwppI0Os= X-Received: by 2002:a0c:879a:: with SMTP id 26mr4413506qvj.62.1547148870458; Thu, 10 Jan 2019 11:34:30 -0800 (PST) Date: Thu, 10 Jan 2019 11:33:49 -0800 In-Reply-To: <20190110193350.213327-1-masayasuzuki@google.com> Message-Id: <20190110193350.213327-5-masayasuzuki@google.com> Mime-Version: 1.0 References: <20190108024741.62176-1-masayasuzuki@google.com> <20190110193350.213327-1-masayasuzuki@google.com> X-Mailer: git-send-email 2.20.1.97.g81188d93c3-goog Subject: [PATCH v4 4/5] remote-curl: unset CURLOPT_FAILONERROR From: Masaya Suzuki To: masayasuzuki@google.com Cc: git@vger.kernel.org, jrnieder@gmail.com, peff@peff.net, sunshine@sunshineco.com, szeder.dev@gmail.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP By not setting CURLOPT_FAILONERROR, curl parses the HTTP response headers even if the response is an error. This makes GIT_CURL_VERBOSE to show the HTTP headers, which is useful for debugging. Signed-off-by: Masaya Suzuki --- remote-curl.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/remote-curl.c b/remote-curl.c index d4673b6e8c..91b39ca098 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -547,6 +547,7 @@ static curlioerr rpc_ioctl(CURL *handle, int cmd, void *clientp) struct rpc_in_data { struct rpc_state *rpc; + struct active_request_slot *slot; }; /* @@ -558,6 +559,13 @@ static size_t rpc_in(char *ptr, size_t eltsize, { size_t size = eltsize * nmemb; struct rpc_in_data *data = buffer_; + long response_code; + + if (curl_easy_getinfo(data->slot->curl, CURLINFO_RESPONSE_CODE, + &response_code) != CURLE_OK) + return size; + if (response_code >= 300) + return size; if (size) data->rpc->any_written = 1; write_or_die(data->rpc->in, ptr, size); @@ -774,7 +782,9 @@ static int post_rpc(struct rpc_state *rpc) curl_easy_setopt(slot->curl, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION, rpc_in); rpc_in_data.rpc = rpc; + rpc_in_data.slot = slot; curl_easy_setopt(slot->curl, CURLOPT_FILE, &rpc_in_data); + curl_easy_setopt(slot->curl, CURLOPT_FAILONERROR, 0); rpc->any_written = 0; From patchwork Thu Jan 10 19:33:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masaya Suzuki X-Patchwork-Id: 10756701 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EB0CF13B5 for ; Thu, 10 Jan 2019 19:34:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D9D0F29A41 for ; Thu, 10 Jan 2019 19:34:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CE6E229AE9; Thu, 10 Jan 2019 19:34:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5C17229A41 for ; Thu, 10 Jan 2019 19:34:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728859AbfAJTee (ORCPT ); Thu, 10 Jan 2019 14:34:34 -0500 Received: from mail-pg1-f202.google.com ([209.85.215.202]:43820 "EHLO mail-pg1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728493AbfAJTed (ORCPT ); Thu, 10 Jan 2019 14:34:33 -0500 Received: by mail-pg1-f202.google.com with SMTP id v72so6906117pgb.10 for ; Thu, 10 Jan 2019 11:34:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=il3+uivG+vJ9y6BdcZtTQmgkQA325QFRMf7WaVuyBis=; b=t+4Blm2G1+QWMcUmqYR/FPfW50HjxGntHWZtxYYDu6yA0Mnq7yPtdb5Fq/4ZwD54vj t04mZCdRp9YpSm/XXB+ntqOB3D6nEY4iqq8GJDZKXPFSudOuaighIzdIBrdaGbR9nMBX dfIy3a9iITQNE4g6QI87pV1C0lNr9e0G3T8OAleBlUUwJFw7NsWNUl97+Zg/lsTDcOKC dYcLI7SUPuvliyZC27LGLEiZIXLQuToLC8AQ+Fwq+h3tIVCT2vU87TXZWF27xF4caYKV UjyRvayMI08+R+rzwA5u0o4EaAk7tpdy3NdFinmtqj17V0cg2g8Pi6/TSZzeLgZelfED 1P7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=il3+uivG+vJ9y6BdcZtTQmgkQA325QFRMf7WaVuyBis=; b=jg4NydgRV07/IgXXBfi1kqOP7+qoHqomtEVSuFPtXFArWjaUp/f2hfDeOP8p2VCeQJ u/rkBFEZKJnyifIlufjb25hRIJ306fIeL859uPKrkl+kkL9OyQxYsX3nZezUbzR4P4H0 aDMulaRR9NBOuChlanIYAevsN28oaYXjRPTkfUYUkysdZC5d6qP99RCxwQUHqbMhEbOP 9CBOdPEpK3ZlIftYt/LHfiwwGW5jmcnbYdYAUhPlZL/2vPbMVtoKjt2rtaxSofWs87Fc 5qsLmf9JDoO/vJqp2fYhPDiBji9GLkUE3hE2tda+1ttzttLBNeRwi3AIsb6469Sp5+lI 8NaA== X-Gm-Message-State: AJcUukfwDdbRKyjfWudbD84TkCwW586GXv5WPmdatKHXpoxfrgqXms0H nb4QSNAZRUdWMIXaVull0MeEoN9whklB7NE+02k= X-Google-Smtp-Source: ALg8bN6NJvzDD8kz7qAxlWDdq2V2XE3PV2fCuUL6qLZr+apQ+n6l5+6Q5da2hyJQk/6QV3RknLvWyDC7+R29JhkqQGc= X-Received: by 2002:aa7:81cc:: with SMTP id c12mr3007076pfn.69.1547148872622; Thu, 10 Jan 2019 11:34:32 -0800 (PST) Date: Thu, 10 Jan 2019 11:33:50 -0800 In-Reply-To: <20190110193350.213327-1-masayasuzuki@google.com> Message-Id: <20190110193350.213327-6-masayasuzuki@google.com> Mime-Version: 1.0 References: <20190108024741.62176-1-masayasuzuki@google.com> <20190110193350.213327-1-masayasuzuki@google.com> X-Mailer: git-send-email 2.20.1.97.g81188d93c3-goog Subject: [PATCH v4 5/5] test: test GIT_CURL_VERBOSE=1 shows an error From: Masaya Suzuki To: masayasuzuki@google.com Cc: git@vger.kernel.org, jrnieder@gmail.com, peff@peff.net, sunshine@sunshineco.com, szeder.dev@gmail.com Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This tests GIT_CURL_VERBOSE shows an error when an URL returns 500. This exercises the code in remote_curl. Signed-off-by: Masaya Suzuki --- t/lib-httpd/apache.conf | 1 + t/t5581-http-curl-verbose.sh | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100755 t/t5581-http-curl-verbose.sh diff --git a/t/lib-httpd/apache.conf b/t/lib-httpd/apache.conf index 581c010d8f..cc4b87507e 100644 --- a/t/lib-httpd/apache.conf +++ b/t/lib-httpd/apache.conf @@ -115,6 +115,7 @@ Alias /auth/dumb/ www/auth/dumb/ SetEnv GIT_EXEC_PATH ${GIT_EXEC_PATH} SetEnv GIT_HTTP_EXPORT_ALL +ScriptAliasMatch /error_git_upload_pack/(.*)/git-upload-pack error.sh/ ScriptAliasMatch /smart_*[^/]*/(.*) ${GIT_EXEC_PATH}/git-http-backend/$1 ScriptAlias /broken_smart/ broken-smart-http.sh/ ScriptAlias /error/ error.sh/ diff --git a/t/t5581-http-curl-verbose.sh b/t/t5581-http-curl-verbose.sh new file mode 100755 index 0000000000..cd9283eeec --- /dev/null +++ b/t/t5581-http-curl-verbose.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +test_description='test GIT_CURL_VERBOSE' +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-httpd.sh +start_httpd + +test_expect_success 'setup repository' ' + mkdir "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && + git -C "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" --bare init && + git config push.default matching && + echo content >file && + git add file && + git commit -m one && + git remote add public "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && + git push public master:master +' + +test_expect_success 'failure in git-upload-pack is shown' ' + test_might_fail env GIT_CURL_VERBOSE=1 \ + git clone "$HTTPD_URL/error_git_upload_pack/smart/repo.git" \ + 2>curl_log && + grep "< HTTP/1.1 500 Intentional Breakage" curl_log +' + +stop_httpd + +test_done