Skip to content

Commit 8ba55d1

Browse files
committed
test: Fix status code test to pass under HTTP/2
The protocol part already checked for it, but the status code was still asserted with the HTTP1-specific textual description which H2 omits.
1 parent f864574 commit 8ba55d1

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

test/CodeoriginTest.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
// Domain root
1919

2020
Unit::testHttp( $server, '/', [], [
21-
'status' => '301 Moved Permanently',
21+
'status' => '301',
2222
'server' => 'nginx',
2323
'location' => 'https://releases.jquery.com/',
2424
] );
2525

2626
// Static assets
2727

2828
Unit::testHttp( $server, '/jquery-3.0.0.js', [], [
29-
'status' => '200 OK',
29+
'status' => '200',
3030
'server' => 'nginx',
3131
'content-type' => 'application/javascript; charset=utf-8',
3232
'content-length' => '263268',
@@ -40,7 +40,7 @@
4040
] );
4141

4242
Unit::testHttp( $server, '/qunit/qunit-2.0.0.css', [], [
43-
'status' => '200 OK',
43+
'status' => '200',
4444
'server' => 'nginx',
4545
'content-type' => 'text/css',
4646
'content-length' => '7456',
@@ -54,7 +54,7 @@
5454
] );
5555

5656
Unit::testHttp( $server, '/ui/1.10.0/themes/base/images/ui-icons_222222_256x240.png', [], [
57-
'status' => '200 OK',
57+
'status' => '200',
5858
'server' => 'nginx',
5959
'content-type' => 'image/png',
6060
'content-length' => '4369',
@@ -67,7 +67,7 @@
6767
] );
6868

6969
Unit::testHttp( $server, '/jquery-2.0.0.min.map', [], [
70-
'status' => '200 OK',
70+
'status' => '200',
7171
'server' => 'nginx',
7272
'content-type' => 'application/octet-stream',
7373
'content-length' => '126081',
@@ -84,7 +84,7 @@
8484
Unit::testHttp( $server, '/jquery-3.0.0.js', [
8585
"x-cdn-access: there-is-no-spoon"
8686
], [
87-
'status' => '200 OK',
87+
'status' => '200',
8888
'server' => 'nginx',
8989
'content-type' => 'application/javascript; charset=utf-8',
9090
'content-length' => '263268',
@@ -100,67 +100,67 @@
100100
// Renamed files
101101

102102
Unit::testHttp( $server, '/jquery-git2.js', [], [
103-
'status' => '301 Moved Permanently',
103+
'status' => '301',
104104
'server' => 'nginx',
105105
'location' => 'https://code.jquery.com/jquery-git.js',
106106
] );
107107

108108
// Moved to releases, WordPress page
109109

110110
Unit::testHttp( $server, '/jquery/', [], [
111-
'status' => '301 Moved Permanently',
111+
'status' => '301',
112112
'server' => 'nginx',
113113
'location' => 'https://releases.jquery.com/jquery/',
114114
] );
115115

116116
// Moved to releases, WordPress page without trailing slash
117117

118118
Unit::testHttp( $server, '/jquery', [], [
119-
'status' => '301 Moved Permanently',
119+
'status' => '301',
120120
'server' => 'nginx',
121121
'location' => 'https://releases.jquery.com/jquery/',
122122
] );
123123

124124
// Moved to releases, root -git file
125125

126126
Unit::testHttp( $server, '/jquery-git.js', [], [
127-
'status' => '301 Moved Permanently',
127+
'status' => '301',
128128
'server' => 'nginx',
129129
'location' => 'https://releases.jquery.com/git/jquery-git.js',
130130
] );
131131

132132
// Moved to releases, nested -git file
133133

134134
Unit::testHttp( $server, '/color/jquery.color-git.min.js', [], [
135-
'status' => '301 Moved Permanently',
135+
'status' => '301',
136136
'server' => 'nginx',
137137
'location' => 'https://releases.jquery.com/git/color/jquery.color-git.min.js',
138138
] );
139139

140140
Unit::testHttp( $server, '/qunit/qunit-git.css', [], [
141-
'status' => '301 Moved Permanently',
141+
'status' => '301',
142142
'server' => 'nginx',
143143
'location' => 'https://releases.jquery.com/git/qunit/qunit-git.css',
144144
] );
145145

146146
Unit::testHttp( $server, '/mobile/git/jquery.mobile-git.min.map', [], [
147-
'status' => '301 Moved Permanently',
147+
'status' => '301',
148148
'server' => 'nginx',
149149
'location' => 'https://releases.jquery.com/git/mobile/git/jquery.mobile-git.min.map',
150150
] );
151151

152152
// Moved to releases, any file under /mobile/git
153153

154154
Unit::testHttp( $server, '/mobile/git/images/icons-png/power-black.png', [], [
155-
'status' => '301 Moved Permanently',
155+
'status' => '301',
156156
'server' => 'nginx',
157157
'location' => 'https://releases.jquery.com/git/mobile/git/images/icons-png/power-black.png',
158158
] );
159159

160160
// Moved to releases, any file under /git (new-style URL)
161161

162162
Unit::testHttp( $server, '/git/qunit/qunit-git.css', [], [
163-
'status' => '301 Moved Permanently',
163+
'status' => '301',
164164
'server' => 'nginx',
165165
'location' => 'https://releases.jquery.com/git/qunit/qunit-git.css',
166166
] );

test/Unit.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ function jq_req( $url, array $reqHeaders = [] ) {
2020
'connection'
2121
];
2222
$len = strlen( $header );
23-
if ( preg_match( "/^(HTTP\/(?:1\.[01]|2)) (\d{3} .*)/", $header, $m ) ) {
23+
// Both HTTP/1.1 and HTTP/2 are valid
24+
// Under HTTP/2, the status code is an integer without textual reason
25+
if ( preg_match( "/^(HTTP\/(?:1\.[01]|2)) (\d+)/", $header, $m ) ) {
2426
$resp['headers'] = [];
2527
$resp['headers']['status'] = trim( $m[2] );
2628
} else {

0 commit comments

Comments
 (0)