-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheaders.py
49 lines (30 loc) · 872 Bytes
/
headers.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
from flask import json
from flask import Flask
from flask import request
app = Flask(__name__)
# @app.route('/hello')
#
# def api_hello():
#
# if 'name' in request.args:
#
# return 'Hello' + request.args['name']
#
# else:
#
# return 'Sorry,no name'
@app.route('/messages', methods=['POST'])
def api_message():
if request.headers['Content-Type'] == 'text/plain':
return "Text Message: " + request.data
elif request.headers['Content-Type'] == 'application/json':
return "JSON Message:" + json.dumps(request.json)
elif request.headers['Content-Type'] == 'application/octet-stream':
f = open('./binary', 'wb')
f.write(request.data)
f.close()
return "Binary message written!"
else:
return "415 Unsupported Media Type ;)"
if __name__ == '__main__':
app.run()