Index: net/tools/testserver/testserver.py |
=================================================================== |
--- net/tools/testserver/testserver.py (revision 107962) |
+++ net/tools/testserver/testserver.py (working copy) |
@@ -266,11 +266,13 @@ |
class BasePageHandler(BaseHTTPServer.BaseHTTPRequestHandler): |
def __init__(self, request, client_address, socket_server, |
- connect_handlers, get_handlers, post_handlers, put_handlers): |
+ connect_handlers, get_handlers, post_handlers, put_handlers, |
+ head_handlers): |
wtc
2011/10/31 19:21:00
Nit: list 'head_handlers' and 'do_HEAD' in alphabe
mmenke
2011/10/31 20:46:40
Done.
|
self._connect_handlers = connect_handlers |
self._get_handlers = get_handlers |
self._post_handlers = post_handlers |
self._put_handlers = put_handlers |
+ self._head_handlers = head_handlers |
BaseHTTPServer.BaseHTTPRequestHandler.__init__( |
self, request, client_address, socket_server) |
@@ -308,7 +310,12 @@ |
if handler(): |
return |
+ def do_HEAD(self): |
+ for handler in self._head_handlers: |
+ if handler(): |
+ return |
+ |
class TestPageHandler(BasePageHandler): |
def __init__(self, request, client_address, socket_server): |
@@ -351,13 +358,14 @@ |
self.DefaultResponseHandler] |
post_handlers = [ |
self.EchoTitleHandler, |
- self.EchoAllHandler, |
self.EchoHandler, |
self.DeviceManagementHandler] + get_handlers |
put_handlers = [ |
self.EchoTitleHandler, |
- self.EchoAllHandler, |
wtc
2011/10/31 19:21:00
Why did you remove self.EchoAllHandler from post_h
mmenke
2011/10/31 20:46:40
It's in get_handlers already, so there's no reason
|
self.EchoHandler] + get_handlers |
+ head_handlers = [ |
+ self.FileHandler, |
+ self.DefaultHeadResponseHandler] |
self._mime_types = { |
'crx' : 'application/x-chrome-extension', |
@@ -372,7 +380,7 @@ |
BasePageHandler.__init__(self, request, client_address, socket_server, |
connect_handlers, get_handlers, post_handlers, |
- put_handlers) |
+ put_handlers, head_handlers) |
def GetMIMETypeFromName(self, file_name): |
"""Returns the mime type for the specified file_name. So far it only looks |
@@ -894,9 +902,11 @@ |
self.send_error(404) |
return True |
- f = open(file_path, "rb") |
- data = f.read() |
- f.close() |
+ data = ''; |
+ if (self.command != 'HEAD'): |
+ f = open(file_path, "rb") |
+ data = f.read() |
+ f.close() |
data = self._ReplaceFileData(data, query) |
wtc
2011/10/31 19:21:00
Just wanted to confirm that this statement should
mmenke
2011/10/31 20:46:40
It didn't matter, either way. Removed the if stat
|
@@ -940,7 +950,8 @@ |
self.send_header('Content-type', self.GetMIMETypeFromName(file_path)) |
self.send_header('Accept-Ranges', 'bytes') |
- self.send_header('Content-Length', len(data)) |
+ if (self.command != 'HEAD'): |
+ self.send_header('Content-Length', len(data)) |
wtc
2011/10/31 19:21:00
Just curious: are HEAD responses forbidden to have
wtc
2011/10/31 19:59:41
julian.reschke: thank you for the reply.
mmenke:
mmenke
2011/10/31 20:46:40
Done. You're right. I misread the RFC.
|
self.send_header('ETag', '\'' + file_path + '\'') |
self.end_headers() |
@@ -1357,6 +1368,15 @@ |
self.wfile.write(contents) |
return True |
+ def DefaultHeadResponseHandler(self): |
+ """This is the catch-all response handler for head requests that aren't |
wtc
2011/10/31 19:21:00
Capitalize "HEAD".
mmenke
2011/10/31 20:46:40
Done.
|
+ handled by one of the special handlers above.""" |
+ |
+ self.send_response(200) |
+ self.send_header('Content-type', 'text/html') |
wtc
2011/10/31 19:21:00
Since there is no |contents|, it seems that we sho
mmenke
2011/10/31 20:46:40
Not done (As per spec - "The Content-Type entity-h
mmenke
2011/10/31 20:49:25
On second thought, you're right, with a 0 content-
mmenke
2011/10/31 20:52:14
Or maybe not? Honestly, I have no idea. Suppose
|
+ self.end_headers() |
+ return True |
+ |
def RedirectConnectHandler(self): |
"""Sends a redirect to the CONNECT request for www.redirect.com. This |
response is not specified by the RFC, so the browser should not follow |
@@ -1464,7 +1484,7 @@ |
self.ChromiumSyncTimeHandler] |
BasePageHandler.__init__(self, request, client_address, |
sync_http_server, [], get_handlers, |
- post_handlers, []) |
+ post_handlers, [], []) |
def ChromiumSyncTimeHandler(self): |