-
Notifications
You must be signed in to change notification settings - Fork 18
/
app.py
executable file
·51 lines (46 loc) · 1.35 KB
/
app.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
48
49
50
51
#!/usr/bin/env python
from os import urandom
from flask import Flask
app = Flask(__name__)
response_cache = dict()
@app.route("/ping")
def hello():
return "pong"
# Returns larger sample JSON from http://json.org/example.html to exercise performance with larger payloads
@app.route("/bigger")
def big_response():
return '''{
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": ["GML", "XML"]
},
"GlossSee": "markup"
}
}
}
}
}'''
@app.route("/length/<int:response_bytes>")
def fix_length_response(response_bytes):
if response_bytes < 1:
raise Exception("Forbidded response length: {0}".format(response_bytes))
try:
response = response_cache[response_bytes]
return response
except KeyError:
response = urandom(response_bytes)
response_cache[response_bytes] = response
return response
if __name__ == "__main__":
app.run()