Class: BetterCap::Proxy::Streamer

Inherits:
Object
  • Object
show all
Defined in:
lib/bettercap/proxy/streamer.rb

Overview

Handle data streaming between clients and servers for the BetterCap::Proxy::Proxy.

Instance Method Summary collapse

Constructor Details

#initialize(processor) ⇒ Streamer

Initialize the class with the given processor routine.


19
20
21
# File 'lib/bettercap/proxy/streamer.rb', line 19

def initialize( processor )
  @processor = processor
end

Instance Method Details

#handle(request, client, is_https) ⇒ Object

Handle the HTTP request from client, if is_https is true it will be forwarded as a HTTPS request.


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/bettercap/proxy/streamer.rb', line 33

def handle( request, client, is_https )
  response = Response.new
  client_ip, client_port = get_client_details( is_https, client )

  Logger.debug "Handling #{request.verb} request from #{client_ip}:#{client_port} ..."

  begin
    self.send( "do_#{request.verb}", request, response )

    if response.textual?
      StreamLogger.log_http( is_https, client_ip, request, response )
    else
      Logger.debug "[#{client_ip}] -> #{request.host}#{request.url} [#{response.code}]"
    end

    @processor.call( request, response )

    client.write response.to_s
  rescue NoMethodError
    Logger.warn "Could not handle #{request.verb} request from #{client_ip}:#{client_port} ..."
  end
end

#rickroll(client) ⇒ Object

Redirect the client to a funny video.


24
25
26
27
28
29
# File 'lib/bettercap/proxy/streamer.rb', line 24

def rickroll( client )
  Logger.warn "#{client_ip} is connecting to us directly."

  client.write "HTTP/1.1 302 Found\n"
  client.write "Location: https://www.youtube.com/watch?v=dQw4w9WgXcQ\n\n"
end