예제 #1
0
    def _send_response(request_handler, *args, **kwargs):

        # Always call method
        retval = method(request_handler, *args, **kwargs)

        # Handy stuff
        headers = request_handler.response.headers
        is_redirect = type(retval) is webapp2.Response and retval.status_int == 302

        # Browser cache control: set appropriate response headers
        if routes.configs.get().cachable and settings.cache.browser_lifetime is not None:
            # Ensure CDNs will cache static output
            headers['Cache-Control'] = 'public, max-age={max_age}'.format(max_age=settings.cache.browser_lifetime)
        else:
            # Ensure no caching
            headers['Cache-Control'] = 'no-cache, no-store, must-revalidate'
            headers['Pragma'] = 'no-cache'
            headers['Expires'] = '0'

        # Ensure http can call https
        headers['Access-Control-Allow-Origin'] = settings.urls.canonical

        if is_redirect:
            # If redirecting, ensure the pjax url param is included to avoid the browser caching wrong response
            return utils.pjaxify_response(retval)
        else:
            # Write calling method's return value to response body if not a redirect
            return request_handler.response.out.write(retval)
예제 #2
0
    def _send_response(request_handler, *args, **kwargs):

        # Always call method
        retval = method(request_handler, *args, **kwargs)

        # Handy stuff
        headers = request_handler.response.headers
        is_redirect = type(retval) is webapp2.Response and retval.status_int == 302

        # Browser cache control: set appropriate response headers
        if routes.configs.get().cachable and settings.cache.browser_lifetime is not None:
            # Ensure CDNs will cache static output
            headers["Cache-Control"] = "public, max-age={max_age}".format(max_age=settings.cache.browser_lifetime)
        else:
            # Ensure no caching
            headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
            headers["Pragma"] = "no-cache"
            headers["Expires"] = "0"

        # Ensure http can call https
        headers["Access-Control-Allow-Origin"] = settings.urls.canonical

        if is_redirect:
            # If redirecting, ensure the pjax url param is included to avoid the browser caching wrong response
            return utils.pjaxify_response(retval)
        else:
            # Write calling method's return value to response body if not a redirect
            return request_handler.response.out.write(retval)
예제 #3
0
    def _check_oauth(request_handler, *args, **kwargs):

        # If auth is required and scope is configured, verify auth and bail if not
        if routes.configs.get().requires_oauth:
            retval = users.verify_oauth(request_handler)

            # Bail if auth sends back a redirect
            if type(retval) is webapp2.Response and retval.status_int == 302:
                retval = utils.pjaxify_response(retval)
                return retval

        # All clear, call our decorated method
        return method(request_handler, *args, **kwargs)
예제 #4
0
    def _check_oauth(request_handler, *args, **kwargs):

        # If auth is required and scope is configured, verify auth and bail if not
        if routes.configs.get().requires_oauth:
            retval = users.verify_oauth(request_handler)

            # Bail if auth sends back a redirect
            if type(retval) is webapp2.Response and retval.status_int == 302:
                retval = utils.pjaxify_response(retval)
                return retval

        # All clear, call our decorated method
        return method(request_handler, *args, **kwargs)