wp/wp-includes/class-wp-http-requests-response.php
changeset 21 48c4eec2b7e6
parent 16 a86126ab1dd4
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
     6  * @subpackage HTTP
     6  * @subpackage HTTP
     7  * @since 4.6.0
     7  * @since 4.6.0
     8  */
     8  */
     9 
     9 
    10 /**
    10 /**
    11  * Core wrapper object for a Requests_Response for standardisation.
    11  * Core wrapper object for a WpOrg\Requests\Response for standardization.
    12  *
    12  *
    13  * @since 4.6.0
    13  * @since 4.6.0
    14  *
    14  *
    15  * @see WP_HTTP_Response
    15  * @see WP_HTTP_Response
    16  */
    16  */
    17 class WP_HTTP_Requests_Response extends WP_HTTP_Response {
    17 class WP_HTTP_Requests_Response extends WP_HTTP_Response {
    18 	/**
    18 	/**
    19 	 * Requests Response object.
    19 	 * Requests Response object.
    20 	 *
    20 	 *
    21 	 * @since 4.6.0
    21 	 * @since 4.6.0
    22 	 * @var Requests_Response
    22 	 * @var \WpOrg\Requests\Response
    23 	 */
    23 	 */
    24 	protected $response;
    24 	protected $response;
    25 
    25 
    26 	/**
    26 	/**
    27 	 * Filename the response was saved to.
    27 	 * Filename the response was saved to.
    34 	/**
    34 	/**
    35 	 * Constructor.
    35 	 * Constructor.
    36 	 *
    36 	 *
    37 	 * @since 4.6.0
    37 	 * @since 4.6.0
    38 	 *
    38 	 *
    39 	 * @param Requests_Response $response HTTP response.
    39 	 * @param \WpOrg\Requests\Response $response HTTP response.
    40 	 * @param string            $filename Optional. File name. Default empty.
    40 	 * @param string                   $filename Optional. File name. Default empty.
    41 	 */
    41 	 */
    42 	public function __construct( Requests_Response $response, $filename = '' ) {
    42 	public function __construct( WpOrg\Requests\Response $response, $filename = '' ) {
    43 		$this->response = $response;
    43 		$this->response = $response;
    44 		$this->filename = $filename;
    44 		$this->filename = $filename;
    45 	}
    45 	}
    46 
    46 
    47 	/**
    47 	/**
    48 	 * Retrieves the response object for the request.
    48 	 * Retrieves the response object for the request.
    49 	 *
    49 	 *
    50 	 * @since 4.6.0
    50 	 * @since 4.6.0
    51 	 *
    51 	 *
    52 	 * @return Requests_Response HTTP response.
    52 	 * @return WpOrg\Requests\Response HTTP response.
    53 	 */
    53 	 */
    54 	public function get_response_object() {
    54 	public function get_response_object() {
    55 		return $this->response;
    55 		return $this->response;
    56 	}
    56 	}
    57 
    57 
    58 	/**
    58 	/**
    59 	 * Retrieves headers associated with the response.
    59 	 * Retrieves headers associated with the response.
    60 	 *
    60 	 *
    61 	 * @since 4.6.0
    61 	 * @since 4.6.0
    62 	 *
    62 	 *
    63 	 * @return \Requests_Utility_CaseInsensitiveDictionary Map of header name to header value.
    63 	 * @return \WpOrg\Requests\Utility\CaseInsensitiveDictionary Map of header name to header value.
    64 	 */
    64 	 */
    65 	public function get_headers() {
    65 	public function get_headers() {
    66 		// Ensure headers remain case-insensitive.
    66 		// Ensure headers remain case-insensitive.
    67 		$converted = new Requests_Utility_CaseInsensitiveDictionary();
    67 		$converted = new WpOrg\Requests\Utility\CaseInsensitiveDictionary();
    68 
    68 
    69 		foreach ( $this->response->headers->getAll() as $key => $value ) {
    69 		foreach ( $this->response->headers->getAll() as $key => $value ) {
    70 			if ( count( $value ) === 1 ) {
    70 			if ( count( $value ) === 1 ) {
    71 				$converted[ $key ] = $value[0];
    71 				$converted[ $key ] = $value[0];
    72 			} else {
    72 			} else {
    83 	 * @since 4.6.0
    83 	 * @since 4.6.0
    84 	 *
    84 	 *
    85 	 * @param array $headers Map of header name to header value.
    85 	 * @param array $headers Map of header name to header value.
    86 	 */
    86 	 */
    87 	public function set_headers( $headers ) {
    87 	public function set_headers( $headers ) {
    88 		$this->response->headers = new Requests_Response_Headers( $headers );
    88 		$this->response->headers = new WpOrg\Requests\Response\Headers( $headers );
    89 	}
    89 	}
    90 
    90 
    91 	/**
    91 	/**
    92 	 * Sets a single HTTP header.
    92 	 * Sets a single HTTP header.
    93 	 *
    93 	 *