Skip to content

Commit

Permalink
WIP: if allowed - return directory's index, otherwise - 403
Browse files Browse the repository at this point in the history
XXX: need for a response to return proper html

Related: aio-libs#921
  • Loading branch information
trimailov committed Jul 23, 2016
1 parent 083b23a commit 24c5fc2
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions aiohttp/web_urldispatcher.py
Original file line number Diff line number Diff line change
@@ -21,8 +21,8 @@
from .file_sender import FileSender
from .protocol import HttpVersion11
from .web_exceptions import (HTTPMethodNotAllowed, HTTPNotFound,
HTTPExpectationFailed)
from .web_reqrep import StreamResponse
HTTPExpectationFailed, HTTPForbidden)
from .web_reqrep import Response, StreamResponse


__all__ = ('UrlDispatcher', 'UrlMappingMatchInfo',
@@ -494,11 +494,19 @@ def handle(self, request):
request.app.logger.exception(error)
raise HTTPNotFound() from error

# Make sure that filepath is a file
if not filepath.is_file():
raise HTTPNotFound()
# on opening a dir, load it's contents if allowed
if filepath.is_dir():
if self._show_index:
ret = Response(text="")
else:
raise HTTPForbidden()

# on opening a file, load it's contents if they exist
if filepath.is_file():
ret = yield from self._file_sender.send(request, filepath)
else:
raise HTTPNotFound

ret = yield from self._file_sender.send(request, filepath)
return ret

def __repr__(self):

0 comments on commit 24c5fc2

Please sign in to comment.