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>
This commit is contained in:
Jeff King
2023-02-23 05:54:02 -05:00
committed by Junio C Hamano
parent a58f4d6328
commit 4a21230ab0

View File

@ -35,30 +35,35 @@ setup_askpass_helper
test_expect_success 'clone http repository' ' test_expect_success 'clone http repository' '
cat >exp <<-\EOF && cat >exp <<-\EOF &&
> GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 > GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1
> Accept: */* > accept: */*
> Accept-Encoding: ENCODINGS > accept-encoding: ENCODINGS
> Accept-Language: ko-KR, *;q=0.9 > accept-language: ko-KR, *;q=0.9
> Pragma: no-cache > pragma: no-cache
< HTTP/1.1 200 OK < HTTP/1.1 200 OK
< Pragma: no-cache < pragma: no-cache
< Cache-Control: no-cache, max-age=0, must-revalidate < cache-control: no-cache, max-age=0, must-revalidate
< Content-Type: application/x-git-upload-pack-advertisement < content-type: application/x-git-upload-pack-advertisement
> POST /smart/repo.git/git-upload-pack HTTP/1.1 > POST /smart/repo.git/git-upload-pack HTTP/1.1
> Accept-Encoding: ENCODINGS > accept-encoding: ENCODINGS
> Content-Type: application/x-git-upload-pack-request > content-type: application/x-git-upload-pack-request
> Accept: application/x-git-upload-pack-result > accept: application/x-git-upload-pack-result
> Accept-Language: ko-KR, *;q=0.9 > accept-language: ko-KR, *;q=0.9
> Content-Length: xxx > content-length: xxx
< HTTP/1.1 200 OK < HTTP/1.1 200 OK
< Pragma: no-cache < pragma: no-cache
< Cache-Control: no-cache, max-age=0, must-revalidate < cache-control: no-cache, max-age=0, must-revalidate
< Content-Type: application/x-git-upload-pack-result < content-type: application/x-git-upload-pack-result
EOF EOF
GIT_TRACE_CURL=true GIT_TEST_PROTOCOL_VERSION=0 LANGUAGE="ko_KR.UTF-8" \ GIT_TRACE_CURL=true GIT_TEST_PROTOCOL_VERSION=0 LANGUAGE="ko_KR.UTF-8" \
git clone --quiet $HTTPD_URL/smart/repo.git clone 2>err && git clone --quiet $HTTPD_URL/smart/repo.git clone 2>err &&
test_cmp file clone/file && test_cmp file clone/file &&
tr '\''\015'\'' Q <err | tr '\''\015'\'' Q <err |
perl -pe '\''
s/(Send|Recv) header: ([A-Za-z0-9-]+):/
"$1 header: " . lc($2) . ":"
/e;
'\'' |
sed -e " sed -e "
s/Q\$// s/Q\$//
/^[*] /d /^[*] /d
@ -78,31 +83,31 @@ test_expect_success 'clone http repository' '
s/^/> / s/^/> /
} }
/^> User-Agent: /d /^> user-agent: /d
/^> Host: /d /^> host: /d
/^> POST /,$ { /^> POST /,$ {
/^> Accept: [*]\\/[*]/d /^> Accept: [*]\\/[*]/d
} }
s/^> Content-Length: .*/> Content-Length: xxx/ s/^> content-length: .*/> content-length: xxx/
/^> 00..want /d /^> 00..want /d
/^> 00.*done/d /^> 00.*done/d
/^< Server: /d /^< server: /d
/^< Expires: /d /^< expires: /d
/^< Date: /d /^< date: /d
/^< Content-Length: /d /^< content-length: /d
/^< Transfer-Encoding: /d /^< transfer-encoding: /d
" >actual && " >actual &&
# NEEDSWORK: If the overspecification of the expected result is reduced, we # NEEDSWORK: If the overspecification of the expected result is reduced, we
# might be able to run this test in all protocol versions. # might be able to run this test in all protocol versions.
if test "$GIT_TEST_PROTOCOL_VERSION" = 0 if test "$GIT_TEST_PROTOCOL_VERSION" = 0
then then
sed -e "s/^> Accept-Encoding: .*/> Accept-Encoding: ENCODINGS/" \ sed -e "s/^> accept-encoding: .*/> accept-encoding: ENCODINGS/" \
actual >actual.smudged && actual >actual.smudged &&
test_cmp exp actual.smudged && test_cmp exp actual.smudged &&
grep "Accept-Encoding:.*gzip" actual >actual.gzip && grep "accept-encoding:.*gzip" actual >actual.gzip &&
test_line_count = 2 actual.gzip test_line_count = 2 actual.gzip
fi fi
' '