Class: HTTP::Message::Headers
- Inherits:
-
Object
- Object
- HTTP::Message::Headers
- Defined in:
- lib/rss-client/http-access2/http.rb
Overview
HTTP::Message::Headers – HTTP message header.
DESCRIPTION
A class that describes header part of HTTP message.
Constant Summary collapse
- StatusCodeMap =
{ 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', }
- CharsetMap =
{ 'NONE' => 'us-ascii', 'EUC' => 'euc-jp', 'SJIS' => 'shift_jis', 'UTF8' => 'utf-8', }
Instance Attribute Summary collapse
-
#body_charset ⇒ Object
Charset.
-
#body_date ⇒ Object
A milestone of body.
-
#body_size ⇒ Object
Size of body.
-
#body_type ⇒ Object
Content-type.
-
#chunked ⇒ Object
readonly
Chunked or not.
-
#http_version ⇒ Object
HTTP version string in a HTTP header.
-
#reason_phrase ⇒ Object
HTTP status reason phrase.
-
#request_method ⇒ Object
readonly
Request method.
-
#request_uri ⇒ Object
readonly
Requested URI.
-
#request_via_proxy ⇒ Object
Returns the value of attribute request_via_proxy.
-
#response_status_code ⇒ Object
Returns the value of attribute response_status_code.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #contenttype ⇒ Object
- #contenttype=(contenttype) ⇒ Object
- #delete(key) ⇒ Object
- #dump(dev = '') ⇒ Object
- #get(key = nil) ⇒ Object
- #init_request(method, uri, query = nil, via_proxy = nil) ⇒ Object
- #init_response(status_code) ⇒ Object
-
#initialize ⇒ Headers
constructor
SYNOPSIS HTTP::Message.new.
- #set(key, value) ⇒ Object
Constructor Details
#initialize ⇒ Headers
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/rss-client/http-access2/http.rb', line 137 def initialize @is_request = nil # true, false and nil @http_version = 'HTTP/1.1' @body_type = nil @body_charset = nil @body_size = nil @body_date = nil @header_item = [] @chunked = false @response_status_code = nil @reason_phrase = nil @request_method = nil @request_uri = nil @request_query = nil @request_via_proxy = nil end |
Instance Attribute Details
#body_charset ⇒ Object
Charset.
90 91 92 |
# File 'lib/rss-client/http-access2/http.rb', line 90 def body_charset @body_charset end |
#body_date ⇒ Object
A milestone of body.
94 95 96 |
# File 'lib/rss-client/http-access2/http.rb', line 94 def body_date @body_date end |
#body_size ⇒ Object
Size of body.
92 93 94 |
# File 'lib/rss-client/http-access2/http.rb', line 92 def body_size @body_size end |
#body_type ⇒ Object
Content-type.
88 89 90 |
# File 'lib/rss-client/http-access2/http.rb', line 88 def body_type @body_type end |
#chunked ⇒ Object (readonly)
Chunked or not.
96 97 98 |
# File 'lib/rss-client/http-access2/http.rb', line 96 def chunked @chunked end |
#http_version ⇒ Object
HTTP version string in a HTTP header.
86 87 88 |
# File 'lib/rss-client/http-access2/http.rb', line 86 def http_version @http_version end |
#reason_phrase ⇒ Object
HTTP status reason phrase.
102 103 104 |
# File 'lib/rss-client/http-access2/http.rb', line 102 def reason_phrase @reason_phrase end |
#request_method ⇒ Object (readonly)
Request method.
98 99 100 |
# File 'lib/rss-client/http-access2/http.rb', line 98 def request_method @request_method end |
#request_uri ⇒ Object (readonly)
Requested URI.
100 101 102 |
# File 'lib/rss-client/http-access2/http.rb', line 100 def request_uri @request_uri end |
#request_via_proxy ⇒ Object
Returns the value of attribute request_via_proxy.
171 172 173 |
# File 'lib/rss-client/http-access2/http.rb', line 171 def request_via_proxy @request_via_proxy end |
#response_status_code ⇒ Object
Returns the value of attribute response_status_code.
173 174 175 |
# File 'lib/rss-client/http-access2/http.rb', line 173 def response_status_code @response_status_code end |
Instance Method Details
#[](key) ⇒ Object
231 232 233 |
# File 'lib/rss-client/http-access2/http.rb', line 231 def [](key) get(key).collect { |item| item[1] } end |
#[]=(key, value) ⇒ Object
227 228 229 |
# File 'lib/rss-client/http-access2/http.rb', line 227 def []=(key, value) set(key, value) end |
#contenttype ⇒ Object
179 180 181 |
# File 'lib/rss-client/http-access2/http.rb', line 179 def contenttype self['content-type'][0] end |
#contenttype=(contenttype) ⇒ Object
183 184 185 |
# File 'lib/rss-client/http-access2/http.rb', line 183 def contenttype=(contenttype) self['content-type'] = contenttype end |
#delete(key) ⇒ Object
222 223 224 225 |
# File 'lib/rss-client/http-access2/http.rb', line 222 def delete(key) key = key.upcase @header_item.delete_if { |k, v| k.upcase == key } end |
#dump(dev = '') ⇒ Object
197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/rss-client/http-access2/http.rb', line 197 def dump(dev = '') set_header if @is_request dev << request_line else dev << response_status_line end dev << @header_item.collect { |key, value| dump_line("#{ key }: #{ value }") }.join dev end |
#get(key = nil) ⇒ Object
214 215 216 217 218 219 220 |
# File 'lib/rss-client/http-access2/http.rb', line 214 def get(key = nil) if !key @header_item else @header_item.find_all { |pair| pair[0].upcase == key.upcase } end end |
#init_request(method, uri, query = nil, via_proxy = nil) ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/rss-client/http-access2/http.rb', line 154 def init_request(method, uri, query = nil, via_proxy = nil) @is_request = true @request_method = method @request_uri = if uri.is_a?(URI) uri else URI.parse(uri.to_s) end @request_query = create_query_uri(@request_uri, query) @request_via_proxy = via_proxy end |
#init_response(status_code) ⇒ Object
166 167 168 169 |
# File 'lib/rss-client/http-access2/http.rb', line 166 def init_response(status_code) @is_request = false self.response_status_code = status_code end |
#set(key, value) ⇒ Object
210 211 212 |
# File 'lib/rss-client/http-access2/http.rb', line 210 def set(key, value) @header_item.push([key, value]) end |