~nhanb/gae-proxy

4f225109bb699eeebf3636a18c86fcfa8b9d30c6 — Bùi Thành Nhân 2 years ago 7bce960
auth
3 files changed, 14 insertions(+), 1 deletions(-)

A .gitignore
M app.yaml
M main.py
A .gitignore => .gitignore +3 -0
@@ 0,0 1,3 @@
*.pyc
__pycache__
envars.yaml

M app.yaml => app.yaml +3 -0
@@ 6,3 6,6 @@ handlers:
    secure: always
    redirect_http_response_code: 301
    script: auto

includes:
  - envars.yaml

M main.py => main.py +8 -1
@@ 5,6 5,7 @@ from bottle import HTTPResponse, request, route, run

# GAE recommended
PORT = os.environ.get("PORT", 8080)
PASSWORD = os.environ.get("GAEPROXY_PASSWORD", "")

proxiable_methods = {
    "get": requests.get,


@@ 15,7 16,13 @@ proxiable_methods = {
@route("/proxy", method="POST")
def proxy():
    req = request.json
    assert req["method"] in proxiable_methods

    if req["method"] not in proxiable_methods:
        return HTTPResponse(status=400, body="We serve get/post only!")

    if req["password"] != PASSWORD:
        return HTTPResponse(status=400, body="Get off my lawn!")

    requests_func = proxiable_methods[req["method"]]
    requests_kwargs = {"url": req["url"], "headers": req["headers"]}
    if req["method"] == "post":