title: uwsgi/nginx configuration for chunked response
body: <p>I have two endpoints like below:</p>
  
  <blockquote>
    <p>GET on /api/v1/foo</p>
    
    <p>POST on /api/v1/foo</p>
  </blockquote>
  
  <p>I need the POST implementation to send back chunked responses using HTTP/1.1 chuked-tranfer encoding however the GET endpoint should send plain JSON</p>
  
  <p>My setup is <code>nginx -&gt; uwsgi -&gt; flask</code>.</p>
  
  <p>I see some of my chunks currently getting truncated at a hex size of <code>1000</code> which is <code>4K</code> in bytes and not the same as my flask layer sent it. Probably because I'm missing some nginx or uwsgi configuration.</p>
  
  <p>uwsgi configuration(uwsgi.ini):</p>
  
  <pre><code>[uwsgi]
  route = ^/api/v1/foo$ goto:dochunked
  route-run = last:
  
  route-label = dochunked
  route-if = equal:$\{REQUEST_METHOD\};POST goto:dopostchunked
  route-run = last:
  
  route-label = dopostchunked
  route-run = chunked:
  </code></pre>
  
  <p>nginx configuration:</p>
  
  <pre><code>location / {
      uwsgi_pass unix:var/uwsgi.sock;
      uwsgi_read_timeout 600; 
      include uwsgi_params;   
  }
  
  location /api/v1/foo {   
      uwsgi_pass unix:var/uwsgi.sock;
      uwsgi_read_timeout 600; 
      include uwsgi_params;   
  
      if ($request_method = "POST" ) {
          set $chunked_transfer_encoding on;
          add_header X-Accel-Buffering no;
      }
  }
  </code></pre>
  
  <p>curl response headers</p>
  
  <pre><code>HTTP/1.1 200 OK
  Server: nginx/1.10.1
  Date: Wed, 03 Jan 2018 00:06:50 GMT
  Content-Type: text/plain
  Transfer-Encoding: chunked
  Connection: keep-alive
  X-Frame-Options: deny
  X-Content-Type-Options: nosniff
  X-XSS-Protection: 1; mode=block
  X-Accel-Buffering: no
  </code></pre>