1

TLDR; How do I set a custom HTTP request header in redirect?

Below code redirects to an external service but fails to pass 'Authorization' request header to target. I can see the header in response before redirect happens - can it be forwarded somehow?

@app.route('/external_page')
def external_page():
    if not request.cookies.get('id_token'):
        return flask.redirect(flask.url_for('login',_external=True,_scheme=SCHEME))

    response = flask.redirect(flask.url_for('https://external_service_url/v1/ui'))
    response.headers['Authorization'] = 'token_id'
    return response

Answer: It's not possible, in HTTP and not in any framework.

The only way for a site to instruct a browser to issue an HTTP request with a custom header is to use Javascript and the XMLHttpRequest object. And it needs CORS implemented on the target server to allow such ajax requests.

Source: Redirect to page and send custom HTTP headers

cherry9090
  • 105
  • 1
  • 8

1 Answers1

1

It's not possible

See Redirect to page and send custom HTTP headers

The only way for a site to instruct a browser to issue an HTTP request with a custom header is to use Javascript and the XMLHttpRequest object. And it needs CORS implemented on the target server to allow such ajax requests.

cherry9090
  • 105
  • 1
  • 8