From: Ben Darnell Date: Mon, 29 Nov 2010 21:49:06 +0000 (-0800) Subject: Treat HEAD requests the same as GET for e.g. sending Etag headers. X-Git-Tag: v1.2.0~64 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ae3cc317c2781ad515a0ad48891d65b2370982df;p=thirdparty%2Ftornado.git Treat HEAD requests the same as GET for e.g. sending Etag headers. Closes #180. --- diff --git a/tornado/web.py b/tornado/web.py index 3eddc40b7..d2fccdd90 100644 --- a/tornado/web.py +++ b/tornado/web.py @@ -550,7 +550,8 @@ class RequestHandler(object): # Automatically support ETags and add the Content-Length header if # we have not flushed any content yet. if not self._headers_written: - if (self._status_code == 200 and self.request.method == "GET" and + if (self._status_code == 200 and + self.request.method in ("GET", "HEAD") and "Etag" not in self._headers): hasher = hashlib.sha1() for part in self._write_buffer: @@ -924,7 +925,7 @@ def removeslash(method): @functools.wraps(method) def wrapper(self, *args, **kwargs): if self.request.path.endswith("/"): - if self.request.method == "GET": + if self.request.method in ("GET", "HEAD"): uri = self.request.path.rstrip("/") if self.request.query: uri += "?" + self.request.query self.redirect(uri) @@ -944,7 +945,7 @@ def addslash(method): @functools.wraps(method) def wrapper(self, *args, **kwargs): if not self.request.path.endswith("/"): - if self.request.method == "GET": + if self.request.method in ("GET", "HEAD"): uri = self.request.path + "/" if self.request.query: uri += "?" + self.request.query self.redirect(uri) @@ -1434,7 +1435,7 @@ def authenticated(method): @functools.wraps(method) def wrapper(self, *args, **kwargs): if not self.current_user: - if self.request.method == "GET": + if self.request.method in ("GET", "HEAD"): url = self.get_login_url() if "?" not in url: if urlparse.urlsplit(url).scheme: