title: Flask development server with X-Sendfile
body: <p>I have a Flask application that will run under Apache in production. I have some static files, but they require authenticated access. So using X-Sendfile seemed reasonable to speed up the file delivery after authentication:</p>
  
  <pre><code>flaskapp = flask.Flask()
  flaskapp.use_x_sendfile = True
  </code></pre>
  
  <p>Then where I'm generating the response:</p>
  
  <pre><code>return flask.send_file(filepath)
  </code></pre>
  
  <p>It seems to work fine under Apache. The problem is when I run the development server:</p>
  
  <pre><code># Use SharedDataMiddleware to deliver JS, CSS, icons, etc.
  flaskapp.wsgi_app = SharedDataMiddleware(flaskapp.wsgi_app, {'/static': '/path/to/static'})
  flaskapp.run(host='0.0.0.0', debug=True)
  </code></pre>
  
  <p>When I run it this way with <code>use_x_sendfile = True</code>, the X-Sendfile header shows up in the actual response and an empty file (0 byte) is delivered to the client. Turning off X-Sendfile (and forcing the browser to discard the cached file) fixes the issue, so it seems the Werkzeug server Flask runs isn't processing the X-Sendfile header. Is there a way to enable the development server to process X-Sendfile, or am I forced to turn this off during development?</p>