Skip to content

Commit 39fa527

Browse files
peffgitster
authored andcommitted
http: factor out matching of curl http/2 trace lines
We have to parse out curl's http/2 trace lines so we can redact their headers. We already match two different types of lines from various vintages of curl. In preparation for adding another (which will be slightly more complex), let's pull the matching into its own function, rather than doing it in the middle of a conditional. While we're doing so, let's expand the comment a bit to describe the two matches. That probably should have been part of db30130 (http: handle both "h2" and "h2h3" in curl info lines, 2023-06-17), but will become even more important as we add new types. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent db30130 commit 39fa527

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

http.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -620,18 +620,29 @@ static int redact_sensitive_header(struct strbuf *header, size_t offset)
620620
return ret;
621621
}
622622

623+
static int match_curl_h2_trace(const char *line, const char **out)
624+
{
625+
/*
626+
* curl prior to 8.1.0 gives us:
627+
*
628+
* h2h3 [<header-name>: <header-val>]
629+
*
630+
* Starting in 8.1.0, the first token became just "h2".
631+
*/
632+
if (skip_iprefix(line, "h2h3 [", out) ||
633+
skip_iprefix(line, "h2 [", out))
634+
return 1;
635+
636+
return 0;
637+
}
638+
623639
/* Redact headers in info */
624640
static void redact_sensitive_info_header(struct strbuf *header)
625641
{
626642
const char *sensitive_header;
627643

628-
/*
629-
* curl's h2h3 prints headers in info, e.g.:
630-
* h2h3 [<header-name>: <header-val>]
631-
*/
632644
if (trace_curl_redact &&
633-
(skip_iprefix(header->buf, "h2h3 [", &sensitive_header) ||
634-
skip_iprefix(header->buf, "h2 [", &sensitive_header))) {
645+
match_curl_h2_trace(header->buf, &sensitive_header)) {
635646
if (redact_sensitive_header(header, sensitive_header - header->buf)) {
636647
/* redaction ate our closing bracket */
637648
strbuf_addch(header, ']');

0 commit comments

Comments
 (0)