I have a python Flask listener waiting on port 8080. I expect another process to make a series of POST's to this port.The code for listener is as follows.
#!/usr/bin/env python2
from __future__ import print_function
from flask import Flask, request
from werkzeug import secure_filename
from datetime import datetime
import os, traceback, sys
import zlib
import ssl
import json
import os
import base64
app = Flask('__name__')
@app.route('/',methods=['GET','POST','OPTIONS'])
def recive_fe_events():
try:
data = request.get_data()
if request.content_length < 20000 and request.content_length != 0:
filename = 'out/{0}.json'.format(str(datetime.now()))
with open(filename, 'w') as f:
f.write(data)
print('Wrote', filename)
else:
print("Request too long", request.content_length)
content = '{{"status": 413, "content_length": {0}, "content": "{1}"}}'.format(request.content_length, data)
return content, 413
except:
traceback.print_exc()
return None, status.HTTP_500_INTERNAL_SERVER_ERROR
return '{"status": 200}\n'
if __name__ == '__main__':
app.run(host='0.0.0.0',debug=False,port=8080)
However whenever I try to trigger an event to be pushed to the above listener.It seems that I am getting OPTIONS
instead of POST
.
192.168.129.75 - - [20/May/2015 14:33:45] "OPTIONS / HTTP/1.1" 200 -
192.168.129.75 - - [20/May/2015 14:33:45] "OPTIONS / HTTP/1.1" 200 -
192.168.129.75 - - [20/May/2015 14:33:51] "OPTIONS / HTTP/1.1" 200 -
192.168.129.75 - - [20/May/2015 14:33:51] "OPTIONS / HTTP/1.1" 200 -
The investigation of my client revealed that it expects the following flags in its response
to OPTIONS
.
Access-Control-Allow-Origin value_1
Access-Control-Allow-Methods value_2
Access-Control-Allow-Headers value_3
How do I format the above response
to OPTIONS
so that my server can start receiving POST
messages from the client.