Exemplo n.º 1
0
    def __call__(self, environ, start_response):
        from google.appengine._internal.django.conf import settings

        # Set up middleware if needed. We couldn't do this earlier, because
        # settings weren't available.
        if self._request_middleware is None:
            self.initLock.acquire()
            try:
                try:
                    # Check that middleware is still uninitialised.
                    if self._request_middleware is None:
                        self.load_middleware()
                except:
                    # Unload whatever middleware we got
                    self._request_middleware = None
                    raise
            finally:
                self.initLock.release()

        set_script_prefix(base.get_script_name(environ))
        signals.request_started.send(sender=self.__class__)
        try:
            try:
                request = self.request_class(environ)
            except UnicodeDecodeError:
                response = http.HttpResponseBadRequest()
            else:
                response = self.get_response(request)

                # Apply response middleware
                for middleware_method in self._response_middleware:
                    response = middleware_method(request, response)
                response = self.apply_response_fixes(request, response)
        finally:
            signals.request_finished.send(sender=self.__class__)

        try:
            status_text = STATUS_CODE_TEXT[response.status_code]
        except KeyError:
            status_text = 'UNKNOWN STATUS CODE'
        status = '%s %s' % (response.status_code, status_text)
        response_headers = [(str(k), str(v))
                            for k, v in list(response.items())]
        for c in list(response.cookies.values()):
            response_headers.append(('Set-Cookie', str(c.output(header=''))))
        start_response(status, response_headers)
        return response
Exemplo n.º 2
0
    def __call__(self, environ, start_response):
        from google.appengine._internal.django.conf import settings

        # Set up middleware if needed. We couldn't do this earlier, because
        # settings weren't available.
        if self._request_middleware is None:
            self.initLock.acquire()
            try:
                try:
                    # Check that middleware is still uninitialised.
                    if self._request_middleware is None:
                        self.load_middleware()
                except:
                    # Unload whatever middleware we got
                    self._request_middleware = None
                    raise
            finally:
                self.initLock.release()

        set_script_prefix(base.get_script_name(environ))
        signals.request_started.send(sender=self.__class__)
        try:
            try:
                request = self.request_class(environ)
            except UnicodeDecodeError:
                response = http.HttpResponseBadRequest()
            else:
                response = self.get_response(request)

                # Apply response middleware
                for middleware_method in self._response_middleware:
                    response = middleware_method(request, response)
                response = self.apply_response_fixes(request, response)
        finally:
            signals.request_finished.send(sender=self.__class__)

        try:
            status_text = STATUS_CODE_TEXT[response.status_code]
        except KeyError:
            status_text = "UNKNOWN STATUS CODE"
        status = "%s %s" % (response.status_code, status_text)
        response_headers = [(str(k), str(v)) for k, v in response.items()]
        for c in response.cookies.values():
            response_headers.append(("Set-Cookie", str(c.output(header=""))))
        start_response(status, response_headers)
        return response
Exemplo n.º 3
0
 def __init__(self, environ):
     script_name = base.get_script_name(environ)
     path_info = force_unicode(environ.get('PATH_INFO', u'/'))
     if not path_info or path_info == script_name:
         # Sometimes PATH_INFO exists, but is empty (e.g. accessing
         # the SCRIPT_NAME URL without a trailing slash). We really need to
         # operate as if they'd requested '/'. Not amazingly nice to force
         # the path like this, but should be harmless.
         #
         # (The comparison of path_info to script_name is to work around an
         # apparent bug in flup 1.0.1. Se Django ticket #8490).
         path_info = u'/'
     self.environ = environ
     self.path_info = path_info
     self.path = '%s%s' % (script_name, path_info)
     self.META = environ
     self.META['PATH_INFO'] = path_info
     self.META['SCRIPT_NAME'] = script_name
     self.method = environ['REQUEST_METHOD'].upper()
     self._post_parse_error = False
Exemplo n.º 4
0
 def __init__(self, environ):
     script_name = base.get_script_name(environ)
     path_info = force_unicode(environ.get("PATH_INFO", u"/"))
     if not path_info or path_info == script_name:
         # Sometimes PATH_INFO exists, but is empty (e.g. accessing
         # the SCRIPT_NAME URL without a trailing slash). We really need to
         # operate as if they'd requested '/'. Not amazingly nice to force
         # the path like this, but should be harmless.
         #
         # (The comparison of path_info to script_name is to work around an
         # apparent bug in flup 1.0.1. Se Django ticket #8490).
         path_info = u"/"
     self.environ = environ
     self.path_info = path_info
     self.path = "%s%s" % (script_name, path_info)
     self.META = environ
     self.META["PATH_INFO"] = path_info
     self.META["SCRIPT_NAME"] = script_name
     self.method = environ["REQUEST_METHOD"].upper()
     self._post_parse_error = False