lib/ronin/cli/printing/http.rb in ronin-2.0.0.beta4 vs lib/ronin/cli/printing/http.rb in ronin-2.0.0.beta5
- old
+ new
@@ -47,22 +47,22 @@
#
def print_plain_body(response)
last_chunk = nil
response.read_body do |chunk|
- print chunk
+ stdout.write(chunk)
last_chunk = chunk
end
print_last_newline(last_chunk)
end
#
# Returns the syntax lexer for the given `Content-Type` header.
#
- # @param [String] content_type
+ # @param [String, nil] content_type
# The HTTP `Content-Type` header value.
#
# @return [Rouge::Lexers::HTML,
# Rouge::Lexers::XML,
# Rouge::Lexers::JavaScript,
@@ -70,30 +70,31 @@
# Rouge::Lexers::PlainText]
# The specific syntax lexer or `nil` if the `Content-Type` was not
# recognized.
#
def syntax_lexer_for_content_type(content_type)
- syntax_lexer_for(mimetype: content_type.sub(/;.*$/,''))
+ mimetype = content_type && content_type.sub(/;.*$/,'')
+
+ syntax_lexer_for(mimetype: mimetype)
end
#
- # Prints a syntax highlgihted response body.
+ # Prints a syntax highlighted response body.
#
# @param [Net::HTTPResponse] response
# The HTTP response object.
#
def print_highlighted_body(response)
content_type = response['Content-Type']
- is_utf8 = content_type && content_type.include?('charset=utf-8')
lexer = syntax_lexer_for_content_type(content_type)
last_chunk = nil
response.read_body do |chunk|
- chunk.force_encoding(Encoding::UTF_8) if is_utf8
+ chunk.force_encoding(Encoding::UTF_8)
- print @syntax_formatter.format(lexer.lex(chunk))
+ stdout.write(@syntax_formatter.format(lexer.lex(chunk)))
last_chunk = chunk
end
print_last_newline(last_chunk)
@@ -112,10 +113,10 @@
print_plain_body(response)
end
end
#
- # Prints the respnse headers.
+ # Prints the response headers.
#
# @param [Net::HTTPResponse] response
# The HTTP response object.
#
def print_headers(response)