t5551: lower-case headers in expected curl trace

There's a test in t5551 which checks the curl trace (after simplifying it a bit). It doesn't work with HTTP/2, because in that case curl outputs all of the headers in lower-case. Even though this test is run with HTTP/2 by t5559, nobody has noticed because checking the trace only happens if GIT_TEST_PROTOCOL_VERSION is manually set to "0". Let's fix this by lower-casing all of the header names in the trace, and then checking for those in our expected code (this is easier than making HTTP/2 traces look like HTTP/1.1, since HTTP/1.1 uses title-casing). Sadly, we can't quite do this in our existing sed script. This works if you have GNU sed: s/^\\([><]\\) \\([A-Za-z0-9-]*:\\)/\1 \L\2\E/ but \L is a GNU-ism, and I don't think there's a portable solution. We could just "tr A-Z a-z" on the way in, of course, but that makes the non-header parts harder to read (e.g., lowercase "post" requests). But to paraphrase Baron Munchausen, I have learned from experience that a modicum of Perl can be most efficacious. Note that this doesn't quite get the test passing with t5559; there are more fixes needed on top. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Feb 23, 2023 at 05:54 UTC 4a21230ab0d8b6aac4b00e9f948a34d377d2a6af
1 file changed +30 -25
t/t5551-http-fetch-smart.sh
+30 -25
@@ -35,30 +35,35 @@ setup_askpass_helper
35 test_expect_success 'clone http repository' '
36 cat >exp <<-\EOF &&
37 > GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1
38 - > Accept: */*
39 - > Accept-Encoding: ENCODINGS
40 - > Accept-Language: ko-KR, *;q=0.9
41 - > Pragma: no-cache
38 + > accept: */*
39 + > accept-encoding: ENCODINGS
40 + > accept-language: ko-KR, *;q=0.9
41 + > pragma: no-cache
42 < HTTP/1.1 200 OK
43 - < Pragma: no-cache
44 - < Cache-Control: no-cache, max-age=0, must-revalidate
45 - < Content-Type: application/x-git-upload-pack-advertisement
43 + < pragma: no-cache
44 + < cache-control: no-cache, max-age=0, must-revalidate
45 + < content-type: application/x-git-upload-pack-advertisement
46 > POST /smart/repo.git/git-upload-pack HTTP/1.1
47 - > Accept-Encoding: ENCODINGS
48 - > Content-Type: application/x-git-upload-pack-request
49 - > Accept: application/x-git-upload-pack-result
50 - > Accept-Language: ko-KR, *;q=0.9
51 - > Content-Length: xxx
47 + > accept-encoding: ENCODINGS
48 + > content-type: application/x-git-upload-pack-request
49 + > accept: application/x-git-upload-pack-result
50 + > accept-language: ko-KR, *;q=0.9
51 + > content-length: xxx
52 < HTTP/1.1 200 OK
53 - < Pragma: no-cache
54 - < Cache-Control: no-cache, max-age=0, must-revalidate
55 - < Content-Type: application/x-git-upload-pack-result
53 + < pragma: no-cache
54 + < cache-control: no-cache, max-age=0, must-revalidate
55 + < content-type: application/x-git-upload-pack-result
56 EOF
57
58 GIT_TRACE_CURL=true GIT_TEST_PROTOCOL_VERSION=0 LANGUAGE="ko_KR.UTF-8" \
59 git clone --quiet $HTTPD_URL/smart/repo.git clone 2>err &&
60 test_cmp file clone/file &&
61 tr '\''\015'\'' Q <err |
62 + perl -pe '\''
63 + s/(Send|Recv) header: ([A-Za-z0-9-]+):/
64 + "$1 header: " . lc($2) . ":"
65 + /e;
66 + '\'' |
67 sed -e "
68 s/Q\$//
69 /^[*] /d
@@ -78,31 +83,31 @@ test_expect_success 'clone http repository' '
83 s/^/> /
84 }
85
81 - /^> User-Agent: /d
82 - /^> Host: /d
86 + /^> user-agent: /d
87 + /^> host: /d
88 /^> POST /,$ {
89 /^> Accept: [*]\\/[*]/d
90 }
86 - s/^> Content-Length: .*/> Content-Length: xxx/
91 + s/^> content-length: .*/> content-length: xxx/
92 /^> 00..want /d
93 /^> 00.*done/d
94
90 - /^< Server: /d
91 - /^< Expires: /d
92 - /^< Date: /d
93 - /^< Content-Length: /d
94 - /^< Transfer-Encoding: /d
95 + /^< server: /d
96 + /^< expires: /d
97 + /^< date: /d
98 + /^< content-length: /d
99 + /^< transfer-encoding: /d
100 " >actual &&
101
102 # NEEDSWORK: If the overspecification of the expected result is reduced, we
103 # might be able to run this test in all protocol versions.
104 if test "$GIT_TEST_PROTOCOL_VERSION" = 0
105 then
101 - sed -e "s/^> Accept-Encoding: .*/> Accept-Encoding: ENCODINGS/" \
106 + sed -e "s/^> accept-encoding: .*/> accept-encoding: ENCODINGS/" \
107 actual >actual.smudged &&
108 test_cmp exp actual.smudged &&
109
105 - grep "Accept-Encoding:.*gzip" actual >actual.gzip &&
110 + grep "accept-encoding:.*gzip" actual >actual.gzip &&
111 test_line_count = 2 actual.gzip
112 fi
113 '