1

In app engine app.yaml in the handlers section, I would like to specify a redirect based on http header.

so if a request comes with this header route it elsewhere.

is this possible at all ?

Kravitz
  • 167
  • 11

1 Answers1

0

This is not possible in the app.yaml mainly due to the reason that you are unable to detect specific custom headers only set them for your response as seen here.

What you need to do for a situation like this is manage request headers through your app code to detect the headers you are looking for. Do keep in the header restrictions of using GAE as the documentation states:

For security purposes, some headers are sanitized, amended, or removed by intermediate proxies before they reach the application.

Here is a quick example of how you could do so in python using flask

import os
from flask import Flask, redirect, url_for, request

app = Flask(__name__)

@app.route('/')
def hello():
    if request.headers['your-header-name']:
        return redirect(url_for('foo'))
    else:
        return 'Hello World'

@app.route('/foo')
def foo():
    return 'Hello Foo!'

if __name__ == '__main__':
    # Bind to PORT if defined, otherwise default to 5000.
    port = int(os.environ.get('PORT', 5000))
    app.run(host='0.0.0.0', port=port)
Hipster Cat
  • 131
  • 5