Class: ZMachine::HttpResponseHeader
- Inherits:
-
Hash
- Object
- Hash
- ZMachine::HttpResponseHeader
- Defined in:
- lib/z-http/http_header.rb
Overview
A simple hash is returned for each request made by HttpClient with the headers that were given by the server for that request.
Instance Attribute Summary collapse
-
#http_reason ⇒ Object
The reason returned in the http response (“OK”,“File not found”,etc.).
-
#http_status ⇒ Object
The status code (as a string!).
-
#http_version ⇒ Object
The HTTP version returned.
-
#raw ⇒ Object
Raw headers.
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#chunked_encoding? ⇒ Boolean
Is the transfer encoding chunked?.
- #client_error? ⇒ Boolean
- #compressed? ⇒ Boolean
-
#content_length ⇒ Object
Length of content as an integer, or nil if chunked/unspecified.
-
#cookie ⇒ Object
Cookie header from the server.
-
#etag ⇒ Object
E-Tag.
- #informational? ⇒ Boolean
- #keepalive? ⇒ Boolean
- #last_modified ⇒ Object
- #location ⇒ Object
- #redirection? ⇒ Boolean
- #server_error? ⇒ Boolean
-
#status ⇒ Object
HTTP response status as an integer.
- #successful? ⇒ Boolean
Instance Attribute Details
#http_reason ⇒ Object
The reason returned in the http response (“OK”,“File not found”,etc.)
6 7 8 |
# File 'lib/z-http/http_header.rb', line 6 def http_reason @http_reason end |
#http_status ⇒ Object
The status code (as a string!)
12 13 14 |
# File 'lib/z-http/http_header.rb', line 12 def http_status @http_status end |
#http_version ⇒ Object
The HTTP version returned.
9 10 11 |
# File 'lib/z-http/http_header.rb', line 9 def http_version @http_version end |
#raw ⇒ Object
Raw headers
15 16 17 |
# File 'lib/z-http/http_header.rb', line 15 def raw @raw end |
Instance Method Details
#[](key) ⇒ Object
59 60 61 |
# File 'lib/z-http/http_header.rb', line 59 def [](key) super(key) || super(key.upcase.gsub('-','_')) end |
#chunked_encoding? ⇒ Boolean
Is the transfer encoding chunked?
43 44 45 |
# File 'lib/z-http/http_header.rb', line 43 def chunked_encoding? /chunked/i === self[HttpClient::TRANSFER_ENCODING] end |
#client_error? ⇒ Boolean
75 76 77 |
# File 'lib/z-http/http_header.rb', line 75 def client_error? 400 <= status && 500 > status end |
#compressed? ⇒ Boolean
51 52 53 |
# File 'lib/z-http/http_header.rb', line 51 def compressed? /gzip|compressed|deflate/i === self[HttpClient::CONTENT_ENCODING] end |
#content_length ⇒ Object
Length of content as an integer, or nil if chunked/unspecified
32 33 34 35 |
# File 'lib/z-http/http_header.rb', line 32 def content_length @content_length ||= ((s = self[HttpClient::CONTENT_LENGTH]) && (s =~ /^(\d+)$/)) ? $1.to_i : nil end |
#cookie ⇒ Object
Cookie header from the server
38 39 40 |
# File 'lib/z-http/http_header.rb', line 38 def self[HttpClient::SET_COOKIE] end |
#etag ⇒ Object
E-Tag
18 19 20 |
# File 'lib/z-http/http_header.rb', line 18 def etag self[HttpClient::ETAG] end |
#informational? ⇒ Boolean
63 64 65 |
# File 'lib/z-http/http_header.rb', line 63 def informational? 100 <= status && 200 > status end |
#keepalive? ⇒ Boolean
47 48 49 |
# File 'lib/z-http/http_header.rb', line 47 def keepalive? /keep-alive/i === self[HttpClient::KEEP_ALIVE] end |
#last_modified ⇒ Object
22 23 24 |
# File 'lib/z-http/http_header.rb', line 22 def last_modified self[HttpClient::LAST_MODIFIED] end |
#location ⇒ Object
55 56 57 |
# File 'lib/z-http/http_header.rb', line 55 def location self[HttpClient::LOCATION] end |
#redirection? ⇒ Boolean
71 72 73 |
# File 'lib/z-http/http_header.rb', line 71 def redirection? 300 <= status && 400 > status end |
#server_error? ⇒ Boolean
79 80 81 |
# File 'lib/z-http/http_header.rb', line 79 def server_error? 500 <= status && 600 > status end |
#status ⇒ Object
HTTP response status as an integer
27 28 29 |
# File 'lib/z-http/http_header.rb', line 27 def status @status ||= Integer(http_status) rescue 0 end |
#successful? ⇒ Boolean
67 68 69 |
# File 'lib/z-http/http_header.rb', line 67 def successful? 200 <= status && 300 > status end |