This is more of a Werkzeug question than Flask but it has to do with Flask.text_client. Is there a way to set/change the headers (ie, HTTP_REFERER) in a request with the Flask.text_client? It seems I can possibly do it with the Werzeug environment (although not 100% on this) but not sure about directly through the Flask.test_client. All I really need is to modify the HTTP_REFERER specifically on some requests to make sure we are grabbing it properly in our views. Any help would be appreciated. Thank you
Le 29/06/2011 20:40, Adam Patterson a écrit : > This is more of a Werkzeug question than Flask but it has to do with > Flask.text_client. > > Is there a way to set/change the headers (ie, HTTP_REFERER) in a request > with the Flask.text_client? It seems I can possibly do it with the > Werzeug environment (although not 100% on this) but not sure about > directly through the Flask.test_client. > > All I really need is to modify the HTTP_REFERER specifically on some > requests to make sure we are grabbing it properly in our views. > > Any help would be appreciated. > Thank you Hi, The test client’s methods take the same arguments as EnvironBuilder: http://werkzeug.pocoo.org/docs/test/#werkzeug.test.Client.open http://werkzeug.pocoo.org/docs/test/#werkzeug.test.EnvironBuilder Try this: client.get('/some/path', headers=[('Referer', 'http://example.com/')]) Regards, -- Simon Sapin http://exyr.org/
Thanks a lot guys that worked perfect! On Wed, Jun 29, 2011 at 1:58 PM, Simon Sapin <simon.sapin@exyr.org> wrote: > Le 29/06/2011 20:40, Adam Patterson a écrit : > > This is more of a Werkzeug question than Flask but it has to do with > > Flask.text_client. > > > > Is there a way to set/change the headers (ie, HTTP_REFERER) in a request > > with the Flask.text_client? It seems I can possibly do it with the > > Werzeug environment (although not 100% on this) but not sure about > > directly through the Flask.test_client. > > > > All I really need is to modify the HTTP_REFERER specifically on some > > requests to make sure we are grabbing it properly in our views. > > > > Any help would be appreciated. > > Thank you > > Hi, > > The test client’s methods take the same arguments as EnvironBuilder: > > http://werkzeug.pocoo.org/docs/test/#werkzeug.test.Client.open > http://werkzeug.pocoo.org/docs/test/#werkzeug.test.EnvironBuilder > > Try this: > > client.get('/some/path', > headers=[('Referer', 'http://example.com/')]) > > Regards, > -- > Simon Sapin > http://exyr.org/ > >
Hi, On Wed, Jun 29, 2011 at 2:40 PM, Adam Patterson <fakeempire@gmail.com> wrote: > Is there a way to set/change the headers (ie, HTTP_REFERER) in a request > with the Flask.text_client? It seems I can possibly do it with the Werzeug > environment (although not 100% on this) but not sure about > directly through the Flask.test_client. The open method on the test client (get and post methods call open) passes keyword arguments through to EnvironBuilder, which takes a `headers` keyword argument. Here, headers is of type werkzeug.datastructures.Headers. So you can create a Headers instance and pass it in as the `headers` keyword on your get or post methods of the test client. Relevant docs: http://werkzeug.pocoo.org/docs/test/#environment-building http://werkzeug.pocoo.org/docs/datastructures/#werkzeug.datastructures.Headers Hope this helps, Ron