Assume trailing slashes want to load indexes

When fetching from swift, if the path ends in a trailing slash we
most likely want to load an index.html page. Try to load that first
assuming that objects generally won't end with a slash in our
pseudo filesystem.

Change-Id: Ifda71643ed66ac088bb8b6b3e1e9ad381669000d
This commit is contained in:
Joshua Hesketh 2014-12-12 14:16:49 +11:00
parent cc2907689f
commit 9a5db2c57d
1 changed files with 20 additions and 6 deletions

View File

@ -187,12 +187,26 @@ def get(environ, root_path, config=None):
logpath, openhook=fileinput.hook_compressed)
file_headers.update(util.get_headers_for_file(logpath))
else:
resp_headers, flines_generator = get_swift_line_generator(logname,
config)
if not flines_generator:
logname = os.path.join(logname, 'index.html')
resp_headers, flines_generator = get_swift_line_generator(logname,
config)
# NOTE(jhesketh): If the requested URL ends in a trailing slash we
# assume that this is meaning to load an index.html from our pseudo
# filesystem. This means we should't store objects with a trailing
# slash in their name as os-loganalzye won't load them.
if logname[-1] == '/':
resp_headers, flines_generator = get_swift_line_generator(
os.path.join(logname, 'index.html'), config)
if not flines_generator:
# Maybe our assumption was wrong, lets go back to trying the
# original object name.
resp_headers, flines_generator = get_swift_line_generator(
logname, config)
else:
resp_headers, flines_generator = get_swift_line_generator(
logname, config)
if not flines_generator:
# The object doesn't exist. Try again appending index.html
logname = os.path.join(logname, 'index.html')
resp_headers, flines_generator = get_swift_line_generator(
logname, config)
file_headers.update(resp_headers)
if not flines_generator: