http: support omitting data from traces
authorJonathan Tan <jonathantanmy@google.com>
Fri, 19 Jan 2018 00:28:02 +0000 (16:28 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 19 Jan 2018 21:06:57 +0000 (13:06 -0800)
GIT_TRACE_CURL provides a way to debug what is being sent and received
over HTTP, with automatic redaction of sensitive information. But it
also logs data transmissions, which significantly increases the log file
size, sometimes unnecessarily. Add an option "GIT_TRACE_CURL_NO_DATA" to
allow the user to omit such data transmissions.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git.txt
http.c
t/t5551-http-fetch-smart.sh
index 5446d2143857037bc376673e05a56a1f98ea5eb9..8163b5796b192ee5f5c0cb13fc85bdeff8202e64 100644 (file)
@@ -646,6 +646,10 @@ of clones and fetches.
        variable.
        See `GIT_TRACE` for available trace output options.
 
+`GIT_TRACE_CURL_NO_DATA`::
+       When a curl trace is enabled (see `GIT_TRACE_CURL` above), do not dump
+       data (that is, only dump info lines and headers).
+
 `GIT_REDACT_COOKIES`::
        This can be set to a comma-separated list of strings. When a curl trace
        is enabled (see `GIT_TRACE_CURL` above), whenever a "Cookies:" header
diff --git a/http.c b/http.c
index 088cf70bf039d57adf5c9179238b6e4d138a51cb..32a8238955a42a9f6fd86d7cd71d09129ab454a4 100644 (file)
--- a/http.c
+++ b/http.c
@@ -16,6 +16,7 @@
 #include "string-list.h"
 
 static struct trace_key trace_curl = TRACE_KEY_INIT(CURL);
+static int trace_curl_data = 1;
 static struct string_list cookies_to_redact = STRING_LIST_INIT_DUP;
 #if LIBCURL_VERSION_NUM >= 0x070a08
 long int git_curl_ipresolve = CURL_IPRESOLVE_WHATEVER;
@@ -695,24 +696,32 @@ static int curl_trace(CURL *handle, curl_infotype type, char *data, size_t size,
                curl_dump_header(text, (unsigned char *)data, size, DO_FILTER);
                break;
        case CURLINFO_DATA_OUT:
-               text = "=> Send data";
-               curl_dump_data(text, (unsigned char *)data, size);
+               if (trace_curl_data) {
+                       text = "=> Send data";
+                       curl_dump_data(text, (unsigned char *)data, size);
+               }
                break;
        case CURLINFO_SSL_DATA_OUT:
-               text = "=> Send SSL data";
-               curl_dump_data(text, (unsigned char *)data, size);
+               if (trace_curl_data) {
+                       text = "=> Send SSL data";
+                       curl_dump_data(text, (unsigned char *)data, size);
+               }
                break;
        case CURLINFO_HEADER_IN:
                text = "<= Recv header";
                curl_dump_header(text, (unsigned char *)data, size, NO_FILTER);
                break;
        case CURLINFO_DATA_IN:
-               text = "<= Recv data";
-               curl_dump_data(text, (unsigned char *)data, size);
+               if (trace_curl_data) {
+                       text = "<= Recv data";
+                       curl_dump_data(text, (unsigned char *)data, size);
+               }
                break;
        case CURLINFO_SSL_DATA_IN:
-               text = "<= Recv SSL data";
-               curl_dump_data(text, (unsigned char *)data, size);
+               if (trace_curl_data) {
+                       text = "<= Recv SSL data";
+                       curl_dump_data(text, (unsigned char *)data, size);
+               }
                break;
 
        default:                /* we ignore unknown types by default */
@@ -857,6 +866,8 @@ static CURL *get_curl_handle(void)
        if (getenv("GIT_CURL_VERBOSE"))
                curl_easy_setopt(result, CURLOPT_VERBOSE, 1L);
        setup_curl_trace(result);
+       if (getenv("GIT_TRACE_CURL_NO_DATA"))
+               trace_curl_data = 0;
        if (getenv("GIT_REDACT_COOKIES")) {
                string_list_split(&cookies_to_redact,
                                  getenv("GIT_REDACT_COOKIES"), ',', -1);
index 21a5ce8601738752fa9a601ff922a0dd033bcfbf..f5721b4a59ea4a3333cc0e74d8ab9ad2f182dd5b 100755 (executable)
@@ -385,5 +385,17 @@ test_expect_success 'GIT_REDACT_COOKIES handles empty values' '
        grep "Cookie:.*Foo=<redacted>" err
 '
 
+test_expect_success 'GIT_TRACE_CURL_NO_DATA prevents data from being traced' '
+       rm -rf clone &&
+       GIT_TRACE_CURL=true \
+               git clone $HTTPD_URL/smart/repo.git clone 2>err &&
+       grep "=> Send data" err &&
+
+       rm -rf clone &&
+       GIT_TRACE_CURL=true GIT_TRACE_CURL_NO_DATA=1 \
+               git clone $HTTPD_URL/smart/repo.git clone 2>err &&
+       ! grep "=> Send data" err
+'
+
 stop_httpd
 test_done