Code Monkey home page Code Monkey logo

devproxy's Introduction

devproxy

What is devproxy?

devproxy is intended to be an easily configurable forward HTTP proxy for web application development.

It has the following features:

  • URL rewriting

    If you want to get your browser to access to the upstream HTTP server listening on 127.0.0.1:3000 by a request to http://example.com, the configuration should look as follows:

    hosts:
      http://example.com:
        - ^(/.*)$: http://127.0.0.1:3000$1
    

    This can be done since the name resolution is done in devproxy, which is configured to map any request for http://example.com to http://127.0.0.1:3000.

  • Transparent TLS termination / wrapping (simulation of an SSL/TLS-enabled environment)

    You can also make it possible to direct the request to https://example.com/ to the upstream by adding the configuration like the following:

    hosts:
      http://example.com:
        - ^(/.*)$: http://127.0.0.1:3000$1
      https://example.com:
        - ^(/.*)$: http://127.0.0.1:3000$1
    

    Even though you don't have a valid certificate prepared for example.com, devproxy automatically generates it on the fly. However, it is necessary to set up the private PKI for issuing bogus server certificates and let your browser trust the PKI's root CA certificate. DO IT ON YOUR OWN RISK.

    The CA for issuing bogus server certificates is configured as follows:

    tls:
      ca:
        cert: testca.rsa.crt.pem
        key: testca.rsa.key.pem
    hosts:
      ...
    
  • Request header modification

    You can add / remove arbitrary request HTTP headers for the request being rewritten:

    hosts:
      http://example.com:
        - ^(/.*)$: http://127.0.0.1:3000$1
          headers:
            X-Forwarded-Proto: https
            Removed-Header: null
    
  • Testing FastCGI-enabled upstream

    You can forward the request to a FastCGI-enabled upstream:

    hosts:
      http://example.com:
        - ^(((?:/.*)*/[^/]+\.php)(/.*|$)): fastcgi://localhost$1
          headers:
            X-Cgi-Script-Filename: /var/www/document/root$2
            X-Cgi-Script-Name: $2
            X-Cgi-Path-Info: $3
    
  • Serving files on the filesystem

    You can also serve the local files by specifying file: scheme as an upstream:

    hosts:
      http://example.com:
        - ^(/.*)?/$: file:///some-document-root$1/index.html
        - ^(/.*)$: file:///some-document-root$1
    

    WARNING: this feature does such naive path translation that is easily exploitable for path traversals beyond the document root. Never expose the server to public when it is used.

    file_tx:
      root: /var/empty
      mime_type_file: /usr/share/mime/globs
      mime_type_file_format: xdg-globs
    

    Toplevel file_tx section configures the file transport.

    • root (string, optional)

      Specifies the base directory for resolving a absolute path when a relative form of file URI yields from the match.

    • mime_type_file (string, optional)

      Specifies the path to the MIME-type-to-extension mapping file used to deduce a MIME type from the file's extension.

      devproxy will use Go's standard mime.TypeForExtension() function when unspecified.

    • mime_type_file_format (string, optional)

      Specifies the format for the MIME type file. Accepted values are apache and xdg-globs.

  • Proxy chaining

    You can direct outgoing requests to another proxy server. This is useful in a restricted network environment.

    proxy:
      http: http://anoother-proxy-server:8080
      https: http://another-proxy-server:8080
    

    excluded directive can be used when you want to prevent requests for the specific hosts from being proxied.

    excluded: 
      - 127.0.0.1
      - localhost
      - intranet.example.com
    

    Or inversely, in case of whitelisting:

    included:
      - intranet.example.com
      - foobar.example.com
    

    TLS proxy can also be specified.

    proxy:
      http: https://anoother-proxy-server:8443
      https: https://another-proxy-server:8443
      tls:
        ca_certs: cabundle.crt.pem
        certs:
          - cert: client_crt.pem # this can be either the filename of a PEM-formatted certificate or a PEM string itself.
            key: client_key.pem # this can be either the filename of a PEM-formatted private key or a PEM string itself.
    

Installation

go get github.com/moriyoshi/devproxy

Using devproxy

$GOPATH/bin/devproxy -l listen_addr configuration_file
# ex: $GOPATH/bin/devproxy -l 127.0.0.1:8080 config.yml

And Adjust your browser's proxy settings to what is exactly given to -l option.

Setting up the private PKI

openssl genrsa 2048 > testca.rsa.key.pem
openssl req -new -key testca.rsa.key.pem -out testca.rsa.csr.pem
openssl x509 -req -in testca.rsa.csr.pem -signkey testca.rsa.key.pem -days 3650 -sha256 -extfile x509.ini -extensions CA -out testca.rsa.crt.pem

x509.ini:

[CA]
basicConstraints=critical,CA:TRUE,pathlen:1
keyUsage=digitalSignature,keyCertSign,cRLSign

Configuration file example

tls:
  client:
    verify: true
  ca:
    cert: testca.rsa.crt.pem
    key: testca.rsa.key.pem

hosts:
  http://api.example.com:
    - ^(/v1/.*)$: http://localhost:8000$1
    - ^(/v2/.*)$: http://localhost:8001$1
  http://example.com:
    - ^(/asset.*)$: http://localhost:8002$1
    - ^(/.*)$: http://localhost:8003$1

devproxy's People

Contributors

iakio avatar mattn avatar mopemope avatar moriyoshi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

devproxy's Issues

Allow empty hosts section

  • It would be handy if one can run devproxy without dummy configurations to use it as a simple forward proxy.

Cipher spec support

Hi,

I thought it would be nice to be able to test various TLS implementations when running test sites through devproxy.
Is there any way to tweak SSL/TLS specifications?
I would like to do something like this:

# This example is in LDAP style but it's really up to the developer.
tls:
  version: !1.0:1.1:1.2
  ciphers: HIGH:MEDIUM:!MD5:!RC4:!3DES

Thanks.

Help HTTP over TCP TUNNEL.

Hello @moriyoshi

i am from America, it is possible with your knowledge create a HTTP over TCP tunnel to bypass my isp provider on GO ?
because HTTPS or TLS or SSL is blocks by my ISP provider.

i think it is difficul for me .
i did all the test to check the isp restrictions.

my telegram is : @Trader_Nelson

i will wait your response.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.