Changeset 17914 for trunk/wp-includes/class-http.php
- Timestamp:
- 05/13/2011 09:56:59 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/class-http.php
r17771 r17914 27 27 * 28 28 * Debugging includes several actions, which pass different variables for debugging the HTTP API. 29 *30 * <strong>http_transport_get_debug</strong> - gives working, nonblocking, and blocking transports.31 *32 * <strong>http_transport_post_debug</strong> - gives working, nonblocking, and blocking transports.33 29 * 34 30 * @package WordPress … … 197 193 198 194 /** 195 * Tests which transports are capabable of supporting the request. 196 * 197 * @since 3.2.0 198 * @access private 199 * 200 * @param array $args Request arguments 201 * @param string $url URL to Request 202 * 203 * @return string|false Class name for the first transport that claims to support the request. False if no transport claims to support the request. 204 */ 205 public function _get_first_available_transport( $args, $url = null ) { 206 $request_order = array( 'curl', 'streams', 'fsockopen' ); 207 208 // Loop over each transport on each HTTP request looking for one which will serve this request's needs 209 foreach ( $request_order as $transport ) { 210 $class = 'WP_HTTP_' . $transport; 211 212 // Check to see if this transport is a possibility, calls the transport statically 213 if ( !call_user_func( array( $class, 'test' ), $args, $url ) ) 214 continue; 215 216 return $class; 217 } 218 219 return false; 220 } 221 222 /** 199 223 * Dispatches a HTTP request to a supporting transport. 200 224 * … … 217 241 * @return array|object Array containing 'headers', 'body', 'response', 'cookies'. A WP_Error instance upon error 218 242 */ 219 private function _dispatch_request( $url, $args) {243 private function _dispatch_request( $url, $args ) { 220 244 static $transports = array(); 221 245 222 $request_order = array('curl', 'streams', 'fsockopen'); 223 224 // Loop over each transport on each HTTP request looking for one which will serve this requests needs 225 foreach ( $request_order as $transport ) { 226 $class = 'WP_HTTP_' . $transport; 227 228 // Check to see if this transport is a possibility, calls the transport statically 229 if ( ! call_user_func( array($class, 'test'), $args, $url) ) 230 continue; 231 232 // Transport claims to support request, Instantate it and give it a whirl. 233 if ( empty( $transports[ $transport ] ) ) 234 $transports[ $transport ] = new $class; 235 236 $response = $transports[ $transport ]->request( $url, $args ); 237 238 do_action( 'http_api_debug', $response, 'response', $class ); 239 240 if ( is_wp_error( $response ) ) 241 return $response; 242 243 return apply_filters( 'http_response', $response, $args, $url ); 244 } 245 246 return new WP_Error('http_failure', __('There are no HTTP transports available which can complete the requested request.') ); 246 $class = $this->_get_first_available_transport( $args, $url ); 247 if ( !$class ) 248 return new WP_Error( 'http_failure', __( 'There are no HTTP transports available which can complete the requested request.' ) ); 249 250 // Transport claims to support request, Instantate it and give it a whirl. 251 if ( empty( $transports[$class] ) ) 252 $transports[$class] = new $class; 253 254 $response = $transports[$class]->request( $url, $args ); 255 256 do_action( 'http_api_debug', $response, 'response', $class ); 257 258 if ( is_wp_error( $response ) ) 259 return $response; 260 261 return apply_filters( 'http_response', $response, $args, $url ); 247 262 } 248 263
Note: See TracChangeset
for help on using the changeset viewer.