Class: HTTP::Message::Headers
- Inherits:
-
Object
- Object
- HTTP::Message::Headers
- Defined in:
- lib/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::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
- #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
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/http-access2/http.rb', line 116 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.
74 75 76 |
# File 'lib/http-access2/http.rb', line 74 def body_charset @body_charset end |
#body_date ⇒ Object
A milestone of body.
78 79 80 |
# File 'lib/http-access2/http.rb', line 78 def body_date @body_date end |
#body_size ⇒ Object
Size of body.
76 77 78 |
# File 'lib/http-access2/http.rb', line 76 def body_size @body_size end |
#body_type ⇒ Object
Content-type.
72 73 74 |
# File 'lib/http-access2/http.rb', line 72 def body_type @body_type end |
#chunked ⇒ Object (readonly)
Chunked or not.
80 81 82 |
# File 'lib/http-access2/http.rb', line 80 def chunked @chunked end |
#http_version ⇒ Object
HTTP version string in a HTTP header.
70 71 72 |
# File 'lib/http-access2/http.rb', line 70 def http_version @http_version end |
#reason_phrase ⇒ Object
HTTP status reason phrase.
86 87 88 |
# File 'lib/http-access2/http.rb', line 86 def reason_phrase @reason_phrase end |
#request_method ⇒ Object (readonly)
Request method.
82 83 84 |
# File 'lib/http-access2/http.rb', line 82 def request_method @request_method end |
#request_uri ⇒ Object (readonly)
Requested URI.
84 85 86 |
# File 'lib/http-access2/http.rb', line 84 def request_uri @request_uri end |
#request_via_proxy ⇒ Object
Returns the value of attribute request_via_proxy.
150 151 152 |
# File 'lib/http-access2/http.rb', line 150 def request_via_proxy @request_via_proxy end |
#response_status_code ⇒ Object
Returns the value of attribute response_status_code.
152 153 154 |
# File 'lib/http-access2/http.rb', line 152 def response_status_code @response_status_code end |
Instance Method Details
#[](key) ⇒ Object
205 206 207 |
# File 'lib/http-access2/http.rb', line 205 def [](key) get(key).collect { |item| item[1] } end |
#[]=(key, value) ⇒ Object
201 202 203 |
# File 'lib/http-access2/http.rb', line 201 def []=(key, value) set(key, value) end |
#contenttype ⇒ Object
158 159 160 |
# File 'lib/http-access2/http.rb', line 158 def contenttype self['content-type'][0] end |
#contenttype=(contenttype) ⇒ Object
162 163 164 |
# File 'lib/http-access2/http.rb', line 162 def contenttype=(contenttype) self['content-type'] = contenttype end |
#dump(dev = '') ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/http-access2/http.rb', line 176 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
193 194 195 196 197 198 199 |
# File 'lib/http-access2/http.rb', line 193 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
133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/http-access2/http.rb', line 133 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
145 146 147 148 |
# File 'lib/http-access2/http.rb', line 145 def init_response(status_code) @is_request = false self.response_status_code = status_code end |
#set(key, value) ⇒ Object
189 190 191 |
# File 'lib/http-access2/http.rb', line 189 def set(key, value) @header_item.push([key, value]) end |