Object
Represents HTTP message header.
$KCODE to charset mapping definition.
Placeholder URI object for nil uri.
HTTP response status code to reason phrase mapping definition.
Creates a Message::Headers. Use init_request, init_response, or init_connect_request for acutual initialize.
# File lib/httpclient/http.rb, line 153 def initialize @http_version = 1.1 @body_size = nil @chunked = false @request_method = nil @request_uri = nil @request_query = nil @request_via_proxy = nil @status_code = nil @reason_phrase = nil @body_type = nil @body_charset = nil @body_date = nil @is_request = nil @header_item = [] @dumped = false end
Returns an Array of header values for the given key.
# File lib/httpclient/http.rb, line 284 def [](key) get(key).collect { |item| item[1] } end
Adds a header. See set.
# File lib/httpclient/http.rb, line 279 def []=(key, value) set(key, value) end
Adds a header. Addition order is preserved.
# File lib/httpclient/http.rb, line 239 def add(key, value) if value.is_a?(Array) value.each do |v| @header_item.push([key, v]) end else @header_item.push([key, value]) end end
Returns an Array of all headers.
# File lib/httpclient/http.rb, line 268 def all @header_item end
Sets byte size of message body. body_size == nil means that the body is_a? IO
# File lib/httpclient/http.rb, line 220 def body_size=(body_size) @body_size = body_size end
Returns 'Content-Type' header value.
# File lib/httpclient/http.rb, line 208 def contenttype self['Content-Type'][0] end
Sets 'Content-Type' header value. Overrides if already exists.
# File lib/httpclient/http.rb, line 213 def contenttype=(contenttype) delete('Content-Type') self['Content-Type'] = contenttype end
Deletes headers of the given key.
# File lib/httpclient/http.rb, line 273 def delete(key) key = key.upcase @header_item.delete_if { |k, v| k.upcase == key } end
Dumps message header part and returns a dumped String.
# File lib/httpclient/http.rb, line 225 def dump set_header str = nil if @is_request str = request_line else str = response_status_line end str + @header_item.collect { |key, value| "#{ key }: #{ value }#{ CRLF }" }.join end
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.
# File lib/httpclient/http.rb, line 258 def get(key = nil) if key.nil? all else key = key.upcase @header_item.find_all { |k, v| k.upcase == key } end end
Initialize this instance as a CONNECT request.
# File lib/httpclient/http.rb, line 176 def init_connect_request(uri) @is_request = true @request_method = 'CONNECT' @request_uri = uri @request_query = nil @http_version = 1.0 end
Initialize this instance as a general request.
# File lib/httpclient/http.rb, line 187 def init_request(method, uri, query = nil) @is_request = true @request_method = method @request_uri = uri || NIL_URI @request_query = query @request_via_proxy = false end
Initialize this instance as a response.
# File lib/httpclient/http.rb, line 196 def init_response(status_code) @is_request = false self.status_code = status_code end
Generated with the Darkfish Rdoc Generator 2.