title: Google Cloud Run for Anthos (Knative) not setting X-Forwarded-Proto header correctly on https requests
body: <p>I have a django application running in Google cloud run (in a Kube cluster), via Docker served by uwsgi (but I've tried manage.py runserver and it's the same). By default cloud run accepts connections on both http and https.</p>
  <p>I would like to redirect the user to the https version but cloud run does not seen to be setting the headers correctly.</p>
  <p>I have a handler that returns the headers via: <code>json.dumps(request.headers.__dict__['_store'])</code></p>
  <p>And the relevant headers returned are:</p>
  <pre><code>&quot;x-forwarded-proto&quot;: [&quot;X-Forwarded-Proto&quot;, &quot;http&quot;]
  </code></pre>
  <p>But the value <strong>http</strong> never changes even when I visit the <strong>https</strong> version of the site.</p>
  <p>How should django correctly detect http requests on cloud run? I am unable to use</p>
  <p>SECURE_PROXY_SSL_HEADER</p>
  <p>to detect and redirect http requests to https as they all appear to be http requests, so you end up in a redirect loop.</p>
  <p>However if I follow the links in this post: <a href="https://www.jhanley.com/google-cloud-run-https-part-2/" rel="nofollow noreferrer">https://www.jhanley.com/google-cloud-run-https-part-2/</a></p>
  <p>to their &quot;show me the headers&quot; link the value does indeed change from http to https. Is it a django thing? Or a &quot;cloud run on kube&quot; thing?</p>
  <p>Hosting the app in question on pure cloud run and visiting the http version does an internal redirect to the HTTPS version and gives the reason: Non-Authoritative-Reason: HSTS</p>
  <p>Which is exactly what I'm trying to achieve. It seems the headers I am getting are from the internal routing, not the original request itself when running in Anthos mode.</p>