I asked this question earlier in the year, and still haven't figured out a simple way to change the HTTP referer header<http://en.wikipedia.org/wiki/HTTP_REFERER> on a redirect? Does anyone have any ideas? Thanks. Zach
Hi, On Wed, Nov 16, 2011 at 8:13 PM, Zach Williams <hey@zachwill.com> wrote: > I asked this question earlier in the year, and still haven't figured out a > simple way to change the HTTP referer header on a redirect? > Does anyone have any ideas? I don't know if web browsers will respect certain headers on a redirect, but here's how you can modify the response headers: from flask import Flask, redirect, request app = Flask(__name__) @app.route('/') def index(): response = redirect('/destination/') # modify response.headers here return response @app.route('/destination/') def destination(): return '<pre>{0}</pre>'.format(request.headers) Hope this helps, Ron
Hey Zach, Do you want to change the referrer or is just hiding/clearing it ok? If you just want to clear it, look into double meta refreshes. I recently did this on a flask app. Let me know if you have any questions. On Thu, Nov 17, 2011 at 10:39 AM, Ron DuPlain <ron.duplain@gmail.com> wrote: > Hi, > > On Wed, Nov 16, 2011 at 8:13 PM, Zach Williams <hey@zachwill.com> wrote: >> I asked this question earlier in the year, and still haven't figured out a >> simple way to change the HTTP referer header on a redirect? >> Does anyone have any ideas? > > I don't know if web browsers will respect certain headers on a > redirect, but here's how you can modify the response headers: > > from flask import Flask, redirect, request > > app = Flask(__name__) > > @app.route('/') > def index(): > response = redirect('/destination/') > # modify response.headers here > return response > > @app.route('/destination/') > def destination(): > return '<pre>{0}</pre>'.format(request.headers) > > Hope this helps, > > Ron >
Ron, thanks for the example code, man. Any ideas on modifying the request before the redirect? Adam, hiding it or clearing it would be awesome. Whenever I try to change the request's headers, I get the dreaded: *TypeError: 'EnvironHeaders' objects are immutable* and haven't figured out a workaround for Werkzeug's EnvironHeaders — do I need to subclass it so it's mutable? I'd definitely appreciate any example code for clearing the headers out. On Wed, Nov 16, 2011 at 9:59 PM, Adam Patterson <fakeempire@gmail.com>wrote: > Hey Zach, > > Do you want to change the referrer or is just hiding/clearing it ok? > > If you just want to clear it, look into double meta refreshes. I > recently did this on a flask app. Let me know if you have any > questions. > > On Thu, Nov 17, 2011 at 10:39 AM, Ron DuPlain <ron.duplain@gmail.com> > wrote: > > Hi, > > > > On Wed, Nov 16, 2011 at 8:13 PM, Zach Williams <hey@zachwill.com> wrote: > >> I asked this question earlier in the year, and still haven't figured > out a > >> simple way to change the HTTP referer header on a redirect? > >> Does anyone have any ideas? > > > > I don't know if web browsers will respect certain headers on a > > redirect, but here's how you can modify the response headers: > > > > from flask import Flask, redirect, request > > > > app = Flask(__name__) > > > > @app.route('/') > > def index(): > > response = redirect('/destination/') > > # modify response.headers here > > return response > > > > @app.route('/destination/') > > def destination(): > > return '<pre>{0}</pre>'.format(request.headers) > > > > Hope this helps, > > > > Ron > > >
https://gist.github.com/1372608 Basically, instead of redirecting directly to the final destination, you render a template that meta refreshes to another view which in turn meta refreshes to the final destination. This is a double meta refresh. It clears the original HTTP_REFERRER info. On Thu, Nov 17, 2011 at 1:54 PM, Zach Williams <hey@zachwill.com> wrote: > Ron, thanks for the example code, man. Any ideas on modifying the request > before the redirect? > Adam, hiding it or clearing it would be awesome. Whenever I try to change > the request's headers, I get the dreaded: TypeError: 'EnvironHeaders' > objects are immutable and haven't figured out a workaround for Werkzeug's > EnvironHeaders — do I need to subclass it so it's mutable? I'd definitely > appreciate any example code for clearing the headers out. > On Wed, Nov 16, 2011 at 9:59 PM, Adam Patterson <fakeempire@gmail.com> > wrote: >> >> Hey Zach, >> >> Do you want to change the referrer or is just hiding/clearing it ok? >> >> If you just want to clear it, look into double meta refreshes. I >> recently did this on a flask app. Let me know if you have any >> questions. >> >> On Thu, Nov 17, 2011 at 10:39 AM, Ron DuPlain <ron.duplain@gmail.com> >> wrote: >> > Hi, >> > >> > On Wed, Nov 16, 2011 at 8:13 PM, Zach Williams <hey@zachwill.com> wrote: >> >> I asked this question earlier in the year, and still haven't figured >> >> out a >> >> simple way to change the HTTP referer header on a redirect? >> >> Does anyone have any ideas? >> > >> > I don't know if web browsers will respect certain headers on a >> > redirect, but here's how you can modify the response headers: >> > >> > from flask import Flask, redirect, request >> > >> > app = Flask(__name__) >> > >> > @app.route('/') >> > def index(): >> > response = redirect('/destination/') >> > # modify response.headers here >> > return response >> > >> > @app.route('/destination/') >> > def destination(): >> > return '<pre>{0}</pre>'.format(request.headers) >> > >> > Hope this helps, >> > >> > Ron >> > > >