#Check the 'Accept' header to see what formats work
if cpg.request.headerMap.has_key('Accept'):
theStr = cpg.request.headerMap['Accept']
if 'text/xml' in theStr or 'text/*' in theStr or '*/*' in
theStr:
#they'll accept xml(default, so do nothing)
pass
elif theStr=='text/html' or theStr=='text/xhtml':
#they'll only accept html
theFormat='XHTML'
else:
cpg.response.headerMap['Status']= '406 Not acceptable'
return """<h1>406 Not acceptable</h1><br />
'Accept': %s was requested<br />
No acceptable formats available --
'txt/xml' is default, 'txt/html' or 'txt/xhtml'
provided"""%theStr
I didn't "not think" about this, it just took longer than I thought to
think what I thought :)
Yes, I think we could -- the Accept information comes in a logical
structure, but it's sure not one that's employed anywhere else. How
about if it were exposed as a dictionary, similar to the way CherryPy
"pythonizes" the HeaderMap? Something like:
AcceptHeaderMap={'text':[{'xml':{'q':50}},{'html':{'q':30}},{'*':{'q':10}}]}
or something?
There's a lot of good data in the Accept header, and it comes in a
structured way, so it should be possible -- but is it simpler for the
developer just to parse it for what the application needs? OTOH, if it
were written as a "generic AcceptHeaderFilter," it would provide a way
to handle the ever-expanding list of filetypes, encodings, languages,
etc. gracefully.
So, assuming we could, then should we? Eventually?
Ron