fixed 401 handling and made trailing slash optional.

@dknochen I believe that this part is not necessary once it's deployed on S3.