Module

Net::HTTPHeader

Inheritance

Header module.

Provides access to @header in the mixed-into class as a hash-like object, except with case-insensitive keys. Also provides methods for accessing commonly-used header values in a more convenient format.

Aliases

Method Alias Description
size → length

Methods

Instance

Visibility Signature
public [] (key)
public []= (key, val)
public add_field (key, val)
public basic_auth (account, password)
public canonical_each ()
public chunked? ()
public content_length ()
public content_length= (len)
public content_range ()
public content_type ()
public content_type= (type, params = {})
public delete (key)
public each (
public each_capitalized () {|capitalize(k), v.join(', ')| ...}
public each_capitalized_name () {|+key+| ...}
public each_header ( {|+key+, +value+| ...}
public each_key ()
public each_name () {|+key+| ...}
public each_value ( {|+value+| ...}
public fetch (key, *args) {|+key+| ...}
public form_data= (params, sep = '&')
public get_fields (key)
public initialize_http_header (initheader)
public key? (key)
public main_type ()
public proxy_basic_auth (account, password)
public range ()
public range= (r, e = nil)
public range_length ()
public set_content_type (type, params = {})
public set_form_data (params, sep = '&')
public set_range (r, e = nil)
public sub_type ()
public to_hash ()
public type_params ()

Instance Method Detail

[](key)

Returns the header field corresponding to the case-insensitive key. For example, a key of "Content-Type" might return "text/html"

[]=(key, val)

Sets the header field corresponding to the case-insensitive key.

add_field(key, val)

[Ruby 1.8.3] Adds header field instead of replace. Second argument val must be a String. See also #[]=, #[] and get_fields.

  request.add_field 'X-My-Header', 'a'
  p request['X-My-Header']              #=> "a"
  p request.get_fields('X-My-Header')   #=> ["a"]
  request.add_field 'X-My-Header', 'b'
  p request['X-My-Header']              #=> "a, b"
  p request.get_fields('X-My-Header')   #=> ["a", "b"]
  request.add_field 'X-My-Header', 'c'
  p request['X-My-Header']              #=> "a, b, c"
  p request.get_fields('X-My-Header')   #=> ["a", "b", "c"]

basic_auth(account, password)

Set the Authorization: header for "Basic" authorization.

canonical_each()

Alias for each_capitalized

chunked?()

Returns "true" if the "transfer-encoding" header is present and set to "chunked". This is an HTTP/1.1 feature, allowing the the content to be sent in "chunks" without at the outset stating the entire content length.

content_length()

Returns an Integer object which represents the Content-Length: header field or nil if that field is not provided.

content_length=(len)

content_range()

Returns a Range object which represents Content-Range: header field. This indicates, for a partial entity body, where this fragment fits inside the full entity body, as range of byte offsets.

content_type()

Returns a content type string such as "text/html". This method returns nil if Content-Type: header field does not exist.

content_type=(type, params = {})

Alias for set_content_type

delete(key)

Removes a header field.

each(

Alias for each_header

each_capitalized() {|capitalize(k), v.join(', ')| ...}

As for each_header, except the keys are provided in capitalized form.

each_capitalized_name() {|+key+| ...}

Iterates for each capitalized header names.

each_header( {|+key+, +value+| ...}

Iterates for each header names and values.

each_key()

Alias for each_name

each_name() {|+key+| ...}

Iterates for each header names.

each_value( {|+value+| ...}

Iterates for each header values.

fetch(key, *args) {|+key+| ...}

Returns the header field corresponding to the case-insensitive key. Returns the default value args, or the result of the block, or nil, if there‘s no header field named key. See Hash#fetch

form_data=(params, sep = '&')

Alias for set_form_data

get_fields(key)

[Ruby 1.8.3] Returns an array of header field strings corresponding to the case-insensitive key. This method allows you to get duplicated header fields without any processing. See also #[].

  p response.get_fields('Set-Cookie')
    #=> ["session=al98axx; expires=Fri, 31-Dec-1999 23:58:23",
         "query=rubyscript; expires=Fri, 31-Dec-1999 23:58:23"]
  p response['Set-Cookie']
    #=> "session=al98axx; expires=Fri, 31-Dec-1999 23:58:23, query=rubyscript; expires=Fri, 31-Dec-1999 23:58:23"

initialize_http_header(initheader)

key?(key)

true if key header exists.

main_type()

Returns a content type string such as "text". This method returns nil if Content-Type: header field does not exist.

proxy_basic_auth(account, password)

Set Proxy-Authorization: header for "Basic" authorization.

range()

Returns an Array of Range objects which represents Range: header field, or nil if there is no such header.

range=(r, e = nil)

Alias for set_range

range_length()

The length of the range represented in Content-Range: header.

set_content_type(type, params = {})

Set Content-Type: header field by type and params. type must be a String, params must be a Hash.

set_form_data(params, sep = '&')

Set header fields and a body from HTML form data. params should be a Hash containing HTML form data. Optional argument sep means data record separator.

This method also set Content-Type: header field to application/x-www-form-urlencoded.

set_range(r, e = nil)

Set Range: header from Range (arg r) or beginning index and length from it (arg idx&len).

  req.range = (0..1023)
  req.set_range 0, 1023

sub_type()

Returns a content type string such as "html". This method returns nil if Content-Type: header field does not exist or sub-type is not given (e.g. "Content-Type: text").

to_hash()

Returns a Hash consist of header names and values.

type_params()

Returns content type parameters as a Hash as like {"charset" => "iso-2022-jp"}.