### Eclipse Workspace Patch 1.0
#P wordpress
|
|
|
|
| 238 | 238 | if ( false !== $pre ) |
| 239 | 239 | return $pre; |
| 240 | 240 | |
| 241 | | $arrURL = parse_url($url); |
| | 241 | $arrURL = parse_url( $url ); |
| 242 | 242 | |
| 243 | | if ( empty( $url ) || empty($url['scheme'] ) ) |
| 244 | | return new WP_Error('http_request_failed', __('A valid URL was not provided.')); |
| | 243 | if ( empty( $url ) || empty( $arrURL['scheme'] ) ) |
| | 244 | return new WP_Error( 'http_request_failed', __( 'A valid URL was not provided.' ) ); |
| 245 | 245 | |
| 246 | 246 | if ( $this->block_request( $url ) ) |
| 247 | | return new WP_Error('http_request_failed', __('User has blocked requests through HTTP.')); |
| | 247 | return new WP_Error( 'http_request_failed', __( 'User has blocked requests through HTTP.' ) ); |
| 248 | 248 | |
| 249 | 249 | // Determine if this is a https call and pass that on to the transport functions |
| 250 | 250 | // so that we can blacklist the transports that do not support ssl verification |
| 251 | | $r['ssl'] = $arrURL['scheme'] == 'https' || $arrURL['scheme'] == 'ssl'; |
| | 251 | $r['ssl'] = $arrURL['scheme'] == 'https' || $arrURL['scheme'] == 'ssl'; |
| 252 | 252 | |
| 253 | 253 | // Determine if this request is to OUR install of WordPress |
| 254 | | $homeURL = parse_url( get_bloginfo('url') ); |
| | 254 | $homeURL = parse_url( get_bloginfo( 'url' ) ); |
| 255 | 255 | $r['local'] = $homeURL['host'] == $arrURL['host'] || 'localhost' == $arrURL['host']; |
| 256 | | unset($homeURL); |
| | 256 | unset( $homeURL ); |
| 257 | 257 | |
| 258 | 258 | if ( is_null( $r['headers'] ) ) |
| 259 | 259 | $r['headers'] = array(); |
| 260 | 260 | |
| 261 | | if ( ! is_array($r['headers']) ) { |
| 262 | | $processedHeaders = WP_Http::processHeaders($r['headers']); |
| 263 | | $r['headers'] = $processedHeaders['headers']; |
| | 261 | if ( ! is_array( $r['headers'] ) ) { |
| | 262 | $processedHeaders = WP_Http::processHeaders( $r['headers'] ); |
| | 263 | $r['headers'] = $processedHeaders['headers']; |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | | if ( isset($r['headers']['User-Agent']) ) { |
| 267 | | $r['user-agent'] = $r['headers']['User-Agent']; |
| 268 | | unset($r['headers']['User-Agent']); |
| | 266 | if ( isset( $r['headers']['User-Agent'] ) ) { |
| | 267 | $r['user-agent'] = $r['headers']['User-Agent']; |
| | 268 | unset( $r['headers']['User-Agent'] ); |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | | if ( isset($r['headers']['user-agent']) ) { |
| 272 | | $r['user-agent'] = $r['headers']['user-agent']; |
| 273 | | unset($r['headers']['user-agent']); |
| | 271 | if ( isset( $r['headers']['user-agent'] ) ) { |
| | 272 | $r['user-agent'] = $r['headers']['user-agent']; |
| | 273 | unset( $r['headers']['user-agent'] ); |
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | // Construct Cookie: header if any cookies are set |
| … |
… |
|
| 283 | 283 | // Some servers fail when sending content without the content-length header being set. |
| 284 | 284 | // Also, to fix another bug, we only send when doing POST and PUT and the content-length |
| 285 | 285 | // header isn't already set. |
| 286 | | if( ($r['method'] == 'POST' || $r['method'] == 'PUT') && ! isset($r['headers']['Content-Length']) ) |
| | 286 | if( ($r['method'] == 'POST' || $r['method'] == 'PUT') && ! isset( $r['headers']['Content-Length'] ) ) |
| 287 | 287 | $r['headers']['Content-Length'] = 0; |
| 288 | 288 | |
| 289 | 289 | // The method is ambiguous, because we aren't talking about HTTP methods, the "get" in |
| 290 | 290 | // this case is simply that we aren't sending any bodies and to get the transports that |
| 291 | 291 | // don't support sending bodies along with those which do. |
| 292 | | $transports = WP_Http::_getTransport($r); |
| | 292 | $transports = WP_Http::_getTransport( $r ); |
| 293 | 293 | } else { |
| 294 | 294 | if ( is_array( $r['body'] ) || is_object( $r['body'] ) ) { |
| 295 | 295 | if ( ! version_compare(phpversion(), '5.1.2', '>=') ) |
| 296 | | $r['body'] = _http_build_query($r['body'], null, '&'); |
| | 296 | $r['body'] = _http_build_query( $r['body'], null, '&' ); |
| 297 | 297 | else |
| 298 | | $r['body'] = http_build_query($r['body'], null, '&'); |
| 299 | | $r['headers']['Content-Type'] = 'application/x-www-form-urlencoded; charset=' . get_option('blog_charset'); |
| 300 | | $r['headers']['Content-Length'] = strlen($r['body']); |
| | 298 | $r['body'] = http_build_query( $r['body'], null, '&' ); |
| | 299 | $r['headers']['Content-Type'] = 'application/x-www-form-urlencoded; charset=' . get_option( 'blog_charset' ); |
| | 300 | $r['headers']['Content-Length'] = strlen( $r['body'] ); |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | if ( ! isset( $r['headers']['Content-Length'] ) && ! isset( $r['headers']['content-length'] ) ) |
| 304 | | $r['headers']['Content-Length'] = strlen($r['body']); |
| | 304 | $r['headers']['Content-Length'] = strlen( $r['body'] ); |
| 305 | 305 | |
| 306 | 306 | // The method is ambiguous, because we aren't talking about HTTP methods, the "post" in |
| 307 | 307 | // this case is simply that we are sending HTTP body and to get the transports that do |
| 308 | 308 | // support sending the body. Not all do, depending on the limitations of the PHP core |
| 309 | 309 | // limitations. |
| 310 | | $transports = WP_Http::_postTransport($r); |
| | 310 | $transports = WP_Http::_postTransport( $r ); |
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | do_action( 'http_api_debug', $transports, 'transports_list' ); |
| 314 | 314 | |
| 315 | 315 | $response = array( 'headers' => array(), 'body' => '', 'response' => array('code' => false, 'message' => false), 'cookies' => array() ); |
| 316 | 316 | foreach ( (array) $transports as $transport ) { |
| 317 | | $response = $transport->request($url, $r); |
| | 317 | $response = $transport->request( $url, $r ); |
| 318 | 318 | |
| 319 | | do_action( 'http_api_debug', $response, 'response', get_class($transport) ); |
| | 319 | do_action( 'http_api_debug', $response, 'response', get_class( $transport ) ); |
| 320 | 320 | |
| 321 | | if ( ! is_wp_error($response) ) |
| | 321 | if ( ! is_wp_error( $response ) ) |
| 322 | 322 | return apply_filters( 'http_response', $response, $r, $url ); |
| 323 | 323 | } |
| 324 | 324 | |