Class: HTTP::Message::Headers

Class | HTTP::Message::Headers
In: | lib/httpclient/http.rb
Parent: | Object

Represents HTTP message header.

### Methods

[] []= add all body_size= contenttype contenttype= delete dump get init_connect_request init_request init_response new set status_code=

### Constants

STATUS_CODE_MAP | = | { Status::OK => 'OK', Status::CREATED => "Created", Status::NON_AUTHORITATIVE_INFORMATION => "Non-Authoritative Information", Status::NO_CONTENT => "No Content", Status::RESET_CONTENT => "Reset Content", Status::PARTIAL_CONTENT => "Partial Content", Status::MOVED_PERMANENTLY => 'Moved Permanently', Status::FOUND => 'Found', Status::SEE_OTHER => 'See Other', Status::TEMPORARY_REDIRECT => 'Temporary Redirect', Status::MOVED_TEMPORARILY => 'Temporary Redirect', Status::BAD_REQUEST => 'Bad Request', Status::INTERNAL => 'Internal Server Error', } |  | HTTP response status code to reason phrase mapping definition.
CHARSET_MAP | = | { 'NONE' => 'us-ascii', 'EUC' => 'euc-jp', 'SJIS' => 'shift_jis', 'UTF8' => 'utf-8', } |  | $KCODE to charset mapping definition.
NIL_URI | = | URI.parse('http://nil-uri-given/') |  | Placeholder URI object for nil uri.

### Attributes

body_size | [R] | Size of body. nil when size is unknown (e.g. chunked response).
chunked | [RW] | Request/Response is chunked or not.
http_version | [RW] | HTTP version in a HTTP header. Float.
reason_phrase | [RW] | Response only. HTTP status reason phrase.
request_method | [R] | Request only. Requested method.
request_query | [RW] | Request only. Requested query.
request_uri | [RW] | Request only. Requested URI.
request_via_proxy | [RW] | Request only. Requested via proxy or not.
status_code | [R] | Response only. HTTP status

### Public Class methods

new()

Creates a Message::Headers. Use init_request, init_response, or init_connect_request for acutual initialize.

### Public Instance methods

[](key)

Returns an Array of header values for the given key.

[]=(key, value)

Adds a header. See set.

add(key, value)

Adds a header. Addition order is preserved.

all()

Returns an Array of all headers.

body_size=(body_size)

Sets byte size of message body. body_size == nil means that the body is_a? IO

contenttype()

Returns ‘Content-Type’ header value.

contenttype=(contenttype)

Sets ‘Content-Type’ header value. Overrides if already exists.

delete(key)

Deletes headers of the given key.

dump()

Dumps message header part and returns a dumped String.

get(key = nil)

Returns an Array of headers for the given key. Each element is a pair of key and value. It returns an single element Array even if the only one header exists. If nil key given, it returns all headers.

init_connect_request(uri)

Initialize this instance as a CONNECT request.

init_request(method, uri, query = nil)

Initialize this instance as a general request.

init_response(status_code)

Initialize this instance as a response.

set(key, value)

Sets a header.

status_code=(status_code)

Sets status code and reason phrase.

[Validate]