Class: Knj::Http2::Response
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
Instance Method Summary collapse
-
#body ⇒ Object
Returns the complete body of the result as a string.
-
#charset ⇒ Object
Returns the charset of the result.
-
#code ⇒ Object
Returns the code of the result (200, 404, 500 etc).
-
#contenttype ⇒ Object
Returns the content-type of the result as a string.
-
#header(key) ⇒ Object
Returns a certain header by name or false if not found.
-
#header?(key) ⇒ Boolean
Returns true if a header of the given string exists.
-
#headers ⇒ Object
Returns headers given from the host for the result.
-
#http_version ⇒ Object
Returns the HTTP-version of the result.
-
#initialize(args = {}) ⇒ Response
constructor
A new instance of Response.
Constructor Details
#initialize(args = {}) ⇒ Response
Returns a new instance of Response.
601 602 603 604 605 |
# File 'lib/knj/http2.rb', line 601 def initialize(args = {}) @args = args @args[:headers] = {} if !@args.key?(:headers) @args[:body] = "" if !@args.key?(:body) end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
599 600 601 |
# File 'lib/knj/http2.rb', line 599 def args @args end |
Instance Method Details
#body ⇒ Object
Returns the complete body of the result as a string.
Examples
print “Looks like we caught the end of it as well?” if res.body.to_s.downcase.index(“</html>”) != nil
647 648 649 |
# File 'lib/knj/http2.rb', line 647 def body return @args[:body] end |
#charset ⇒ Object
Returns the charset of the result.
652 653 654 |
# File 'lib/knj/http2.rb', line 652 def charset return @args[:charset] end |
#code ⇒ Object
Returns the code of the result (200, 404, 500 etc).
Examples
print “An internal error occurred.” if res.code.to_i == 500
633 634 635 |
# File 'lib/knj/http2.rb', line 633 def code return @args[:code] end |
#contenttype ⇒ Object
Returns the content-type of the result as a string.
Examples
print “This body can be printed - its just plain text!” if http.contenttype == “text/plain”
659 660 661 |
# File 'lib/knj/http2.rb', line 659 def contenttype return @args[:contenttype] end |
#header(key) ⇒ Object
Returns a certain header by name or false if not found.
Examples
val = res.header(“content-type”)
617 618 619 620 |
# File 'lib/knj/http2.rb', line 617 def header(key) return false if !@args[:headers].key?(key) return @args[:headers][key].first.to_s end |
#header?(key) ⇒ Boolean
Returns true if a header of the given string exists.
Examples
print “No content-type was given.” if !http.header?(“content-type”)
625 626 627 628 |
# File 'lib/knj/http2.rb', line 625 def header?(key) return true if @args[:headers].key?(key) and @args[:headers][key].first.to_s.length > 0 return false end |
#headers ⇒ Object
Returns headers given from the host for the result.
Examples
headers_hash = res.headers
610 611 612 |
# File 'lib/knj/http2.rb', line 610 def headers return @args[:headers] end |
#http_version ⇒ Object
Returns the HTTP-version of the result.
Examples
print “We are using HTTP 1.1 and should support keep-alive.” if res.http_version.to_s == “1.1”
640 641 642 |
# File 'lib/knj/http2.rb', line 640 def http_version return @args[:http_version] end |