class HTTP::Response

def content_length

Returns:
  • (Integer) - otherwise
  • (nil) - if Content-Length was not given, or it's value was invalid
def content_length
  # http://greenbytes.de/tech/webdav/rfc7230.html#rfc.section.3.3.3
  # Clause 3: "If a message is received with both a Transfer-Encoding
  # and a Content-Length header field, the Transfer-Encoding overrides the Content-Length.
  return nil if @headers.include?(Headers::TRANSFER_ENCODING)
  value = @headers[Headers::CONTENT_LENGTH]
  return nil unless value
  begin
    Integer(value)
  rescue ArgumentError
    nil
  end
end