-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
47 lines (33 loc) · 1.14 KB
/
server.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os
from uuid import uuid4
import logging
from flask import (Flask, render_template, request,
redirect, url_for, make_response)
app = Flask(__name__)
if __name__ != '__main__':
gunicorn_logger = logging.getLogger('gunicorn.error')
app.logger.handlers = gunicorn_logger.handlers
app.logger.setLevel(gunicorn_logger.level)
@app.before_request
def log_headers():
app.logger.debug('Request Headers: \n%s', request.headers)
app.logger.debug('Data: \n%s', request.get_data())
def generate_uuid():
return str(uuid4())
@app.route('/')
def index():
resp = make_response(redirect(url_for('after_cookie_was_set')))
resp.set_cookie('client-reflection-cookie', generate_uuid())
return resp
@app.route('/after-cookie-was-set')
def after_cookie_was_set():
resp = make_response(render_template(
'index.html',
user_agent=request.headers.get('User-Agent'),
ip=request.remote_addr,
headers=dict(request.headers)
))
resp.set_cookie('other-cookie', generate_uuid())
return resp
if __name__ == "__main__":
app.run(host='0.0.0.0', port=os.getenv('PORT') or 31337)