title: Sending Response to OPTIONS in Python Flask application
body: <p>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.</p>
  
  <pre><code>#!/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 &lt; 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)
  </code></pre>
  
  <p>However whenever I try to trigger an event to be pushed to the above listener.It seems that I am getting <code>OPTIONS</code> instead of <code>POST</code>. </p>
  
  <pre><code>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 -
  </code></pre>
  
  <p>The investigation of my client revealed that it expects the following flags in its <code>response</code> to <code>OPTIONS</code>.</p>
  
  <pre><code>Access-Control-Allow-Origin          value_1
  Access-Control-Allow-Methods         value_2      
  Access-Control-Allow-Headers         value_3
  </code></pre>
  
  <p>How do I format the above <code>response</code> to <code>OPTIONS</code> so that my server can start receiving <code>POST</code> messages from the client. </p>