Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can you alter what is sent back? #4

Open
myers opened this issue Mar 22, 2018 · 1 comment
Open

How can you alter what is sent back? #4

myers opened this issue Mar 22, 2018 · 1 comment

Comments

@myers
Copy link

myers commented Mar 22, 2018

I would like to create a blacklisting MITM proxy, where at initialization time I give a list of hosts, and when a request (http/https) is made to that host, the proxy just returns an empty document and status code 200.

This is to be used as a way to filter out all the tracking cookies while running rspec feature test with headless chrome.

If this is possible perhaps add directions for it in the readme.md?

Thanks!

@myers
Copy link
Author

myers commented Mar 23, 2018

I made what I want, not sure if this use case interests you:

require 'evil-proxy'

EvilProxy::AgentProxyServer.class_eval do
  
  alias perform_proxy_request_without_hijack perform_proxy_request
  def perform_proxy_request(req, res, &block)
    puts req.host.inspect
    if req.host == "localhost"
      perform_proxy_request_without_hijack(req, res, &block)
    else
      res.status = 200
      res.body = ""
      res['proxy-connection'] = "close"
      res['connection'] = "close"
      res['content-type'] = "text/plain"        
    end
  end
end
    
class EvilerProxy < EvilProxy::MITMProxyServer
  alias perform_proxy_request_without_hijack perform_proxy_request
  def perform_proxy_request(req, res, &block)
    puts req.host.inspect
    if req.host == "localhost"
      perform_proxy_request_without_hijack(req, res, &block)
    else
      res.status = 200
      res.body = ""
      res['proxy-connection'] = "close"
      res['connection'] = "close"
      res['content-type'] = "text/plain"        
    end
  end
end

proxy = EvilerProxy.new Port: 8080

trap "INT"  do proxy.shutdown end
trap "TERM" do proxy.shutdown end

proxy.start

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant