lib/ronin/cli/commands/http.rb in ronin-2.0.0.beta5 vs lib/ronin/cli/commands/http.rb in ronin-2.0.0

- old
+ new

@@ -264,10 +264,15 @@ # Additional URL query params. # # @return [Hash{String => String}] attr_reader :query_params + # The body to send with the request. + # + # @return [String, nil] + attr_reader :body + # Form data. # # @return [Hash{String => String}] attr_reader :form_data @@ -321,26 +326,26 @@ # The URL to request. # def process_value(url) url = URI(url) - response = begin - Support::Network::HTTP.request( - @http_method, url, proxy: @proxy, - user_agent: @user_agent, - user: url.user, - password: url.password, - query_params: @query_params, - headers: @headers, - body: @body, - form_data: @form_data - ) - rescue => error - print_error(error.message) - exit(1) - end - - print_response(response) + Support::Network::HTTP.request( + @http_method, url, proxy: @proxy, + user_agent: @user_agent, + user: url.user, + password: url.password, + query_params: @query_params, + headers: @headers, + body: @body, + form_data: @form_data + ) do |response| + # NOTE: we must call HTTP.request with a block to avoid causing + # #read_body to be called twice. + print_response(response) + end + rescue => error + print_error(error.message) + exit(1) end # # Prints the HTTP response. #