Class | HTTP::Message |
In: |
lib/httpclient/http.rb
|
Parent: | Object |
Represents a HTTP message. A message is for a request or a response.
Request message is generated from given parameters internally so users don‘t need to care about it. Response message is the instance that methods of HTTPClient returns so users need to know how to extract HTTP response data from Message.
Some attributes are only for a request or a response, not both.
res = clnt.get(url) p res.content #=> String
res = clnt.get(url) p res.status #=> 200, 501, etc. (Integer)
res = clnt.get(url) res.header['set-cookie'].each do |value| p value end assert_equal(1, res.header['last-modified'].size) p res.header['last-modified'].first
CRLF | = | "\r\n" |
mime_type_handler= | -> | set_mime_type_func |
For backward compatibility. | ||
mime_type_handler | -> | get_mime_type_func |
body | [R] |
|
||
header | [RW] |
|
||
peer_cert | [RW] |
|
Returns true if the given object is a File. In HTTPClient, a file is;
Sets MIME type handler.
handler must respond to :call with a single argument :path and returns a MIME type String e.g. ‘text/html’. When the handler returns nil or an empty String, ‘application/octet-stream’ is used.
When you set nil to the handler, internal_mime_type is used instead. The handler is nil by default.
Creates a Message instance of general request.
method: | HTTP method String. |
uri: | an URI object which represents an URL of web resource. |
query: | a Hash or an Array of query part of URL. e.g. { "a" =>
"b" } => ‘host/part?a=b’ Give an array to pass
multiple value like
|
body: | a Hash or an Array of body part. e.g. { "a" => "b" }
=> ‘a=b’. Give an array to pass multiple value like
|
boundary: | When the boundary given, it is sent as a multipart/form-data using this boundary String. |
Creates a Message instance of response.
body: | a String or an IO of response message body. |