예제 #1
0
파일: hooks.py 프로젝트: Vinsurya/Plone
def modifyStreamingResponse(event):
    """Invoke the modifyResponse() method of a caching operation, if one
    can be found, for a streaming response (one using response.write()).
    """
    
    response = event.response
    if response is None:
        return
    
    request = getRequest()
    if request is None:
        return
    
    # Mark the response to allow us to avoid attempting a modify operation
    # again in the normal hook above
    alsoProvides(request, IStreamedResponse)
    
    published = request.get('PUBLISHED', None)
    
    rule, operationName, operation = findOperation(request)
    
    if rule is None:
        return
    
    response.setHeader(X_CACHE_RULE_HEADER, rule)
    logger.debug("Published: %s Ruleset: %s Operation: %s", repr(published), rule, operation)
    
    if operation is not None:
        
        response.setHeader(X_CACHE_OPERATION_HEADER, operationName)
        operation.modifyResponse(rule, response)
예제 #2
0
def modifyStreamingResponse(event):
    """Invoke the modifyResponse() method of a caching operation, if one
    can be found, for a streaming response (one using response.write()).
    """

    response = event.response
    if response is None:
        return

    request = getRequest()
    if request is None:
        return

    # Mark the response to allow us to avoid attempting a modify operation
    # again in the normal hook above
    alsoProvides(request, IStreamedResponse)

    published = request.get('PUBLISHED', None)

    rule, operationName, operation = findOperation(request)

    if rule is None:
        return

    response.setHeader(X_CACHE_RULE_HEADER, rule)
    logger.debug("Published: %s Ruleset: %s Operation: %s", repr(published), rule, operation)

    if operation is not None:

        response.setHeader(X_CACHE_OPERATION_HEADER, operationName)
        operation.modifyResponse(rule, response)
예제 #3
0
    def mutate(self):
        request = self.request

        # Abort if this was a streamed request handled by our event handler
        # below
        if IStreamedResponse.providedBy(request):
            return

        published = request.get('PUBLISHED', None)
        rule, operationName, operation = findOperation(request)

        if rule is None:
            return

        request.response.setHeader(X_CACHE_RULE_HEADER, rule)
        logger.debug(
            'Published: %s Ruleset: %s Operation: %s',
            repr(published),
            rule,
            operation
        )

        if operation is not None:
            request.response.setHeader(X_CACHE_OPERATION_HEADER, operationName)
            operation.modifyResponse(rule, request.response)
예제 #4
0
def intercept(event):
    """Invoke the interceptResponse() method of a caching operation, if one
    can be found.

    To properly abort request processing, this will raise an exception. The
    actual response (typically an empty response) is then set via a view on
    the exception. We set and lock the response status to avoid defaulting to
    a 404 exception.
    """

    try:
        request = event.request
        published = request.get('PUBLISHED', None)
        rule, operationName, operation = findOperation(request)

        if rule is None:
            return

        request.response.setHeader(X_CACHE_RULE_HEADER, rule)
        logger.debug(
            'Published: %s Ruleset: %s Operation: %s',
            repr(published),
            rule,
            operation
        )

        if operation is not None:
            responseBody = operation.interceptResponse(rule, request.response)

            if responseBody is not None:
                # Only put this in the response if the operation actually
                # intercepted something
                request.response.setHeader(
                    X_CACHE_OPERATION_HEADER,
                    operationName
                )

                # Stop any post-processing, including the operation's response
                # modification
                if DISABLE_TRANSFORM_REQUEST_KEY not in request.environ:
                    request.environ[DISABLE_TRANSFORM_REQUEST_KEY] = True

                # The view is liable to have set a response status. Lock it
                # now so that it doesn't get set to 500 later.
                status = request.response.getStatus()
                if status:
                    request.response.setStatus(status, lock=True)

                raise Intercepted(status, responseBody)

    except ConflictError:
        raise
    except Intercepted:
        raise
    except Exception:
        logging.exception(
            'Swallowed exception in plone.caching IPubAfterTraversal event '
            'handler'
        )
예제 #5
0
def intercept(event):
    """Invoke the interceptResponse() method of a caching operation, if one
    can be found.

    To properly abort request processing, this will raise an exception. The
    actual response (typically an empty response) is then set via a view on
    the exception. We set and lock the response status to avoid defaulting to
    a 404 exception.
    """

    try:
        request = event.request
        published = request.get('PUBLISHED', None)

        rule, operationName, operation = findOperation(request)

        if rule is None:
            return

        request.response.setHeader(X_CACHE_RULE_HEADER, rule)
        logger.debug("Published: %s Ruleset: %s Operation: %s", repr(published), rule, operation)

        if operation is not None:

            responseBody = operation.interceptResponse(rule, request.response)

            if responseBody is not None:

                # Only put this in the response if the operation actually
                # intercepted something

                request.response.setHeader(X_CACHE_OPERATION_HEADER, operationName)

                # Stop any post-processing, including the operation's response
                # modification
                if DISABLE_TRANSFORM_REQUEST_KEY not in request.environ:
                    request.environ[DISABLE_TRANSFORM_REQUEST_KEY] = True

                # The view is liable to have set a response status. Lock it
                # now so that it doesn't get set to 500 later.
                status = request.response.getStatus()
                if status:
                    request.response.setStatus(status, lock=True)

                raise Intercepted(status, responseBody)

    except ConflictError:
        raise
    except Intercepted:
        raise
    except:
        logging.exception("Swallowed exception in plone.caching IPubAfterTraversal event handler")
예제 #6
0
    def mutate(self):
        request = self.request

        # Abort if this was a streamed request handled by our event handler
        # below
        if IStreamedResponse.providedBy(request):
            return

        published = request.get('PUBLISHED', None)
        rule, operationName, operation = findOperation(request)

        if rule is None:
            return

        request.response.setHeader(X_CACHE_RULE_HEADER, rule)
        logger.debug('Published: %s Ruleset: %s Operation: %s',
                     repr(published), rule, operation)

        if operation is not None:
            request.response.setHeader(X_CACHE_OPERATION_HEADER, operationName)
            operation.modifyResponse(rule, request.response)