Skip to content

Commit 7a90d1e

Browse files
committed
Merge branch 'jk/redact-h2h3-headers-fix'
HTTP Header redaction code has been adjusted for a newer version of cURL library that shows its traces differently from earlier versions. * jk/redact-h2h3-headers-fix: http: update curl http/2 info matching for curl 8.3.0 http: factor out matching of curl http/2 trace lines
2 parents fb6e6e0 + 0763c3a commit 7a90d1e

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

http.c

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -738,18 +738,43 @@ static int redact_sensitive_header(struct strbuf *header, size_t offset)
738738
return ret;
739739
}
740740

741+
static int match_curl_h2_trace(const char *line, const char **out)
742+
{
743+
const char *p;
744+
745+
/*
746+
* curl prior to 8.1.0 gives us:
747+
*
748+
* h2h3 [<header-name>: <header-val>]
749+
*
750+
* Starting in 8.1.0, the first token became just "h2".
751+
*/
752+
if (skip_iprefix(line, "h2h3 [", out) ||
753+
skip_iprefix(line, "h2 [", out))
754+
return 1;
755+
756+
/*
757+
* curl 8.3.0 uses:
758+
* [HTTP/2] [<stream-id>] [<header-name>: <header-val>]
759+
* where <stream-id> is numeric.
760+
*/
761+
if (skip_iprefix(line, "[HTTP/2] [", &p)) {
762+
while (isdigit(*p))
763+
p++;
764+
if (skip_prefix(p, "] [", out))
765+
return 1;
766+
}
767+
768+
return 0;
769+
}
770+
741771
/* Redact headers in info */
742772
static void redact_sensitive_info_header(struct strbuf *header)
743773
{
744774
const char *sensitive_header;
745775

746-
/*
747-
* curl's h2h3 prints headers in info, e.g.:
748-
* h2h3 [<header-name>: <header-val>]
749-
*/
750776
if (trace_curl_redact &&
751-
(skip_iprefix(header->buf, "h2h3 [", &sensitive_header) ||
752-
skip_iprefix(header->buf, "h2 [", &sensitive_header))) {
777+
match_curl_h2_trace(header->buf, &sensitive_header)) {
753778
if (redact_sensitive_header(header, sensitive_header - header->buf)) {
754779
/* redaction ate our closing bracket */
755780
strbuf_addch(header, ']');

0 commit comments

Comments
 (0)