proxy.py 938 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
import requests
import gluon.contrib.simplejson

if request.env.http_origin:
    response.headers['Access-Control-Allow-Origin'] = request.env.http_origin
    response.headers['Access-Control-Allow-Credentials'] = 'true'
    response.headers['Access-Control-Max-Age'] = 86400


def index():
    return gluon.contrib.simplejson.dumps("index()")

Mikaël Salson's avatar
Mikaël Salson committed
13
def proxy_request(url, headers):
14 15
    if request.env.request_method == "POST":
        payload = dict(request.post_vars)
16 17 18
        
        if 'Session' in payload.keys():
            del payload['Session']
Mikaël Salson's avatar
Mikaël Salson committed
19 20

        response = requests.post(url, headers = headers, data=payload)
21 22 23 24 25 26
        if response.status_code == requests.codes.ok:
            return response
        return gluon.contrib.simplejson.dumps("the site returned an invalid response")
    return gluon.contrib.simplejson.dumps("improper method")
   

Mikaël Salson's avatar
Mikaël Salson committed
27 28
def imgt():
    return proxy_request("http://www.imgt.org/IMGT_vquest/analysis")
29