From: Elia Pinto <gitter.spiros@gmail.com>
To: git@vger.kernel.org
Cc: tboegi@web.de, ramsay@ramsayjones.plus.com, gitster@pobox.com,
sunshine@sunshineco.com, peff@peff.net,
Elia Pinto <gitter.spiros@gmail.com>
Subject: [PATCHv5 1/2] http.c: implement the GIT_TRACE_CURL environment variable
Date: Mon, 2 May 2016 14:28:12 +0000 [thread overview]
Message-ID: <20160502142813.50868-2-gitter.spiros@gmail.com> (raw)
In-Reply-To: <20160502142813.50868-1-gitter.spiros@gmail.com>
Implement the GIT_TRACE_CURL environment variable to allow a
greater degree of detail of GIT_CURL_VERBOSE, in particular
the complete transport header and all the data payload exchanged.
It might be useful if a particular situation could require a more
thorough debugging analysis. Document the new GIT_TRACE_CURL
environment variable.
Helped-by: Torsten Bögershausen <tboegi@web.de>
Helped-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
---
Documentation/git.txt | 8 ++++
http.c | 115 +++++++++++++++++++++++++++++++++++++++++++++++++-
http.h | 4 ++
3 files changed, 125 insertions(+), 2 deletions(-)
diff --git a/Documentation/git.txt b/Documentation/git.txt
index 34ff007..5e59576 100644
--- a/Documentation/git.txt
+++ b/Documentation/git.txt
@@ -1076,6 +1076,14 @@ of clones and fetches.
cloning of shallow repositories.
See 'GIT_TRACE' for available trace output options.
+'GIT_TRACE_CURL'::
+ Enables a curl full trace dump of all incoming and outgoing data,
+ including descriptive information, of the git transport protocol.
+ This is similar to doing curl --trace-ascii on the command line.
+ This option overrides setting the GIT_CURL_VERBOSE environment
+ variable.
+ See 'GIT_TRACE' for available trace output options.
+
'GIT_LITERAL_PATHSPECS'::
Setting this variable to `1` will cause Git to treat all
pathspecs literally, rather than as glob patterns. For example,
diff --git a/http.c b/http.c
index 985b995..5e2bc19 100644
--- a/http.c
+++ b/http.c
@@ -11,6 +11,7 @@
#include "gettext.h"
#include "transport.h"
+static struct trace_key trace_curl = TRACE_KEY_INIT(CURL);
#if LIBCURL_VERSION_NUM >= 0x070a08
long int git_curl_ipresolve = CURL_IPRESOLVE_WHATEVER;
#else
@@ -478,6 +479,116 @@ static void set_curl_keepalive(CURL *c)
}
#endif
+static void curl_dump(const char *text, unsigned char *ptr, size_t size, int nopriv)
+{
+ size_t i;
+ struct strbuf out = STRBUF_INIT;
+ unsigned int width = 80;
+
+ strbuf_addf(&out, "%s, %10.10ld bytes (0x%8.8lx)\n",
+ text, (long)size, (long)size);
+ trace_strbuf(&trace_curl, &out);
+
+ for (i = 0; i < size; i += width) {
+ size_t w;
+ size_t prefix_len;
+ const char *header;
+
+ strbuf_reset(&out);
+ strbuf_addf(&out, "%s: ", text);
+ prefix_len = out.len;
+ for (w = 0; (w < width) && (i + w < size); w++) {
+ if ((i + w + 1 < size) && ptr[i + w] == '\r'
+ && ptr[i + w + 1] == '\n') {
+ i += (w + 2 - width);
+ break;
+ }
+ strbuf_addch(&out, (ptr[i + w] >= 0x20)
+ && (ptr[i + w] < 0x80) ? ptr[i + w] : '.');
+ if ((i + w + 2 < size)
+ && ptr[i + w + 1] == '\r'
+ && ptr[i + w + 2] == '\n') {
+ i += (w + 3 - width);
+ break;
+ }
+ }
+
+ /*
+ * if we are called with nopriv substitute a dummy value
+ * in the Authorization or Proxy-Authorization http header if
+ * present.
+ */
+ if (nopriv &&
+ (skip_prefix(out.buf + prefix_len, "Authorization:", &header)
+ || skip_prefix(out.buf + prefix_len, "Proxy-Authorization:", &header))) {
+ /* The first token is the type, which is OK to log */
+ while (isspace(*header))
+ header++;
+ /* Everything else is opaque and possibly sensitive */
+ strbuf_setlen(&out, header - out.buf);
+ strbuf_addstr(&out, " <redacted>");
+ }
+ strbuf_addch(&out, '\n');
+ trace_strbuf(&trace_curl, &out);
+ }
+ strbuf_release(&out);
+}
+
+void setup_curl_trace(CURL *handle)
+{
+ if (!trace_want(&trace_curl)) return;
+ curl_easy_setopt(handle, CURLOPT_VERBOSE, 1L);
+ curl_easy_setopt(handle, CURLOPT_DEBUGFUNCTION, curl_trace);
+ curl_easy_setopt(handle, CURLOPT_DEBUGDATA, NULL);
+}
+
+int curl_trace(CURL *handle, curl_infotype type, char *data, size_t size, void *userp)
+{
+ const char *text;
+ (void)handle; /* prevent compiler unused parameter warning if checked */
+ (void)userp; /* prevent compiler unused parameter warning if checked */
+ int nopriv = 0; /*
+ * default: there are no sensitive data
+ * in the trace to be skipped
+ */
+
+ switch (type) {
+ case CURLINFO_TEXT:
+ trace_printf_key(&trace_curl, "== Info: %s", data);
+ default: /* we ignore unknown types by default */
+ return 0;
+
+ case CURLINFO_HEADER_OUT:
+ text = "=> Send header";
+ nopriv = 1;
+ break;
+ case CURLINFO_DATA_OUT:
+ text = "=> Send data";
+ nopriv = 0;
+ break;
+ case CURLINFO_SSL_DATA_OUT:
+ text = "=> Send SSL data";
+ nopriv = 0;
+ break;
+ case CURLINFO_HEADER_IN:
+ text = "<= Recv header";
+ nopriv = 0;
+ break;
+ case CURLINFO_DATA_IN:
+ text = "<= Recv data";
+ nopriv = 0;
+ break;
+ case CURLINFO_SSL_DATA_IN:
+ text = "<= Recv SSL data";
+ nopriv = 0;
+ break;
+ }
+
+ curl_dump(text, (unsigned char *)data, size, nopriv);
+ return 0;
+}
+
+
static CURL *get_curl_handle(void)
{
CURL *result = curl_easy_init();
@@ -576,9 +687,9 @@ static CURL *get_curl_handle(void)
warning("protocol restrictions not applied to curl redirects because\n"
"your curl version is too old (>= 7.19.4)");
#endif
-
if (getenv("GIT_CURL_VERBOSE"))
- curl_easy_setopt(result, CURLOPT_VERBOSE, 1);
+ curl_easy_setopt(result, CURLOPT_VERBOSE, 1L);
+ setup_curl_trace(result);
curl_easy_setopt(result, CURLOPT_USERAGENT,
user_agent ? user_agent : git_user_agent());
diff --git a/http.h b/http.h
index 36f558b..cd186a4 100644
--- a/http.h
+++ b/http.h
@@ -225,4 +225,8 @@ extern int finish_http_object_request(struct http_object_request *freq);
extern void abort_http_object_request(struct http_object_request *freq);
extern void release_http_object_request(struct http_object_request *freq);
+/* Debug callback and setup routine for curl_easy_setopt CURLOPT_DEBUGFUNCTION */
+void setup_curl_trace(CURL *handle);
+int curl_trace(CURL *handle, curl_infotype type, char *data, size_t size, void *userp);
+
#endif /* HTTP_H */
--
2.8.2.435.ga07a3e0
next prev parent reply other threads:[~2016-05-02 14:28 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-02 14:28 [PATCHv5 0/2] Implement the GIT_TRACE_CURL environment variable Elia Pinto
2016-05-02 14:28 ` Elia Pinto [this message]
2016-05-02 17:03 ` [PATCHv5 1/2] http.c: implement " Ramsay Jones
2016-05-02 18:15 ` Jeff King
2016-05-02 18:59 ` Junio C Hamano
2016-05-02 19:25 ` Jeff King
2016-05-02 19:15 ` Junio C Hamano
2016-05-02 14:28 ` [PATCHv5 2/2] imap-send.c: introduce " Elia Pinto
2016-05-02 18:13 ` [PATCHv5 0/2] Implement " Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160502142813.50868-2-gitter.spiros@gmail.com \
--to=gitter.spiros@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
--cc=ramsay@ramsayjones.plus.com \
--cc=sunshine@sunshineco.com \
--cc=tboegi@web.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).