# ri > WEBrick::HTTPResponse

---
type: CommandReference
command: WEBrick::HTTPResponse
mode: ri
section:
source: rdoc
---

## Quick Reference

- `WEBrick::HTTPResponse.new` — Create a new HTTP response object
- `response.body = "content"` — Set the response body
- `response.status = 200` — Set the HTTP status code
- `response.content_type = "text/html"` — Set the Content-Type header
- `response.set_redirect(WEBrick::HTTPStatus::Redirect, "http://...")` — Set a redirect response
- `response.set_error(WEBrick::HTTPStatus::InternalServerError)` — Set an error response
- `response.header` — Access the response header hash
- `response.cookies` — Access the cookies array

## Name

WEBrick::HTTPResponse — An HTTP response object for WEBrick, used by servlets to send responses to clients. This monkey patch allows applications to perform their own chunking if `rack` is set to true.

## Synopsis

Not documented directly; see the methods below.

## Methods

### Class Methods

- `new` — Creates a new HTTPResponse instance.

### Instance Methods

- `[](key)` — Get a header value by key.
- `[]=(key, value)` — Set a header value.
- `_rack_setup_header` — Setup header for Rack compatibility.
- `body` — Returns the response body.
- `chunked=(value)` — Enable or disable chunked transfer encoding.
- `chunked?` — Returns whether the response is chunked.
- `config` — Returns the configuration hash.
- `content_length` — Returns the `Content-Length` header value.
- `content_length=(length)` — Sets the `Content-Length` header.
- `content_type` — Returns the `Content-Type` header value.
- `content_type=(type)` — Sets the `Content-Type` header.
- `cookies` — Returns the array of cookies.
- `each` — Iterates over response headers.
- `filename` — Returns the filename for `Content-Disposition`.
- `header` — Returns the header hash.
- `http_version` — Returns the HTTP version string.
- `keep_alive` — Returns whether keep-alive is enabled.
- `keep_alive?` — Returns whether keep-alive is enabled.
- `reason_phrase` — Returns the reason phrase (e.g., "OK").
- `request_http_version` — Returns the HTTP version of the request.
- `request_method` — Returns the HTTP method of the request.
- `request_uri` — Returns the URI of the request.
- `sent_size` — Returns the number of bytes sent to the client.
- `set_error(status, backtrace=nil)` — Sets the response to an error status.
- `set_redirect(status, url)` — Sets the response to a redirect.
- `setup_header` — Setup the response headers.
- `status` — Returns the HTTP status code.
- `status=(code)` — Sets the HTTP status code.
- `status_line` — Returns the status line string (e.g., "HTTP/1.1 200 OK").

### Attributes

- `attr_accessor :body` — The response body.
- `attr_accessor :filename` — The filename for `Content-Disposition`.
- `attr_accessor :keep_alive` — Keep-alive flag.
- `attr_accessor :rack` — Rack compatibility flag.
- `attr_accessor :reason_phrase` — The HTTP reason phrase.
- `attr_accessor :request_http_version` — The request HTTP version.
- `attr_accessor :request_method` — The request method.
- `attr_accessor :request_uri` — The request URI.
- `attr_reader :config` — Configuration hash.
- `attr_reader :cookies` — Array of cookies.
- `attr_reader :header` — Response headers hash.
- `attr_reader :http_version` — HTTP version.
- `attr_reader :sent_size` — Bytes sent to client.
- `attr_reader :status` — HTTP status code.

## See Also

- WEBrick::HTTPServlet — Base class for servlets.
- WEBrick::HTTPRequest — The corresponding request object.

## Exit Codes

Not applicable.