Set header, add header, but how do I delete one?

1,416 views
Skip to first unread message

Noah McIlraith

unread,
Oct 5, 2011, 1:39:53 AM10/5/11
to python-...@googlegroups.com
Pretty simple, deleting headers, how do I do this?

HENG

unread,
Oct 5, 2011, 5:27:10 AM10/5/11
to python-...@googlegroups.com
You can do it as follows:

self.request.headers.pop("headers_key")

2011/10/5 Noah McIlraith <noah.mc...@gmail.com>

Pretty simple, deleting headers, how do I do this?



--
--------------------------------------------------------------------
HengZhou
---------------------------------------------------------------------
--

Ben Darnell

unread,
Oct 5, 2011, 1:08:12 PM10/5/11
to python-...@googlegroups.com
Currently the only way to delete an outgoing header is with
RequestHandler.clear(), which resets all headers and buffered output.

-Ben

Anthony Leung

unread,
Jan 16, 2015, 1:20:17 PM1/16/15
to python-...@googlegroups.com, b...@bendarnell.com
But sets some again.

def clear(self): """Resets all headers and content for this response.""" self._headers = httputil.HTTPHeaders({ "Server": "TornadoServer/%s" % tornado.version, "Content-Type": "text/html; charset=UTF-8", "Date": httputil.format_timestamp(time.time()), 
})

 There's a new clear_header method, so use that:

tornado.web.RequestHandler.clear(self)
self.set_header('X-Accel-Redirect', redirect_location)
self.clear_header('Content-Type')
( if in this case you need to not have the Content-Type set as the .clear method sets content-type to text/html )
Reply all
Reply to author
Forward
0 new messages