Skip to content

Instantly share code, notes, and snippets.

@xiaocong
Forked from anjackson/gist:2888380
Created October 15, 2013 08:50
Show Gist options
  • Select an option

  • Save xiaocong/6988640 to your computer and use it in GitHub Desktop.

Select an option

Save xiaocong/6988640 to your computer and use it in GitHub Desktop.

Revisions

  1. xiaocong revised this gist Dec 9, 2013. No changes.
  2. @anjackson anjackson created this gist Jun 7, 2012.
    40 changes: 40 additions & 0 deletions gistfile1.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    import bottle
    from wsgiproxy.app import WSGIProxyApp

    # Remove "hop-by-hop" headers (as defined by RFC2613, Section 13)
    # since they are not allowed by the WSGI standard.
    FILTER_HEADERS = [
    'Connection',
    'Keep-Alive',
    'Proxy-Authenticate',
    'Proxy-Authorization',
    'TE',
    'Trailers',
    'Transfer-Encoding',
    'Upgrade',
    ]

    root = bottle.Bottle()
    proxy_app = WSGIProxyApp("http://localhost/")

    def wrap_start_response(start_response):
    def wrapped_start_response(status, headers_out):
    # Remove "hop-by-hop" headers
    headers_out = [(k,v) for (k,v) in headers_out
    if k not in FILTER_HEADERS]
    return start_response(status, headers_out)
    return wrapped_start_response


    def wrapped_proxy_app(environ, start_response):
    start_response = wrap_start_response(start_response)
    return proxy_app(environ, start_response)

    root.mount(wrapped_proxy_app,"/proxytest")

    @root.route('/hello/:name')
    def index(name='World'):
    return '<b>Hello %s!</b>' % name

    bottle.debug(True)
    bottle.run(app=root, host='localhost', port=8080)