Title: WP_HTTP_Response
Published: December 9, 2015
Last modified: May 20, 2026

---

# class WP_HTTP_Response {}

## In this article

 * [Methods](https://developer.wordpress.org/reference/classes/WP_HTTP_Response/?output_format=md#methods)
 * [Source](https://developer.wordpress.org/reference/classes/WP_HTTP_Response/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/WP_HTTP_Response/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/WP_HTTP_Response/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/WP_HTTP_Response/?output_format=md#wp--skip-link--target)

Core class used to prepare HTTP responses.

## 󠀁[Methods](https://developer.wordpress.org/reference/classes/WP_HTTP_Response/?output_format=md#methods)󠁿

| Name | Description | 
| [WP_HTTP_Response::__construct](https://developer.wordpress.org/reference/classes/wp_http_response/__construct/) | Constructor. | 
| [WP_HTTP_Response::get_data](https://developer.wordpress.org/reference/classes/wp_http_response/get_data/) | Retrieves the response data. | 
| [WP_HTTP_Response::get_headers](https://developer.wordpress.org/reference/classes/wp_http_response/get_headers/) | Retrieves headers associated with the response. | 
| [WP_HTTP_Response::get_status](https://developer.wordpress.org/reference/classes/wp_http_response/get_status/) | Retrieves the HTTP return code for the response. | 
| [WP_HTTP_Response::header](https://developer.wordpress.org/reference/classes/wp_http_response/header/) | Sets a single HTTP header. | 
| [WP_HTTP_Response::jsonSerialize](https://developer.wordpress.org/reference/classes/wp_http_response/jsonserialize/) | Retrieves the response data for JSON serialization. | 
| [WP_HTTP_Response::set_data](https://developer.wordpress.org/reference/classes/wp_http_response/set_data/) | Sets the response data. | 
| [WP_HTTP_Response::set_headers](https://developer.wordpress.org/reference/classes/wp_http_response/set_headers/) | Sets all header values. | 
| [WP_HTTP_Response::set_status](https://developer.wordpress.org/reference/classes/wp_http_response/set_status/) | Sets the 3-digit HTTP status code. |

## 󠀁[Source](https://developer.wordpress.org/reference/classes/WP_HTTP_Response/?output_format=md#source)󠁿

    ```php
    #[AllowDynamicProperties]
    class WP_HTTP_Response {

    	/**
    	 * Response data.
    	 *
    	 * @since 4.4.0
    	 * @var mixed
    	 */
    	public $data;

    	/**
    	 * Response headers.
    	 *
    	 * @since 4.4.0
    	 * @var array
    	 */
    	public $headers;

    	/**
    	 * Response status.
    	 *
    	 * @since 4.4.0
    	 * @var int
    	 */
    	public $status;

    	/**
    	 * Constructor.
    	 *
    	 * @since 4.4.0
    	 *
    	 * @param mixed $data    Response data. Default null.
    	 * @param int   $status  Optional. HTTP status code. Default 200.
    	 * @param array $headers Optional. HTTP header map. Default empty array.
    	 */
    	public function __construct( $data = null, $status = 200, $headers = array() ) {
    		$this->set_data( $data );
    		$this->set_status( $status );
    		$this->set_headers( $headers );
    	}

    	/**
    	 * Retrieves headers associated with the response.
    	 *
    	 * @since 4.4.0
    	 *
    	 * @return array Map of header name to header value.
    	 */
    	public function get_headers() {
    		return $this->headers;
    	}

    	/**
    	 * Sets all header values.
    	 *
    	 * @since 4.4.0
    	 *
    	 * @param array $headers Map of header name to header value.
    	 */
    	public function set_headers( $headers ) {
    		$this->headers = $headers;
    	}

    	/**
    	 * Sets a single HTTP header.
    	 *
    	 * @since 4.4.0
    	 *
    	 * @param string $key     Header name.
    	 * @param string $value   Header value.
    	 * @param bool   $replace Optional. Whether to replace an existing header of the same name.
    	 *                        Default true.
    	 */
    	public function header( $key, $value, $replace = true ) {
    		if ( $replace || ! isset( $this->headers[ $key ] ) ) {
    			$this->headers[ $key ] = $value;
    		} else {
    			$this->headers[ $key ] .= ', ' . $value;
    		}
    	}

    	/**
    	 * Retrieves the HTTP return code for the response.
    	 *
    	 * @since 4.4.0
    	 *
    	 * @return int The 3-digit HTTP status code.
    	 */
    	public function get_status() {
    		return $this->status;
    	}

    	/**
    	 * Sets the 3-digit HTTP status code.
    	 *
    	 * @since 4.4.0
    	 *
    	 * @param int $code HTTP status.
    	 */
    	public function set_status( $code ) {
    		$this->status = absint( $code );
    	}

    	/**
    	 * Retrieves the response data.
    	 *
    	 * @since 4.4.0
    	 *
    	 * @return mixed Response data.
    	 */
    	public function get_data() {
    		return $this->data;
    	}

    	/**
    	 * Sets the response data.
    	 *
    	 * @since 4.4.0
    	 *
    	 * @param mixed $data Response data.
    	 */
    	public function set_data( $data ) {
    		$this->data = $data;
    	}

    	/**
    	 * Retrieves the response data for JSON serialization.
    	 *
    	 * It is expected that in most implementations, this will return the same as get_data(),
    	 * however this may be different if you want to do custom JSON data handling.
    	 *
    	 * @since 4.4.0
    	 *
    	 * @return mixed Any JSON-serializable value.
    	 */
    	public function jsonSerialize() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid
    		return $this->get_data();
    	}
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-http-response.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/class-wp-http-response.php#L15)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/class-wp-http-response.php#L15-L154)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/WP_HTTP_Response/?output_format=md#related)󠁿

| Used by | Description | 
| [WP_HTTP_Requests_Response](https://developer.wordpress.org/reference/classes/wp_http_requests_response/)`wp-includes/class-wp-http-requests-response.php` |

Core wrapper object for a WpOrg\Requests\Response for standardization.

  | 
| [WP_REST_Response](https://developer.wordpress.org/reference/classes/wp_rest_response/)`wp-includes/rest-api/class-wp-rest-response.php` |

Core class used to implement a REST response object.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/WP_HTTP_Response/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.4.0](https://developer.wordpress.org/reference/since/4.4.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_http_response%2F)
before being able to contribute a note or feedback.