Skip to content

Commit 4a21230

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a58f4d6 commit 4a21230

File tree

1 file changed

+30
-25
lines changed

1 file changed

+30
-25
lines changed

t/t5551-http-fetch-smart.sh

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -35,30 +35,35 @@ setup_askpass_helper
3535
test_expect_success 'clone http repository' '
3636
cat >exp <<-\EOF &&
3737
> 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
4242
< 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
4646
> 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
5252
< 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
5656
EOF
5757
5858
GIT_TRACE_CURL=true GIT_TEST_PROTOCOL_VERSION=0 LANGUAGE="ko_KR.UTF-8" \
5959
git clone --quiet $HTTPD_URL/smart/repo.git clone 2>err &&
6060
test_cmp file clone/file &&
6161
tr '\''\015'\'' Q <err |
62+
perl -pe '\''
63+
s/(Send|Recv) header: ([A-Za-z0-9-]+):/
64+
"$1 header: " . lc($2) . ":"
65+
/e;
66+
'\'' |
6267
sed -e "
6368
s/Q\$//
6469
/^[*] /d
@@ -78,31 +83,31 @@ test_expect_success 'clone http repository' '
7883
s/^/> /
7984
}
8085
81-
/^> User-Agent: /d
82-
/^> Host: /d
86+
/^> user-agent: /d
87+
/^> host: /d
8388
/^> POST /,$ {
8489
/^> Accept: [*]\\/[*]/d
8590
}
86-
s/^> Content-Length: .*/> Content-Length: xxx/
91+
s/^> content-length: .*/> content-length: xxx/
8792
/^> 00..want /d
8893
/^> 00.*done/d
8994
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
95100
" >actual &&
96101
97102
# NEEDSWORK: If the overspecification of the expected result is reduced, we
98103
# might be able to run this test in all protocol versions.
99104
if test "$GIT_TEST_PROTOCOL_VERSION" = 0
100105
then
101-
sed -e "s/^> Accept-Encoding: .*/> Accept-Encoding: ENCODINGS/" \
106+
sed -e "s/^> accept-encoding: .*/> accept-encoding: ENCODINGS/" \
102107
actual >actual.smudged &&
103108
test_cmp exp actual.smudged &&
104109
105-
grep "Accept-Encoding:.*gzip" actual >actual.gzip &&
110+
grep "accept-encoding:.*gzip" actual >actual.gzip &&
106111
test_line_count = 2 actual.gzip
107112
fi
108113
'

0 commit comments

Comments
 (0)