Skip to content

Commit 8ba18e6

Browse files
jonathantanmygitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8341178 commit 8ba18e6

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

Documentation/git.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,10 @@ of clones and fetches.
646646
variable.
647647
See `GIT_TRACE` for available trace output options.
648648

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+
649653
`GIT_REDACT_COOKIES`::
650654
This can be set to a comma-separated list of strings. When a curl trace
651655
is enabled (see `GIT_TRACE_CURL` above), whenever a "Cookies:" header

http.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "string-list.h"
1717

1818
static struct trace_key trace_curl = TRACE_KEY_INIT(CURL);
19+
static int trace_curl_data = 1;
1920
static struct string_list cookies_to_redact = STRING_LIST_INIT_DUP;
2021
#if LIBCURL_VERSION_NUM >= 0x070a08
2122
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,
695696
curl_dump_header(text, (unsigned char *)data, size, DO_FILTER);
696697
break;
697698
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+
}
700703
break;
701704
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+
}
704709
break;
705710
case CURLINFO_HEADER_IN:
706711
text = "<= Recv header";
707712
curl_dump_header(text, (unsigned char *)data, size, NO_FILTER);
708713
break;
709714
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+
}
712719
break;
713720
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+
}
716725
break;
717726

718727
default: /* we ignore unknown types by default */
@@ -857,6 +866,8 @@ static CURL *get_curl_handle(void)
857866
if (getenv("GIT_CURL_VERBOSE"))
858867
curl_easy_setopt(result, CURLOPT_VERBOSE, 1L);
859868
setup_curl_trace(result);
869+
if (getenv("GIT_TRACE_CURL_NO_DATA"))
870+
trace_curl_data = 0;
860871
if (getenv("GIT_REDACT_COOKIES")) {
861872
string_list_split(&cookies_to_redact,
862873
getenv("GIT_REDACT_COOKIES"), ',', -1);

t/t5551-http-fetch-smart.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,5 +385,17 @@ test_expect_success 'GIT_REDACT_COOKIES handles empty values' '
385385
grep "Cookie:.*Foo=<redacted>" err
386386
'
387387

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+
388400
stop_httpd
389401
test_done

0 commit comments

Comments
 (0)