11#! /bin/sh
22
3- : ${HTTP_PROTO:= HTTP}
3+ : ${HTTP_PROTO:= HTTP/ 1.1 }
44test_description=" test smart fetching over http via http-backend ($HTTP_PROTO )"
55GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
66export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
@@ -33,35 +33,71 @@ test_expect_success 'create http-accessible bare repository' '
3333setup_askpass_helper
3434
3535test_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
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
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
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
36+ if test_have_prereq HTTP2 && test "$HTTPD_PROTO" = "https"
37+ then
38+ # ALPN lets us immediately use HTTP/2; likewise, POSTs with
39+ # bodies can use it because they do not need to upgrade
40+ INITIAL_PROTO=HTTP/2
41+ else
42+ # either we are not using HTTP/2, or the initial
43+ # request is sent via HTTP/1.1 and asks for upgrade
44+ INITIAL_PROTO=HTTP/1.1
45+ fi &&
46+
47+ cat >exp.raw <<-EOF &&
48+ > GET /smart/repo.git/info/refs?service=git-upload-pack $INITIAL_PROTO
49+ > accept: */*
50+ > accept-encoding: ENCODINGS
51+ > accept-language: ko-KR, *;q=0.9
52+ > pragma: no-cache
53+ {V2} > git-protocol: version=2
54+ < $HTTP_PROTO 200 OK
55+ < pragma: no-cache
56+ < cache-control: no-cache, max-age=0, must-revalidate
57+ < content-type: application/x-git-upload-pack-advertisement
58+ > POST /smart/repo.git/git-upload-pack $INITIAL_PROTO
59+ > accept-encoding: ENCODINGS
60+ > content-type: application/x-git-upload-pack-request
61+ > accept: application/x-git-upload-pack-result
62+ > accept-language: ko-KR, *;q=0.9
63+ {V2} > git-protocol: version=2
64+ > content-length: xxx
65+ < $INITIAL_PROTO 200 OK
66+ < pragma: no-cache
67+ < cache-control: no-cache, max-age=0, must-revalidate
68+ < content-type: application/x-git-upload-pack-result
69+ {V2} > POST /smart/repo.git/git-upload-pack $INITIAL_PROTO
70+ {V2} > accept-encoding: ENCODINGS
71+ {V2} > content-type: application/x-git-upload-pack-request
72+ {V2} > accept: application/x-git-upload-pack-result
73+ {V2} > accept-language: ko-KR, *;q=0.9
74+ {V2} > git-protocol: version=2
75+ {V2} > content-length: xxx
76+ {V2} < $INITIAL_PROTO 200 OK
77+ {V2} < pragma: no-cache
78+ {V2} < cache-control: no-cache, max-age=0, must-revalidate
79+ {V2} < content-type: application/x-git-upload-pack-result
5680 EOF
5781
58- GIT_TRACE_CURL=true GIT_TEST_PROTOCOL_VERSION=0 LANGUAGE="ko_KR.UTF-8" \
82+ if test "$GIT_TEST_PROTOCOL_VERSION" = 0
83+ then
84+ sed "/^{V2}/d" <exp.raw >exp
85+ else
86+ sed "s/^{V2} //" <exp.raw >exp
87+ fi &&
88+
89+ GIT_TRACE_CURL=true LANGUAGE="ko_KR.UTF-8" \
5990 git clone --quiet $HTTPD_URL/smart/repo.git clone 2>err &&
6091 test_cmp file clone/file &&
6192 tr ' \' ' \015' \' ' Q <err |
93+ perl -pe ' \' '
94+ s/(Send|Recv) header: ([A-Za-z0-9-]+):/
95+ "$1 header: " . lc($2) . ":"
96+ /e;
97+ ' \' ' |
6298 sed -e "
6399 s/Q\$//
64- /^[*] /d
100+ /^[^<=] /d
65101 /^== Info:/d
66102 /^=> Send header, /d
67103 /^=> Send header:$/d
@@ -71,43 +107,44 @@ test_expect_success 'clone http repository' '
71107 s/= Recv header://
72108 /^<= Recv data/d
73109 /^=> Send data/d
110+ /^<= Recv SSL data/d
111+ /^=> Send SSL data/d
74112 /^$/d
75113 /^< $/d
76114
77115 /^[^><]/{
78116 s/^/> /
79117 }
80118
81- /^> User-Agent: /d
82- /^> Host: /d
119+ /^< HTTP/ {
120+ s/200$/200 OK/
121+ }
122+ /^< HTTP\\/1.1 101/d
123+ /^[><] connection: /d
124+ /^[><] upgrade: /d
125+ /^> http2-settings: /d
126+
127+ /^> user-agent: /d
128+ /^> host: /d
83129 /^> POST /,$ {
84130 /^> Accept: [*]\\/[*]/d
85131 }
86- s/^> Content-Length : .*/> Content-Length : xxx/
132+ s/^> content-length : .*/> content-length : xxx/
87133 /^> 00..want /d
88134 /^> 00.*done/d
89135
90- /^< Server : /d
91- /^< Expires : /d
92- /^< Date : /d
93- /^< Content-Length : /d
94- /^< Transfer-Encoding : /d
136+ /^< server : /d
137+ /^< expires : /d
138+ /^< date : /d
139+ /^< content-length : /d
140+ /^< transfer-encoding : /d
95141 " >actual &&
96142
97- # NEEDSWORK: If the overspecification of the expected result is reduced, we
98- # might be able to run this test in all protocol versions.
99- if test "$GIT_TEST_PROTOCOL_VERSION" = 0
100- then
101- sed -e "s/^> Accept-Encoding: .*/> Accept-Encoding: ENCODINGS/" \
102- actual >actual.smudged &&
103- test_cmp exp actual.smudged &&
104-
105- grep "Accept-Encoding:.*gzip" actual >actual.gzip &&
106- test_line_count = 2 actual.gzip &&
143+ sed -e "s/^> accept-encoding: .*/> accept-encoding: ENCODINGS/" \
144+ actual >actual.smudged &&
145+ test_cmp exp actual.smudged &&
107146
108- grep "Accept-Language: ko-KR, *" actual >actual.language &&
109- test_line_count = 2 actual.language
110- fi
147+ grep "accept-encoding:.*gzip" actual >actual.gzip
111148'
112149
113150test_expect_success ' fetch changes via http' '
@@ -119,19 +156,9 @@ test_expect_success 'fetch changes via http' '
119156'
120157
121158test_expect_success ' used upload-pack service' '
122- cat >exp <<-\EOF &&
123- GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
124- POST /smart/repo.git/git-upload-pack HTTP/1.1 200
125- GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1 200
126- POST /smart/repo.git/git-upload-pack HTTP/1.1 200
127- EOF
128-
129- # NEEDSWORK: If the overspecification of the expected result is reduced, we
130- # might be able to run this test in all protocol versions.
131- if test "$GIT_TEST_PROTOCOL_VERSION" = 0
132- then
133- check_access_log exp
134- fi
159+ strip_access_log >log &&
160+ grep "GET /smart/repo.git/info/refs?service=git-upload-pack HTTP/[0-9.]* 200" log &&
161+ grep "POST /smart/repo.git/git-upload-pack HTTP/[0-9.]* 200" log
135162'
136163
137164test_expect_success ' follow redirects (301)' '
@@ -280,21 +307,23 @@ test_expect_success 'cookies stored in http.cookiefile when http.savecookies set
280307 127.0.0.1 FALSE /smart_cookies/ FALSE 0 othername othervalue
281308 EOF
282309 sort >expect_cookies.txt <<-\EOF &&
283-
284310 127.0.0.1 FALSE /smart_cookies/ FALSE 0 othername othervalue
311+ 127.0.0.1 FALSE /smart_cookies/repo.git/ FALSE 0 name value
285312 127.0.0.1 FALSE /smart_cookies/repo.git/info/ FALSE 0 name value
286313 EOF
287314 git config http.cookiefile cookies.txt &&
288315 git config http.savecookies true &&
289- git ls-remote $HTTPD_URL/smart_cookies/repo.git main &&
290316
291- # NEEDSWORK: If the overspecification of the expected result is reduced, we
292- # might be able to run this test in all protocol versions.
293- if test "$GIT_TEST_PROTOCOL_VERSION" = 0
294- then
295- tail -3 cookies.txt | sort >cookies_tail.txt &&
296- test_cmp expect_cookies.txt cookies_tail.txt
297- fi
317+ test_when_finished "
318+ git --git-dir=\"\$HTTPD_DOCUMENT_ROOT_PATH/repo.git\" \
319+ tag -d cookie-tag
320+ " &&
321+ git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
322+ tag -m "foo" cookie-tag &&
323+ git fetch $HTTPD_URL/smart_cookies/repo.git cookie-tag &&
324+
325+ grep "^[^#]" cookies.txt | sort >cookies_stripped.txt &&
326+ test_cmp expect_cookies.txt cookies_stripped.txt
298327'
299328
300329test_expect_success ' transfer.hiderefs works over smart-http' '
@@ -666,4 +695,13 @@ test_expect_success 'push warns or fails when using username:password' '
666695 test_line_count -ge 1 warnings
667696'
668697
698+ test_expect_success ' no empty path components' '
699+ # In the URL, add a trailing slash, and see if git appends yet another
700+ # slash.
701+ git clone $HTTPD_URL/smart/repo.git/ clone-with-slash &&
702+
703+ strip_access_log >log &&
704+ ! grep "//" log
705+ '
706+
669707test_done
0 commit comments