[Web-SIG] Defining a standard interface for common web tasks
Ian Bicking
ianb at colorstudy.com
Fri Oct 24 11:54:01 EDT 2003
Some minor nits...
On Friday, October 24, 2003, at 02:38 AM, David Fraser wrote:
> For CGI, it would seem to make sense that you do something like the
> following:
> res = web.cgi.HTTPResponse(sys.stdout)
req = web.cgi.HTTPRequest()
res = req.response
> res.content_type = 'text/html'
res.setHeader('content-type', 'text/html')
# I don't really see a reason that this header needs special attention
> res.set_cookie('name', 'Simon')
> res['X-Additional-Header'] = 'Another header'
res.setHeader('X-additional-header', 'Another header')
# It's not clear what dictionary access to the response object would
mean.
# res.headers['X-additional-header'] = 'Another header' might be okay
# but it makes it difficult to add multiple headers by the same name --
but
# I don't know if HTTP ever really calls for that anyway.
> res.send_headers()
> res.write('<html><h1>Hi there</h1>\n%s' % body)
# This, but also:
res.write('<html><h1>Hi there</h1>\n%s' % body)
res.setHeader('X-Yet-Another-Header', 'Yet another value')
res.commit()
# res.flush()? Sends headers *and* any body, can be called multiple
times
res.setHeader('Content-type', 'text/plain')
# raises exception
res.write('</html>')
# does not raise exception
--
Ian Bicking | ianb at colorstudy.com | http://blog.ianbicking.org
More information about the Web-SIG
mailing list