Skip to content

Simple helpers for stubbing a proxied server #7

@jbodah

Description

@jbodah

Hey, thanks for this repo! It's been really useful for stubbing out some JS files with local versions without having to do tons of data setup

Right now I'm doing something like the following to stub out some requests on a proxied host. I'd love to know if 1) there is an easier way to do this or 2) you'd be open to me adding some helpers to streamline this:

require 'evil-proxy'

proxy = EvilProxy::MITMProxyServer.new Port: 8080, MITMPattern: /my\.server\.com/

proxy.after_mitm do |req, res|
  # Hook into the created MITM server and prepend functionality to the GET handler
  @mitm_servers["my.server.com"].singleton_class.class_eval do
    def do_GET(req, res)
      if req.path =~ /some.*.file/
        res.body = "hello world"
      else
        super
      end
    end
  end
end

proxy.start

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions