include/response.rb in http2-0.0.28 vs include/response.rb in http2-0.0.29
- old
+ new
@@ -5,11 +5,11 @@
attr_accessor :body, :charset, :code, :content_type, :http_version
#This method should not be called manually.
def initialize(args = {})
@args = args
- @args[:headers] = {} if !@args.key?(:headers)
+ @args[:headers] = {} unless @args.key?(:headers)
@body = args[:body] || ""
@debug = @args[:debug]
end
#Returns headers given from the host for the result.
@@ -29,11 +29,11 @@
#Returns true if a header of the given string exists.
#===Examples
# print "No content-type was given." if !http.header?("content-type")
def header?(key)
- return true if @args[:headers].key?(key) and @args[:headers][key].first.to_s.length > 0
+ return true if @args[:headers].key?(key) && @args[:headers][key].first.to_s.length > 0
return false
end
def content_length
header("content-length").to_i if header?("content-length")
@@ -41,33 +41,33 @@
#Returns the requested URL as a string.
#===Examples
# res.requested_url #=> "?show=status&action=getstatus"
def requested_url
- raise "URL could not be detected." if !@args[:request_args][:url]
+ raise "URL could not be detected." unless @args[:request_args][:url]
return @args[:request_args][:url]
end
# Checks the data that has been sat on the object and raises various exceptions, if it does not validate somehow.
def validate!
puts "Http2: Validating response length." if @debug
validate_body_versus_content_length!
end
- private
+private
# Checks that the length of the body is the same as the given content-length if given.
def validate_body_versus_content_length!
unless self.header?("content-length")
puts "Http2: No content length given - skipping length validation." if @debug
return nil
end
- content_length = self.header("content-length").to_i
+ content_length = header("content-length").to_i
body_length = @body.bytesize
puts "Http2: Body length: #{body_length}" if @debug
puts "Http2: Content length: #{content_length}" if @debug
raise "Body does not match the given content-length: '#{body_length}', '#{content_length}'." if body_length != content_length
end
-end
\ No newline at end of file
+end