From 91f66dd593f03cf688bc5612b6abbb43df571456 Mon Sep 17 00:00:00 2001 From: Murilo Santana Date: Fri, 26 Feb 2016 16:51:26 -0300 Subject: [PATCH] handle DELETE requests --- lib/bettercap/proxy/stream_logger.rb | 5 +++-- lib/bettercap/proxy/streamer.rb | 9 ++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/bettercap/proxy/stream_logger.rb b/lib/bettercap/proxy/stream_logger.rb index 5565c174..15252778 100644 --- a/lib/bettercap/proxy/stream_logger.rb +++ b/lib/bettercap/proxy/stream_logger.rb @@ -144,7 +144,8 @@ def self.log_post( request ) # Log a HTTP ( HTTPS if +is_https+ is true ) stream performed by the +client+ # with the +request+ and +response+ most important informations. def self.log_http( request, response ) - response_s = "( #{response.content_type} )" + response_s = "" + response_s += " ( #{response.content_type} )" unless response.content_type.nil? request_s = request.to_url( request.post?? nil : @@MAX_REQ_SIZE ) code = response.code.to_s[0] @@ -154,7 +155,7 @@ def self.log_http( request, response ) response_s += " [#{response.code}]" end - Logger.raw "[#{self.addr2s(request.client)}] #{request.method.light_blue} #{request_s} #{response_s}" + Logger.raw "[#{self.addr2s(request.client)}] #{request.method.light_blue} #{request_s}#{response_s}" # Log post body if the POST sniffer is enabled. if Context.get.post_sniffer_enabled? self.log_post( request ) diff --git a/lib/bettercap/proxy/streamer.rb b/lib/bettercap/proxy/streamer.rb index be07d244..40319847 100644 --- a/lib/bettercap/proxy/streamer.rb +++ b/lib/bettercap/proxy/streamer.rb @@ -61,7 +61,7 @@ def handle( request, client, redirects = 0 ) response = r end - if response.textual? + if response.textual? or request.method == 'DELETE' StreamLogger.log_http( request, response ) else Logger.debug "[#{request.client}] -> #{request.to_url} [#{response.code}]" @@ -187,6 +187,13 @@ def do_HEAD(req, res) end end + # Handle a DELETE request, +req+ is the request object and +res+ the response. + def do_DELETE(req, res) + perform_proxy_request(req, res) do |http, path, header| + http.delete(path, header) + end + end + # Handle a POST request, +req+ is the request object and +res+ the response. def do_POST(req, res) perform_proxy_request(req, res) do |http, path, header|