Beispiel #1
0
 def lookup_app(self, environ):
     # Check again if the branch is blocked from being served, this is
     # mostly for tests. It's already checked in apps/transport.py
     if not self.branch.get_config().get_user_option_as_bool('http_serve',
                                                             default=True):
         raise httpexceptions.HTTPNotFound()
     self._url_base = environ['SCRIPT_NAME']
     self._path_info = environ['PATH_INFO']
     self._static_url_base = environ.get('loggerhead.static.url')
     if self._static_url_base is None:
         self._static_url_base = self._url_base
     self._environ = environ
     if self.served_url is _DEFAULT:
         public_branch = self.public_branch_url()
         if public_branch is not None:
             self.served_url = public_branch
         else:
             self.served_url = wsgiref.util.application_uri(environ)
     for hook in self.hooks['controller']:
         controller = hook(self, environ)
         if controller is not None:
             return controller
     path = request.path_info_pop(environ)
     if not path:
         raise httpexceptions.HTTPMovedPermanently(
             self.absolute_url('/changes'))
     if path == 'static':
         return static_app
     elif path == '+json':
         environ['loggerhead.as_json'] = True
         path = request.path_info_pop(environ)
     cls = self.controllers_dict.get(path)
     if cls is not None:
         return cls(self, self.get_history)
     raise httpexceptions.HTTPNotFound()
Beispiel #2
0
 def __call__(self, environ, start_response):
     # /download/<rev_id>/<filename>
     h = self._history
     args = self.get_args(environ)
     if len(args) < 2:
         raise httpexceptions.HTTPMovedPermanently(
             self._branch.absolute_url('/changes'))
     revid = h.fix_revid(args[0])
     try:
         path, filename, content = h.get_file(args[1], revid)
     except (NoSuchFile, NoSuchRevision):
         # Compatibility API for /download/rev_id/file_id/<filename>
         try:
             path, filename, content = h.get_file_by_fileid(
                 args[1].encode('UTF-8'), revid)
         except (NoSuchId, NoSuchRevision):
             raise httpexceptions.HTTPNotFound()
     mime_type, encoding = mimetypes.guess_type(filename)
     if mime_type is None:
         mime_type = 'application/octet-stream'
     self.log.info('/download %s @ %s (%d bytes)',
                   path,
                   h.get_revno(revid),
                   len(content))
     encoded_filename = self.encode_filename(filename)
     headers = [
         ('Content-Type', mime_type),
         ('Content-Length', str(len(content))),
         ('Content-Disposition',
          "attachment; filename*=utf-8''%s" % (encoded_filename,)),
         ]
     start_response('200 OK', headers)
     return [content]
Beispiel #3
0
 def add_slash(self, environ, start_response):
     """
     This happens when you try to get to a directory
     without a trailing /
     """
     url = request.construct_url(environ, with_query_string=False)
     url += '/'
     if environ.get('QUERY_STRING'):
         url += '?' + environ['QUERY_STRING']
     exc = httpexceptions.HTTPMovedPermanently(
         'The resource has moved to %s - you should be redirected '
         'automatically.' % url,
         headers=[('location', url)])
     return exc.wsgi_application(environ, start_response)
Beispiel #4
0
 def lookup_app(self, environ):
     # Check again if the branch is blocked from being served, this is
     # mostly for tests. It's already checked in apps/transport.py
     if self.branch.get_config().get_user_option('http_serve') == 'False':
         raise httpexceptions.HTTPNotFound()
     self._url_base = environ['SCRIPT_NAME']
     self._static_url_base = environ.get('loggerhead.static.url')
     if self._static_url_base is None:
         self._static_url_base = self._url_base
     self._environ = environ
     if self.served_url is _DEFAULT:
         public_branch = self.public_branch_url()
         if public_branch is not None:
             self.served_url = public_branch
         else:
             # Loggerhead only supports serving .bzr/ on local branches, so
             # we shouldn't suggest something that won't work.
             try:
                 util.local_path_from_url(self.branch.base)
                 self.served_url = self.url([])
             except breezy.errors.InvalidURL:
                 self.served_url = None
     for hook in self.hooks['controller']:
         controller = hook(self, environ)
         if controller is not None:
             return controller
     path = request.path_info_pop(environ)
     if not path:
         raise httpexceptions.HTTPMovedPermanently(
             self.absolute_url('/changes'))
     if path == 'static':
         return static_app
     elif path == '+json':
         environ['loggerhead.as_json'] = True
         path = request.path_info_pop(environ)
     cls = self.controllers_dict.get(path)
     if cls is not None:
         return cls(self, self.get_history)
     raise httpexceptions.HTTPNotFound()