fix serving binary files on windows

This commit is contained in:
Damien Churchill 2009-04-20 20:26:03 +00:00
parent 2f44899521
commit 503169ce76
1 changed files with 5 additions and 3 deletions

View File

@ -204,12 +204,14 @@ class LookupResource(resource.Resource, component.Component):
return self return self
def render(self, request): def render(self, request):
log.debug("Requested path: '%s'", request.path)
for lookup in self.directories: for lookup in self.directories:
if request.path in os.listdir(lookup): if request.path in os.listdir(lookup):
path = os.path.join(lookup, request.path) path = os.path.join(lookup, request.path)
log.debug("Serving path: '%s'", path)
mime_type = mimetypes.guess_type(path) mime_type = mimetypes.guess_type(path)
request.setHeader("content-type", mime_type[0]) request.setHeader("content-type", mime_type[0])
return open(path).read() return open(path, "rb").read()
request.setResponseCode(http.NOT_FOUND) request.setResponseCode(http.NOT_FOUND)
return "<h1>404 - Not Found</h1>" return "<h1>404 - Not Found</h1>"