Index: trunk/phase3/tests/HttpTest.php |
— | — | @@ -63,9 +63,8 @@ |
64 | 64 | |
65 | 65 | |
66 | 66 | function testInstantiation() { |
67 | | - global $wgHTTPEngine; |
| 67 | + Http::$httpEngine = false; |
68 | 68 | |
69 | | - unset($wgHTTPEngine); |
70 | 69 | $r = new HttpRequest("http://www.example.com/"); |
71 | 70 | if ( self::$has_curl ) { |
72 | 71 | $this->isInstanceOf( $r, 'CurlHttpRequest' ); |
— | — | @@ -74,7 +73,7 @@ |
75 | 74 | } |
76 | 75 | unset($r); |
77 | 76 | |
78 | | - $wgHTTPEngine = 'php'; |
| 77 | + Http::$httpEngine = 'php'; |
79 | 78 | $r = new HttpRequest("http://www.example.com/"); |
80 | 79 | $this->isInstanceOf( $r, 'PhpHttpRequest' ); |
81 | 80 | unset($r); |
— | — | @@ -82,7 +81,7 @@ |
83 | 82 | if( !self::$has_curl ) { |
84 | 83 | $this->setExpectedException( 'MWException' ); |
85 | 84 | } |
86 | | - $wgHTTPEngine = 'curl'; |
| 85 | + Http::$httpEngine = 'curl'; |
87 | 86 | $r = new HttpRequest("http://www.example.com/"); |
88 | 87 | if( self::$has_curl ) { |
89 | 88 | $this->isInstanceOf( $r, 'CurlHttpRequest' ); |
— | — | @@ -90,7 +89,6 @@ |
91 | 90 | } |
92 | 91 | |
93 | 92 | function runHTTPFailureChecks() { |
94 | | - global $wgHTTPEngine; |
95 | 93 | // Each of the following requests should result in a failure. |
96 | 94 | |
97 | 95 | $timeout = 1; |
— | — | @@ -98,32 +96,26 @@ |
99 | 97 | $r = HTTP::get( "http://www.example.com:1/", $timeout); |
100 | 98 | $end_time = time(); |
101 | 99 | $this->assertLessThan($timeout+2, $end_time - $start_time, |
102 | | - "Request took less than {$timeout}s via $wgHTTPEngine"); |
| 100 | + "Request took less than {$timeout}s via ".Http::$httpEngine); |
103 | 101 | $this->assertEquals($r, false, "false -- what we get on error from Http::get()"); |
104 | 102 | } |
105 | 103 | |
106 | 104 | function testFailureDefault() { |
107 | | - global $wgHTTPEngine; |
108 | | - |
109 | | - unset($wgHTTPEngine); |
| 105 | + Http::$httpEngine = false; |
110 | 106 | self::runHTTPFailureChecks(); |
111 | 107 | } |
112 | 108 | |
113 | 109 | function testFailurePhp() { |
114 | | - global $wgHTTPEngine; |
115 | | - |
116 | | - $wgHTTPEngine = "php"; |
| 110 | + Http::$httpEngine = "php"; |
117 | 111 | self::runHTTPFailureChecks(); |
118 | 112 | } |
119 | 113 | |
120 | 114 | function testFailureCurl() { |
121 | | - global $wgHTTPEngine; |
122 | | - |
123 | 115 | if (!self::$has_curl ) { |
124 | 116 | $this->markTestIncomplete("This test requires curl."); |
125 | 117 | } |
126 | 118 | |
127 | | - $wgHTTPEngine = "curl"; |
| 119 | + Http::$httpEngine = "curl"; |
128 | 120 | self::runHTTPFailureChecks(); |
129 | 121 | } |
130 | 122 | |
— | — | @@ -131,7 +123,6 @@ |
132 | 124 | /* ./includes/Import.php:1124: $link = Title::newFromText( "$interwiki:Special:Export/$page" ); */ |
133 | 125 | /* ./includes/Import.php:1134: return ImportStreamSource::newFromURL( $url, "POST" ); */ |
134 | 126 | function runHTTPRequests($proxy=null) { |
135 | | - global $wgHTTPEngine; |
136 | 127 | $opt = array(); |
137 | 128 | |
138 | 129 | if($proxy) { |
— | — | @@ -141,32 +132,26 @@ |
142 | 133 | /* no postData here because the only request I could find in code so far didn't have any */ |
143 | 134 | foreach ( $this->test_requesturl as $u ) { |
144 | 135 | $r = Http::request( "POST", $u, $opt ); |
145 | | - $this->assertEquals( self::$content["POST $u"], "$r", "POST $u with $wgHTTPEngine" ); |
| 136 | + $this->assertEquals( self::$content["POST $u"], "$r", "POST $u with ".Http::$httpEngine ); |
146 | 137 | } |
147 | 138 | } |
148 | 139 | |
149 | 140 | function testRequestDefault() { |
150 | | - global $wgHTTPEngine; |
151 | | - |
152 | | - unset($wgHTTPEngine); |
| 141 | + Http::$httpEngine = false; |
153 | 142 | self::runHTTPRequests(); |
154 | 143 | } |
155 | 144 | |
156 | 145 | function testRequestPhp() { |
157 | | - global $wgHTTPEngine; |
158 | | - |
159 | | - $wgHTTPEngine = "php"; |
| 146 | + Http::$httpEngine = "php"; |
160 | 147 | self::runHTTPRequests(); |
161 | 148 | } |
162 | 149 | |
163 | 150 | function testRequestCurl() { |
164 | | - global $wgHTTPEngine; |
165 | | - |
166 | 151 | if (!self::$has_curl ) { |
167 | 152 | $this->markTestIncomplete("This test requires curl."); |
168 | 153 | } |
169 | 154 | |
170 | | - $wgHTTPEngine = "curl"; |
| 155 | + Http::$httpEngine = "curl"; |
171 | 156 | self::runHTTPRequests(); |
172 | 157 | } |
173 | 158 | |
— | — | @@ -215,7 +200,6 @@ |
216 | 201 | /* ./extensions/Interlanguage/Interlanguage.php:56: $a = Http::get( $url ); */ |
217 | 202 | /* ./extensions/MWSearch/MWSearch_body.php:492: $data = Http::get( $searchUrl, $wgLuceneSearchTimeout, $httpOpts); */ |
218 | 203 | function runHTTPGets($proxy=null) { |
219 | | - global $wgHTTPEngine; |
220 | 204 | $opt = array(); |
221 | 205 | |
222 | 206 | if($proxy) { |
— | — | @@ -224,38 +208,31 @@ |
225 | 209 | |
226 | 210 | foreach ( $this->test_geturl as $u ) { |
227 | 211 | $r = Http::get( $u, 30, $opt ); /* timeout of 30s */ |
228 | | - $this->assertEquals( self::$content["GET $u"], "$r", "Get $u with $wgHTTPEngine" ); |
| 212 | + $this->assertEquals( self::$content["GET $u"], "$r", "Get $u with ".Http::$httpEngine ); |
229 | 213 | } |
230 | 214 | } |
231 | 215 | |
232 | 216 | function testGetDefault() { |
233 | | - global $wgHTTPEngine; |
234 | | - |
235 | | - unset($wgHTTPEngine); |
| 217 | + Http::$httpEngine = false; |
236 | 218 | self::runHTTPGets(); |
237 | 219 | } |
238 | 220 | |
239 | 221 | function testGetPhp() { |
240 | | - global $wgHTTPEngine; |
241 | | - |
242 | | - $wgHTTPEngine = "php"; |
| 222 | + Http::$httpEngine = "php"; |
243 | 223 | self::runHTTPGets(); |
244 | 224 | } |
245 | 225 | |
246 | 226 | function testGetCurl() { |
247 | | - global $wgHTTPEngine; |
248 | | - |
249 | 227 | if (!self::$has_curl ) { |
250 | 228 | $this->markTestIncomplete("This test requires curl."); |
251 | 229 | } |
252 | 230 | |
253 | | - $wgHTTPEngine = "curl"; |
| 231 | + Http::$httpEngine = "curl"; |
254 | 232 | self::runHTTPGets(); |
255 | 233 | } |
256 | 234 | |
257 | 235 | /* ./phase3/maintenance/parserTests.inc:1618: return Http::post( $url, array( 'postData' => wfArrayToCGI( $data ) ) ); */ |
258 | 236 | function runHTTPPosts($proxy=null) { |
259 | | - global $wgHTTPEngine; |
260 | 237 | $opt = array(); |
261 | 238 | |
262 | 239 | if($proxy) { |
— | — | @@ -266,38 +243,30 @@ |
267 | 244 | $opt['postData'] = $postData; |
268 | 245 | $r = Http::post( $u, $opt ); |
269 | 246 | $this->assertEquals( self::$content["POST $u => $postData"], "$r", |
270 | | - "POST $u (postData=$postData) with $wgHTTPEngine" ); |
| 247 | + "POST $u (postData=$postData) with ".Http::$httpEngine ); |
271 | 248 | } |
272 | 249 | } |
273 | 250 | |
274 | 251 | function testPostDefault() { |
275 | | - global $wgHTTPEngine; |
276 | | - |
277 | | - unset($wgHTTPEngine); |
| 252 | + Http::$httpEngine = false; |
278 | 253 | self::runHTTPPosts(); |
279 | 254 | } |
280 | 255 | |
281 | 256 | function testPostPhp() { |
282 | | - global $wgHTTPEngine; |
283 | | - |
284 | | - $wgHTTPEngine = "php"; |
| 257 | + Http::$httpEngine = "php"; |
285 | 258 | self::runHTTPPosts(); |
286 | 259 | } |
287 | 260 | |
288 | 261 | function testPostCurl() { |
289 | | - global $wgHTTPEngine; |
290 | | - |
291 | 262 | if (!self::$has_curl ) { |
292 | 263 | $this->markTestIncomplete("This test requires curl."); |
293 | 264 | } |
294 | 265 | |
295 | | - $wgHTTPEngine = "curl"; |
| 266 | + Http::$httpEngine = "curl"; |
296 | 267 | self::runHTTPPosts(); |
297 | 268 | } |
298 | 269 | |
299 | 270 | function runProxyRequests() { |
300 | | - global $wgHTTPEngine; |
301 | | - |
302 | 271 | if(!self::$has_proxy) { |
303 | 272 | $this->markTestIncomplete("This test requires a proxy."); |
304 | 273 | } |
— | — | @@ -307,27 +276,21 @@ |
308 | 277 | } |
309 | 278 | |
310 | 279 | function testProxyDefault() { |
311 | | - global $wgHTTPEngine; |
312 | | - |
313 | | - unset($wgHTTPEngine); |
| 280 | + Http::$httpEngine = false; |
314 | 281 | self::runProxyRequests(); |
315 | 282 | } |
316 | 283 | |
317 | 284 | function testProxyPhp() { |
318 | | - global $wgHTTPEngine; |
319 | | - |
320 | | - $wgHTTPEngine = 'php'; |
| 285 | + Http::$httpEngine = 'php'; |
321 | 286 | self::runProxyRequests(); |
322 | 287 | } |
323 | 288 | |
324 | 289 | function testProxyCurl() { |
325 | | - global $wgHTTPEngine; |
326 | | - |
327 | 290 | if (!self::$has_curl ) { |
328 | 291 | $this->markTestIncomplete("This test requires curl."); |
329 | 292 | } |
330 | 293 | |
331 | | - $wgHTTPEngine = 'curl'; |
| 294 | + Http::$httpEngine = 'curl'; |
332 | 295 | self::runProxyRequests(); |
333 | 296 | } |
334 | 297 | |
Index: trunk/phase3/includes/DefaultSettings.php |
— | — | @@ -3698,14 +3698,6 @@ |
3699 | 3699 | $wgAllowSpecialInclusion = true; |
3700 | 3700 | |
3701 | 3701 | /** |
3702 | | - * 'curl' to use curl or 'php' to use pure php (for which |
3703 | | - * allow_url_fopen needs to be enabled). If left as false, |
3704 | | - * HttpFunctions will attempt to use curl if it is available. The use |
3705 | | - * of curl is strongly encouraged. |
3706 | | - */ |
3707 | | -$wgHTTPEngine = false; |
3708 | | - |
3709 | | -/** |
3710 | 3702 | * Timeout for HTTP requests done internally |
3711 | 3703 | */ |
3712 | 3704 | $wgHTTPTimeout = 25; |
Index: trunk/phase3/includes/HttpFunctions.php |
— | — | @@ -8,6 +8,8 @@ |
9 | 9 | * @ingroup HTTP |
10 | 10 | */ |
11 | 11 | class Http { |
| 12 | + static $httpEngine = false; |
| 13 | + |
12 | 14 | /** |
13 | 15 | * Perform an HTTP request |
14 | 16 | * @param $method string HTTP method. Usually GET/POST |
— | — | @@ -169,16 +171,13 @@ |
170 | 172 | * @see HttpRequest::__construct |
171 | 173 | */ |
172 | 174 | public static function factory( $url, $options ) { |
173 | | - global $wgHTTPEngine; |
174 | | - $engine = $wgHTTPEngine; |
175 | | - |
176 | | - if ( !$wgHTTPEngine ) { |
177 | | - $wgHTTPEngine = function_exists( 'curl_init' ) ? 'curl' : 'php'; |
178 | | - } elseif ( $wgHTTPEngine == 'curl' && !function_exists( 'curl_init' ) ) { |
179 | | - throw new MWException( __METHOD__.': curl (http://php.net/curl) is not installed, but $wgHTTPEngine is set to "curl"' ); |
| 175 | + if ( !Http::$httpEngine ) { |
| 176 | + Http::$httpEngine = function_exists( 'curl_init' ) ? 'curl' : 'php'; |
| 177 | + } elseif ( Http::$httpEngine == 'curl' && !function_exists( 'curl_init' ) ) { |
| 178 | + throw new MWException( __METHOD__.': curl (http://php.net/curl) is not installed, but Http::$httpEngine is set to "curl"' ); |
180 | 179 | } |
181 | 180 | |
182 | | - switch( $wgHTTPEngine ) { |
| 181 | + switch( Http::$httpEngine ) { |
183 | 182 | case 'curl': |
184 | 183 | return new CurlHttpRequest( $url, $options ); |
185 | 184 | case 'php': |
— | — | @@ -188,7 +187,7 @@ |
189 | 188 | } |
190 | 189 | return new PhpHttpRequest( $url, $options ); |
191 | 190 | default: |
192 | | - throw new MWException( __METHOD__.': The setting of $wgHTTPEngine is not valid.' ); |
| 191 | + throw new MWException( __METHOD__.': The setting of Http::$httpEngine is not valid.' ); |
193 | 192 | } |
194 | 193 | } |
195 | 194 | |