-
Notifications
You must be signed in to change notification settings - Fork 0
/
wsgi.py
28 lines (23 loc) · 1005 Bytes
/
wsgi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from flask import Flask, request, make_response
import requests
TARGET = 'https://accounts.google.com/'
app = Flask(__name__, static_folder=None)
@app.route('/', defaults={'path': ''})
@app.route('/<path:path>', methods=['GET', 'POST'])
def proxy(path):
if request.method == 'GET':
r = requests.get(TARGET + path, cookies=request.cookies)
if request.method == 'POST':
s = request.headers['Referer']
referer = TARGET + s.split('//', maxsplit=1)[1].split('/', maxsplit=1)[1]
headers = {
'Origin': request.headers['Origin'],
'Content-Type': request.headers['Content-Type'],
'Referer': referer,
}
r = requests.post(TARGET + path, data=request.form, headers=headers, cookies=request.cookies)
response = make_response(r.content, r.status_code)
for key, value in r.cookies.items():
response.set_cookie(key, value)
response.headers['Content-Type'] = r.headers['Content-Type']
return response