northof40 wrote:
> I'm trying to get access to the 'Referer' header value
when a page is
> requested but I cannot !
>
> I'm running CP 2.1.1 with Apache in front of it.
Everything works
> normally apart from this. At first I thought the
headers structure was
> dictionary (as per http:/
/docs.cherrypy.org/api-reference#request) but
> I got error messages suggesting it was a generator (I
don't know much
> about generators) so I tried doing this eventually to
dump
> them all out and I get no output.
>
> try:
> print "About to iterate headers"
> while 1:
> print cherrypy.request.headers.next()
> except StopIteration:
> pass
> print "About to iterate headers - again"
> for k in cherrypy.request.headers():
> print k
In CherryPy 2.1.1, there are two data structures from which
you can
obtain header values. But you should normally only use one
of them:
cherrypy.request.headerMap. This is a dictionary, and you
can get the
Referer header via:
ref = cherrypy.request.headerMap.get('Referer')
if ref:
do_stuff_with_ref(ref)
The other, cherrypy.request.headers, is only there for
people who think
the order in which headers were supplied by the client is
important. It
should be an iterable of (key, value) 2-tuples. But you
shouldn't use
it.
Robert Brewer
System Architect
Amor Ministries
fumanchu amor.org
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-users googlegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribe googlegroups.com
For more options, visit this group at http://groups-beta.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---
|