title: An HTTP POST redirect to HTTPS leads to a data lose?
body: <p>Faced with an issue when a POST request redirected has no Content-Length.</p>
  
  <p>First got this issue with AWS ALB and its 301 for HTTP => HTTPS redirect, and thought it was something with ALB itself.</p>
  
  <p>Then configured just a common NGINX with HTTP 80 server and HTTP 443 server:</p>
  
  <pre><code>server {
  
      listen 80;
      ...
  
      location / {
          return 302 https://example.com$request_uri;
      }
  }
  
  server {
  
      listen       443 ssl;
  ...
      location / {
  
          proxy_pass http://localhost:8081;        
  
          proxy_set_header    Host              $host;
          proxy_set_header    X-Real-IP         $remote_addr;
          proxy_set_header    X-Forwarded-For   $proxy_add_x_forwarded_for;
          proxy_set_header    X-Forwarded-SSL on;
          proxy_set_header    X-Forwarded-Proto $scheme;
     }
  }
  </code></pre>
  
  <p>And on the upstream, I have a simple Python web-server listening to the 8081 port.</p>
  
  <p>Then, if run a request directly to the 443 port - all work well.
  When I issue a request to the port  HTTP 80, which causes 302 redirect - the Python app says:</p>
  
  <blockquote>
  <pre><code>    content_length = int(self.headers['Content-Length']) # &lt;--- Gets the size of data TypeError: int() argument must be a string, a
  bytes-like object or a number, not 'NoneType' ```
  </code></pre>
  </blockquote>
  
  <p>I.e. <code>self.headers['Content-Length']</code> == <code>NoneType</code>.</p>
  
  <p>While <code>curl</code> shows me data:</p>
  
  <pre><code>$ curl -vL -X POST http://example.com/ -d "param1=value1&amp;param2=value2"
  ...
  &lt; HTTP/1.1 502 Bad Gateway
  &lt; Server: nginx/1.10.3
  ...
  &lt; Content-Type: text/html
  &lt; Content-Length: 173
  </code></pre>
  
  <p>I'm not sure if this is NGINX-related issue at all (again - originally faced on AWS Application Load Balancer), but anyway...</p>