Exemplo n.º 1
0
 def repl_start_response(status, headers, exc_info=None):
     ct = header_value(headers, 'content-type')
     if ct and ct.startswith('text/html'):
         type.append(ct)
         remove_header(headers, 'content-length')
         start_response(status, headers, exc_info)
         return body.append
     return start_response(status, headers, exc_info)
Exemplo n.º 2
0
    def challenge(self, environ, status, app_headers, forget_headers):
        """
        Retourne systématiquement une page d'erreur 401.

        Retire également un éventuel en-tête "Content-Lenght" erroné
        (correctif tiré de la révision r8220 de repoze.who.testutil,
        disponible sur http://svn.repoze.org/whoplugins/whotestutil/).
        """
        remove_header(app_headers, 'content-length')
        remove_header(forget_headers, 'content-length')
        return super(VigiloAuthForgerPlugin, self).challenge(
                    environ, status, app_headers, forget_headers)
Exemplo n.º 3
0
 def gzip_start_response(self, status, headers, exc_info=None):
     cnttype = header_value(headers, 'content-type')
     cntenc = header_value(headers, 'content-encoding')
     # Compress only if content-type is 'text/*' or 'application/*'
     typeok = cnttype and \
              (cnttype.startswith('text/') or cnttype.startswith('application/'))
     self.compressible = \
         True if typeok and ('zip' not in cnttype) and (not cntenc) else False
     self.compressible and headers.append(('content-encoding', 'gzip'))
     remove_header(headers, 'content-length')
     self.headers = headers
     self.status = status
     return self.buffer.write
Exemplo n.º 4
0
 def _external_request(self, uri, method, body, headers,
                       wsgi_request, input, output, trusted):
     body = self._serialize_body(input, body, headers)
     # @@: Does httplib2 handle Content-Length?
     dict_headers = MultiDict(headers)
     (res, content) = self.httplib2.request(
         uri, method=method,
         body=body, headers=dict_headers, redirections=self.redirections)
     status = '%s %s' % (res.status, res.reason)
     # @@: Hrm...
     headers = res.items()
     remove_header(headers, 'status')
     return self._create_response(
         status, headers, output, [content], trusted)
Exemplo n.º 5
0
 def __call__(self, environ, start_response):
     global _threadedprint_installed
     if environ.get('paste.testing'):
         # In a testing environment this interception isn't
         # useful:
         return self.app(environ, start_response)
     if (not _threadedprint_installed
         or self._threaded_print_stdout is not sys.stdout):
         # @@: Not strictly threadsafe
         _threadedprint_installed = True
         threadedprint.install(leave_stdout=not self.replace_stdout)
         self._threaded_print_stdout = sys.stdout
     removed = []
     def remove_printdebug():
         removed.append(None)
     environ['paste.remove_printdebug'] = remove_printdebug
     logged = StringIO()
     listeners = [logged]
     environ['paste.printdebug_listeners'] = listeners
     if self.print_wsgi_errors:
         listeners.append(environ['wsgi.errors'])
     replacement_stdout = TeeFile(listeners)
     threadedprint.register(replacement_stdout)
     try:
         status, headers, body = wsgilib.intercept_output(
             environ, self.app)
         if status is None:
             # Some error occurred
             status = '500 Server Error'
             headers = [('Content-type', 'text/html')]
             start_response(status, headers)
             if not body:
                 body = 'An error occurred'
         content_type = response.header_value(headers, 'content-type')
         if (removed or
             (not self.force_content_type and
              (not content_type
               or not content_type.startswith('text/html')))):
             if replacement_stdout == logged:
                 # Then the prints will be lost, unless...
                 environ['wsgi.errors'].write(logged.getvalue())
             start_response(status, headers)
             return [body]
         response.remove_header(headers, 'content-length')
         body = self.add_log(body, logged.getvalue())
         start_response(status, headers)
         return [body]
     finally:
         threadedprint.deregister()
Exemplo n.º 6
0
 def gzip_start_response(self, status, headers, exc_info=None):
     self.headers = headers
     ct = header_value(headers, "content-type")
     ce = header_value(headers, "content-encoding")
     self.compressible = False
     if ct and (ct.startswith("text/") or ct.startswith("application/")) and "zip" not in ct:
         self.compressible = True
     if ce:
         self.compressible = False
     if self.compressible:
         headers.append(("content-encoding", "gzip"))
     remove_header(headers, "content-length")
     self.headers = headers
     self.status = status
     return self.buffer.write
Exemplo n.º 7
0
 def gzip_start_response(self, status, headers, exc_info=None):
     self.headers = headers
     ct = header_value(headers,'content-type')
     ce = header_value(headers,'content-encoding')
     self.compressible = False
     if ct and (ct.startswith('text/') or ct.startswith('application/')) \
         and 'zip' not in ct:
         self.compressible = True
     if ce:
         self.compressible = False
     if self.compressible:
         headers.append(('content-encoding', 'gzip'))
     remove_header(headers, 'content-length')
     self.headers = headers
     self.status = status
     return self.buffer.write
Exemplo n.º 8
0
 def __init__(self, location, headers=None):
     if headers is None:
         headers = []
     elif not isinstance(headers, list):
         # Les en-têtes ont été créés à l'aide de WebOb.
         # On supprime la taille du corps de la page car elle valait
         # zéro (il s'agissait d'une redirection), mais ce n'est plus
         # le cas à présent (et Paste vérifie cette valeur).
         headers.pop('Content-Length', None)
         # Conversion du format de WebOb vers le format de Paste.
         headers = headers.items()
     # Supprime la redirection.
     remove_header(headers, 'location')
     # Empêche la mise en cache de la page intermédiaire.
     CACHE_CONTROL.apply(headers, no_cache=True, no_store=True)
     super(HTTPFoundGrabFragment, self).__init__(location, headers)
Exemplo n.º 9
0
 def gzip_start_response(self, status, headers, exc_info=None):
     self.headers = headers
     ct = header_value(headers,'content-type')
     ce = header_value(headers,'content-encoding')
     self.compressible = False
     if ct and (ct.startswith('text/') or ct.startswith('application/')) \
         and 'zip' not in ct:
         self.compressible = True
     if ce:
         self.compressible = False
     if self.compressible:
         headers.append(('content-encoding', 'gzip'))
     remove_header(headers, 'content-length')
     self.headers = headers
     self.status = status
     return self.buffer.write
Exemplo n.º 10
0
 def gzip_start_response(self, status, headers, exc_info=None):
     self.headers = headers
     ct = header_value(headers, 'content-type')
     ce = header_value(headers, 'content-encoding')
     self.compressible = False
     # This statement is the only change in this monkeypatch:
     if ct and (ct.startswith('text/') or ct.startswith('application/')) \
         and 'zip' not in ct and ct != 'application/x-shockwave-flash':
         self.compressible = True
     if ce:
         self.compressible = False
     if self.compressible:
         headers.append(('content-encoding', 'gzip'))
     remove_header(headers, 'content-length')
     self.headers = headers
     self.status = status
     return self.buffer.write
Exemplo n.º 11
0
 def gzip_start_response(self, status, headers, exc_info=None):
     self.headers = headers
     ct = header_value(headers, 'content-type')
     ce = header_value(headers, 'content-encoding')
     self.compressible = False
     # This statement is the only change in this monkeypatch:
     if ct and (ct.startswith('text/') or ct.startswith('application/')) \
         and 'zip' not in ct and ct != 'application/x-shockwave-flash':
         self.compressible = True
     if ce:
         self.compressible = False
     if self.compressible:
         headers.append(('content-encoding', 'gzip'))
     remove_header(headers, 'content-length')
     self.headers = headers
     self.status = status
     return self.buffer.write
Exemplo n.º 12
0
 def challenge(self, environ, status, app_headers, forget_headers):
     """Return a 401 page unconditionally."""
     headers = app_headers + forget_headers
     remove_header(headers, 'content-length')
     # The HTTP status code and reason may not be the default ones:
     status_parts = _HTTP_STATUS_PATTERN.search(status)
     if status_parts:
         reason = status_parts.group('reason')
         code = int(status_parts.group('code'))
     else:
         reason = 'HTTP Unauthorized'
         code = 401
     # Building the response:
     response = HTTPUnauthorized(headers=headers)
     response.title = reason
     response.code = code
     return response
Exemplo n.º 13
0
 def challenge(self, environ, status, app_headers, forget_headers):
     """Return a 401 page unconditionally."""
     headers = app_headers + forget_headers
     remove_header(headers, 'content-length')
     # The HTTP status code and reason may not be the default ones:
     status_parts = _HTTP_STATUS_PATTERN.search(status)
     if status_parts:
         reason = status_parts.group('reason')
         code = int(status_parts.group('code'))
     else:
         reason = 'HTTP Unauthorized'
         code = 401
     # Building the response:
     response = HTTPUnauthorized(headers=headers)
     response.title = reason
     response.code = code
     return response
Exemplo n.º 14
0
 def gzip_start_response(self, status, headers, exc_info=None):
     self.headers = headers
     ct = header_value(headers, "content-type")
     ce = header_value(headers, "content-encoding")
     self.compressible = False
     # This statement is the only change in this monkeypatch:
     if (
         ct
         and (ct.startswith("text/") or ct.startswith("application/"))
         and "zip" not in ct
         and ct != "application/x-shockwave-flash"
     ):
         self.compressible = True
     if ce:
         self.compressible = False
     if self.compressible:
         headers.append(("content-encoding", "gzip"))
     remove_header(headers, "content-length")
     self.headers = headers
     self.status = status
     return self.buffer.write