http: support omitting data from traces
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>
Jonathan Tan committed
Jan 18, 2018 at 16:28 UTC
8ba18e6fa402666fe94a285cd27addd9b0df6462
3 files changed
+35
-8
Documentation/git.txt
+4
@@ -646,6 +646,10 @@ of clones and fetches.
646
variable.
647
See `GIT_TRACE` for available trace output options.
648
649
+`GIT_TRACE_CURL_NO_DATA`::
650
+ When a curl trace is enabled (see `GIT_TRACE_CURL` above), do not dump
651
+ data (that is, only dump info lines and headers).
652
+
653
`GIT_REDACT_COOKIES`::
654
This can be set to a comma-separated list of strings. When a curl trace
655
is enabled (see `GIT_TRACE_CURL` above), whenever a "Cookies:" header
http.c
+19
-8
@@ -16,6 +16,7 @@
16
#include "string-list.h"
17
18
static struct trace_key trace_curl = TRACE_KEY_INIT(CURL);
19
+static int trace_curl_data = 1;
20
static struct string_list cookies_to_redact = STRING_LIST_INIT_DUP;
21
#if LIBCURL_VERSION_NUM >= 0x070a08
22
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,
696
curl_dump_header(text, (unsigned char *)data, size, DO_FILTER);
697
break;
698
case CURLINFO_DATA_OUT:
698
- text = "=> Send data";
699
- curl_dump_data(text, (unsigned char *)data, size);
699
+ if (trace_curl_data) {
700
+ text = "=> Send data";
701
+ curl_dump_data(text, (unsigned char *)data, size);
702
+ }
703
break;
704
case CURLINFO_SSL_DATA_OUT:
702
- text = "=> Send SSL data";
703
- curl_dump_data(text, (unsigned char *)data, size);
705
+ if (trace_curl_data) {
706
+ text = "=> Send SSL data";
707
+ curl_dump_data(text, (unsigned char *)data, size);
708
+ }
709
break;
710
case CURLINFO_HEADER_IN:
711
text = "<= Recv header";
712
curl_dump_header(text, (unsigned char *)data, size, NO_FILTER);
713
break;
714
case CURLINFO_DATA_IN:
710
- text = "<= Recv data";
711
- curl_dump_data(text, (unsigned char *)data, size);
715
+ if (trace_curl_data) {
716
+ text = "<= Recv data";
717
+ curl_dump_data(text, (unsigned char *)data, size);
718
+ }
719
break;
720
case CURLINFO_SSL_DATA_IN:
714
- text = "<= Recv SSL data";
715
- curl_dump_data(text, (unsigned char *)data, size);
721
+ if (trace_curl_data) {
722
+ text = "<= Recv SSL data";
723
+ curl_dump_data(text, (unsigned char *)data, size);
724
+ }
725
break;
726
727
default: /* we ignore unknown types by default */
@@ -857,6 +866,8 @@ static CURL *get_curl_handle(void)
866
if (getenv("GIT_CURL_VERBOSE"))
867
curl_easy_setopt(result, CURLOPT_VERBOSE, 1L);
868
setup_curl_trace(result);
869
+ if (getenv("GIT_TRACE_CURL_NO_DATA"))
870
+ trace_curl_data = 0;
871
if (getenv("GIT_REDACT_COOKIES")) {
872
string_list_split(&cookies_to_redact,
873
getenv("GIT_REDACT_COOKIES"), ',', -1);
t/t5551-http-fetch-smart.sh
+12
@@ -385,5 +385,17 @@ test_expect_success 'GIT_REDACT_COOKIES handles empty values' '
385
grep "Cookie:.*Foo=<redacted>" err
386
'
387
388
+test_expect_success 'GIT_TRACE_CURL_NO_DATA prevents data from being traced' '
389
+ rm -rf clone &&
390
+ GIT_TRACE_CURL=true \
391
+ git clone $HTTPD_URL/smart/repo.git clone 2>err &&
392
+ grep "=> Send data" err &&
393
+
394
+ rm -rf clone &&
395
+ GIT_TRACE_CURL=true GIT_TRACE_CURL_NO_DATA=1 \
396
+ git clone $HTTPD_URL/smart/repo.git clone 2>err &&
397
+ ! grep "=> Send data" err
398
+'
399
+
400
stop_httpd
401
test_done