From patchwork Tue Jan 8 02:47:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masaya Suzuki X-Patchwork-Id: 10751327 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 B3F9117D2 for ; Tue, 8 Jan 2019 02:48:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A3DD728B18 for ; Tue, 8 Jan 2019 02:48:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9086D28B1B; Tue, 8 Jan 2019 02:48:04 +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 2E89F28B1B for ; Tue, 8 Jan 2019 02:48:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727344AbfAHCsA (ORCPT ); Mon, 7 Jan 2019 21:48:00 -0500 Received: from mail-qk1-f201.google.com ([209.85.222.201]:53471 "EHLO mail-qk1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727147AbfAHCsA (ORCPT ); Mon, 7 Jan 2019 21:48:00 -0500 Received: by mail-qk1-f201.google.com with SMTP id r145so2019733qke.20 for ; Mon, 07 Jan 2019 18:47:59 -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=VgVcVU2oULsoKrNzaUQ/l6Ygm952kaZYHyVrUObIIOM=; b=EZ16zKBup6kTUZw6KkIhcFQIRRzapPv/EoXbOlFLyiN2JhODUj2LZegpI5hLa8KYhR pFnUZ3plc9/3jO0nsjZOtH35kMBp/tV3zXadFBuA3JYDubBR1tKUR3VVFBeHxzbP5NLa GE8q+jr9WmNBTQeg8IMLix6h2HyKo0GEZP0nVYmmc1TziuX9U4EfKdtsngEd5gOFK2m7 PElOfV5/6lfY8+rmoiP7QKEfyCq3/vPh7pSzCy/ZRM74Btx9GMaVZE8sCQxp4RSYsvZM maK6THIDdm4h/ARrV/q2gFZfc7VNdctuZeS+zbtLVoPHtvxM6IMd5GOwNPDQiA86+Z6P M1kg== 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=VgVcVU2oULsoKrNzaUQ/l6Ygm952kaZYHyVrUObIIOM=; b=nvuaCZR8pkTLWi/1/gTRuDA5yJGFYIPsvA7It+WSekCYGRNz1Ia/sFYXkSQ8eOx6ND oFOlUkZPZE17uWmc7Od9HyT46tkltUTI8Mdmj8LMcD4YpL/4aAXYhy1NayjXJzy/C/uo Vg9rfrk6fbIWyzvvuP/9xKw7NqMEJ20QY1m7t2stGA4dQrk+1/i8w0WC6C3uXYFzFWzH Ki9rb4kMYJlwsiFbESkFX+XN4H1aejGwC0cVLIlcjny/hzIdPc0vrOkWxcqobITFusl3 M+sf9Al95yIa23hxVtDgOPVir2xLnjlmROxd195+p1gwGHbEf3SUpsQq4FIm934J+6hb ba0A== X-Gm-Message-State: AJcUukcNoRjtlNQTQOtd6rfmiDQMyqUIGBJkr6qQ8AcwflqHLTUUv4Ql vS3HtrJfciElkQtnyY+kG2cuypFyqggmJ6sQsN0= X-Google-Smtp-Source: ALg8bN6iUNuZzqVIGZS3NpokRW3Snmsxv2o2mrXq46hqVEbrzhYxyU2cqKB+a8ZZEKztjQAxNUS4ZooAOY9RHQ8JTmM= X-Received: by 2002:a0c:98c6:: with SMTP id g6mr2240qvd.46.1546915679313; Mon, 07 Jan 2019 18:47:59 -0800 (PST) Date: Mon, 7 Jan 2019 18:47:37 -0800 In-Reply-To: <20190108024741.62176-1-masayasuzuki@google.com> Message-Id: <20190108024741.62176-2-masayasuzuki@google.com> Mime-Version: 1.0 References: <20181229194447.157763-1-masayasuzuki@google.com> <20190108024741.62176-1-masayasuzuki@google.com> X-Mailer: git-send-email 2.20.1.97.g81188d93c3-goog Subject: [PATCH v3 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 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 | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/http.c b/http.c index 0b6807cef9..06450da96e 100644 --- a/http.c +++ b/http.c @@ -1991,16 +1991,19 @@ 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: + fflush(result); + ftruncate(fileno(result), 0); + break; default: - BUG("HTTP_KEEP_ERROR is only supported with strbufs"); + BUG("Unknown http_request target"); } } From patchwork Tue Jan 8 02:47:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masaya Suzuki X-Patchwork-Id: 10751331 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 39DB713AD for ; Tue, 8 Jan 2019 02:48:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2988C28B17 for ; Tue, 8 Jan 2019 02:48:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1E52528B1C; Tue, 8 Jan 2019 02:48:09 +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 B114828B17 for ; Tue, 8 Jan 2019 02:48:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727367AbfAHCsD (ORCPT ); Mon, 7 Jan 2019 21:48:03 -0500 Received: from mail-qk1-f201.google.com ([209.85.222.201]:37043 "EHLO mail-qk1-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727353AbfAHCsC (ORCPT ); Mon, 7 Jan 2019 21:48:02 -0500 Received: by mail-qk1-f201.google.com with SMTP id s70so2045240qks.4 for ; Mon, 07 Jan 2019 18:48:02 -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=MzGPOc6NVl+jJbFdWBR+ksAAgtvR7G3y2XdsJpRnQYY=; b=H1RqD5mm4CYT5scuHqQP24M1aWLcRV2uGFYWWw/X7HO1jUK9td+dj/mshADA2+/zFL jJHQMxuU+qRqt1K2rhNzp/ahDgKR6w+btztLSzRpKjY04eGVkRTwjA23BS9jtPdZQvDl 0h3mPJeoCBNRw4EjTTt9ABsfWxm80dqPULN79xDhhKpuNy4UZyojuY1QZNK2G4nb/v/6 AkHjgVVp8aOGVOZo6Jj2cs9MAT0baLJSJMidvmkNKigINLvrUOI0csu4KKhVUF3/ffMn FNmtM9i+8OPP/F4dwFdSwF5cHrdN7icS8d+Laqr7UwgKebiaePoWJUd/82rBZbu5VEZW E1lw== 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=MzGPOc6NVl+jJbFdWBR+ksAAgtvR7G3y2XdsJpRnQYY=; b=LIuMuap0Dltee2+lCzFaFm7oIXoFrkK5rPE0kWVVgMVEhQ8z24tiodeI/+j8SJgz8O XGbJhXYIW3jxngY6rPgK0g/nJBVTfQz1kiPAajo5Xgn6I9Fy/HPhw8FHfRUwZOqEg5zx 9kVhXphrjt63VlDC3UBoMieQLkv1xRGqVQqzfeMqRACPxR+5T1asLhx17/S6Ary9r+yd EXmhFN7Tj/1H0kiPwQ2aBsE9D6mGUtCdrTnpo23Gzx+l3PHnKzJdVFsnbHXOBiaALqXC RIr7yZSkZvHUZrZZ5yKiOwAIBTuRKrK9K9Pla9kolxYbcirxblAtp+oKUNooWbIieJed td0A== X-Gm-Message-State: AA+aEWbQStrZiHYutdBNrfhKAnr5PYJAyPsMORfceGKO1INicyc8Y0w6 5BWapM9vk5MIY4mACTSFkzocfhQKNN70i9Y2tQI= X-Google-Smtp-Source: AFSGD/U/wXFjAbbDVvj5POlC07CUwjfhZvw18NQgR+AjQ3V4ugf+mNURBexb6g/5c4tJsZYjpcGkHzzlBA6WvL1bn4Y= X-Received: by 2002:ac8:4307:: with SMTP id z7mr46012772qtm.7.1546915681719; Mon, 07 Jan 2019 18:48:01 -0800 (PST) Date: Mon, 7 Jan 2019 18:47:38 -0800 In-Reply-To: <20190108024741.62176-1-masayasuzuki@google.com> Message-Id: <20190108024741.62176-3-masayasuzuki@google.com> Mime-Version: 1.0 References: <20181229194447.157763-1-masayasuzuki@google.com> <20190108024741.62176-1-masayasuzuki@google.com> X-Mailer: git-send-email 2.20.1.97.g81188d93c3-goog Subject: [PATCH v3 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 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 | 30 +++++++++++++----------------- http.h | 1 - remote-curl.c | 1 - 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/http.c b/http.c index 06450da96e..a72db87723 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,22 +1988,19 @@ 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: - fflush(result); - ftruncate(fileno(result), 0); - break; - default: - BUG("Unknown http_request target"); - } + switch (target) { + case HTTP_REQUEST_STRBUF: + strbuf_reset(result); + break; + case HTTP_REQUEST_FILE: + fflush(result); + ftruncate(fileno(result), 0); + 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 Tue Jan 8 02:47:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masaya Suzuki X-Patchwork-Id: 10751333 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 4AF9B17D2 for ; Tue, 8 Jan 2019 02:48:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3B51528B18 for ; Tue, 8 Jan 2019 02:48:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2FF6F28B1D; Tue, 8 Jan 2019 02:48:09 +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 D2C1428B18 for ; Tue, 8 Jan 2019 02:48:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727382AbfAHCsF (ORCPT ); Mon, 7 Jan 2019 21:48:05 -0500 Received: from mail-qt1-f202.google.com ([209.85.160.202]:52675 "EHLO mail-qt1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727353AbfAHCsF (ORCPT ); Mon, 7 Jan 2019 21:48:05 -0500 Received: by mail-qt1-f202.google.com with SMTP id w15so2178754qtk.19 for ; Mon, 07 Jan 2019 18:48:04 -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=OUkn6wwP1HP2QEKZCQYFKkMCuLmHMrztlh8wS1V+ylpCvEzf5ptpxJNgleBGW/XAoi SElzRHnIhan4ovVjaAg2D0Do5Mqu6e2G/zlh1cSY5MThDwsTcewRmeWYwgjizz9wB97B zGQf5lJrsRjvZXV43ps0k6HXkIvZLWWLAFryMQFYoEqlgkqJslf17X6DIxb25ZkDc2w+ O+G2OV6pC85jKYMhXwJ4VFdj8KU4zeeATr+UpZSQdJquozBRWvy49zy4vun6x/7bucgy /Z5BQU9XNIcFnljJYvv7V58kIsdzipycsNwCmia1fb9YoFZSVEZutA+WpPffk6e577Ei ArnQ== 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=e+WtBj731NwvHciN39VTTrZruRew2V2HQmqq1iYUIxcAanytVuzSdZOtNvwCUXUuSO y9xVDqNZHZUSF6UmxZgmIH/4hqzxNK+qyW2Qt7YejVUbRNp35Fltl2+r0B3yQyCGA2Ny T5+Jf5Sf6r7m3RotqCPpRgIkNZx/WFY0EAFyojhhvVxC5iZaEfvRnM0h1yxllAdM5Lqj 3oBzY6lBkJa1lF49b76E4jN9w3Ihxs6moEElwk0Ez+zudSsouu2ke4a4cCTGbxY4zZe/ vKJgQgoizSSu9s4FTbchJzvSNZt3tBvXjVmt9ZkyX8w3m1S/0jKBOxTibCZTD3G077DG frfg== X-Gm-Message-State: AJcUukfQakjlRb4xO/D0xTvM9eLrAi6vrLP31w9e+hJ8D+7MjLPLZm06 eBf8CXayxBbic2VrO13sfWVYdG/q9DgXu93pp3Q= X-Google-Smtp-Source: ALg8bN57XtVG5wwPDJS5eOHADnmTAxqqWVOWh48/0fFE7zwTSSJJPpQ1wltCdUlQIsaSe7DlfPJJTol4mrGlT8ximoU= X-Received: by 2002:a37:d4d4:: with SMTP id s81mr3925qks.34.1546915684031; Mon, 07 Jan 2019 18:48:04 -0800 (PST) Date: Mon, 7 Jan 2019 18:47:39 -0800 In-Reply-To: <20190108024741.62176-1-masayasuzuki@google.com> Message-Id: <20190108024741.62176-4-masayasuzuki@google.com> Mime-Version: 1.0 References: <20181229194447.157763-1-masayasuzuki@google.com> <20190108024741.62176-1-masayasuzuki@google.com> X-Mailer: git-send-email 2.20.1.97.g81188d93c3-goog Subject: [PATCH v3 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 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 Tue Jan 8 02:47:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masaya Suzuki X-Patchwork-Id: 10751335 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 AA7D413AD for ; Tue, 8 Jan 2019 02:48:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B86928B18 for ; Tue, 8 Jan 2019 02:48:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8FA2928B36; Tue, 8 Jan 2019 02:48:11 +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 410D328B18 for ; Tue, 8 Jan 2019 02:48:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727424AbfAHCsI (ORCPT ); Mon, 7 Jan 2019 21:48:08 -0500 Received: from mail-qk1-f202.google.com ([209.85.222.202]:43546 "EHLO mail-qk1-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727353AbfAHCsH (ORCPT ); Mon, 7 Jan 2019 21:48:07 -0500 Received: by mail-qk1-f202.google.com with SMTP id z126so2020720qka.10 for ; Mon, 07 Jan 2019 18:48:07 -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=TwKPJSNqxFaeuEh37lvd+S234eyb7DLS7lDelG7ILE/cPZETlwhy+XdAAc+1xZWGN0 K59ATS9nvTMNfEqp1zl7RA7cV32VWUc4OyU1soA0F6lhMspbRoqFWAqXY8xx/r7wdGUm +rA9Aju9DQ36Y3n1pINKyDgHStB98uNW4qT2S+8UGFhosij5r2w5DbygTquetZ7kAqaL gylgj326N+6QOzJrrCi9TFpiaiibDYIbAuh13XYOjsf+XTX1BR8FbEwIz1DqTCcmPpv4 xHcsxXRRBPat/WiSi6WYdsfNTiuK1fq44VLXiuBnhx+V8lqlJGGmi5OZTDYxmlHzCqtY XVuQ== 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=md06kb3sdn2JTMx3VtJ1BBc9X6qrEENs/4VGhViAYAcPIgnzmD9Z98nJYkRNu3Q/kD Y8uqcxTh/VbMwve09H/CartNLJNWwj0FyhrQLdjUkzy0A6LO37byzJgcXhddaKtiSLw1 hCLaTYBXhuacRDyk8oMJpqeHiXgJvrIzOtbLcBqtgApIZbWtEAThLamTrqfK3lN9JYDG 3OA+4zPCFqnZ2mKPygYKMVaVjUa119EVOXbzeyGS9lz1WA7tFvAMCvMIP1vrJ0A1NtBz sSgcnJLosdwCH+sONGbA1TsYjm2bd5jsPTQqsS9IW0/Wayx1TyoS8Z+e7Vbo6BhQd+V6 qOng== X-Gm-Message-State: AJcUukd6pVvRDu10nImniDiJk9zI98mNmkl0n+emffFIIpgR38PyDKsG C5DqWbDKMKwcjGaJ5mQkYH3P4h96HleJVX3NHEs= X-Google-Smtp-Source: ALg8bN7xOweOBngINfY2qPa3v+DhyYIaMjgiyJpvapsC8Hs8lr1rgIXByg0ZHCpx+wpVGZEk5SDvgBM7SLVQNaptH5o= X-Received: by 2002:a0c:b650:: with SMTP id q16mr7167qvf.22.1546915686750; Mon, 07 Jan 2019 18:48:06 -0800 (PST) Date: Mon, 7 Jan 2019 18:47:40 -0800 In-Reply-To: <20190108024741.62176-1-masayasuzuki@google.com> Message-Id: <20190108024741.62176-5-masayasuzuki@google.com> Mime-Version: 1.0 References: <20181229194447.157763-1-masayasuzuki@google.com> <20190108024741.62176-1-masayasuzuki@google.com> X-Mailer: git-send-email 2.20.1.97.g81188d93c3-goog Subject: [PATCH v3 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 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 Tue Jan 8 02:47:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masaya Suzuki X-Patchwork-Id: 10751337 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 46ED613AD for ; Tue, 8 Jan 2019 02:48:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 37CEE28B17 for ; Tue, 8 Jan 2019 02:48:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 29E6728B1B; Tue, 8 Jan 2019 02:48:14 +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 BF41428B17 for ; Tue, 8 Jan 2019 02:48:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727434AbfAHCsL (ORCPT ); Mon, 7 Jan 2019 21:48:11 -0500 Received: from mail-io1-f73.google.com ([209.85.166.73]:52305 "EHLO mail-io1-f73.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727353AbfAHCsK (ORCPT ); Mon, 7 Jan 2019 21:48:10 -0500 Received: by mail-io1-f73.google.com with SMTP id h7so2083399iof.19 for ; Mon, 07 Jan 2019 18:48:09 -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=MQ0Sc6UDgquTWHFFlvwIwuNUdq6wFyQzRm+RKdBoLV6C/X0G18tYJtM51OHX8eRhBh 2kadcZZo+/Mc5GiEhQOuTubXbyFVWzJ+qfW75pgcscZj/wWZZyMZHnWmSUG/bE4+nF0R KDrKwDqOoxekDFDTdawoFVvOjh/t2gyO/n9dghN4dDiQt/aVs3dF6RXziOd3OM5JGhtq /FaF/fbv/EE13LpJn/g/HTh+NVbUK5b1eJy67ygparbe4QhHT/TA2vIoUgqZtb3b51PX T1ltLHWXnEVlmV0GEBiH/s/QkUTPM2xou/4PmBajjlyYj3qjcXsV1CFPfGYe3LUdO+BT XlYg== 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=hlk2+UabjFSfBSia1pApGlmM7HMvZ1N3EvikPc+PIqU899MC5Zb0ZwPv69Lf/In6hZ d6aHKO8j/AZd4KsLoi4tp7BbrNRRqZ4ejLwcG7wYvwLxBzCgvA6snosHdSlsXuXhWGzc Y0SuNutT8IDaWonMKrh7zBNdbQIi2pK/Z3vxGSnVkB9bSTEnJ8sotQGiN9VJvLc9VZy4 I3rSa5O+UiV2Z26gCzQdB6JrR3es8O4UGRJTRqhW20dzEqgo3XijzLlJrkH9xWR15Obf M5y1fZL0qKoWjQEekV9vdEU8q3R/lmDdxeqrFYoRLs/hz/WKlQLfAd4NFaDSr2qkYKUT ucOQ== X-Gm-Message-State: AJcUukc9VVY/gR/N3lSNwkoOgl3MLXUkPgzamkV/l5guHHLzpEh10L1Q GzIn5k9Q5HrN9ug2M3T9CSp5vnVzdPRFNFrSaRM= X-Google-Smtp-Source: ALg8bN5ihh0icCIza9Nt7rD0YkWd/XZKwZvjAx0l/TZK7kCPK3w+ZmwjJ1waOz+CqF54YzyVtZA1Ol79nFmrFShMnPI= X-Received: by 2002:a24:15:: with SMTP id 21mr213312ita.27.1546915689151; Mon, 07 Jan 2019 18:48:09 -0800 (PST) Date: Mon, 7 Jan 2019 18:47:41 -0800 In-Reply-To: <20190108024741.62176-1-masayasuzuki@google.com> Message-Id: <20190108024741.62176-6-masayasuzuki@google.com> Mime-Version: 1.0 References: <20181229194447.157763-1-masayasuzuki@google.com> <20190108024741.62176-1-masayasuzuki@google.com> X-Mailer: git-send-email 2.20.1.97.g81188d93c3-goog Subject: [PATCH v3 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 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