Interface ResponseInterceptor


  • public interface ResponseInterceptor
    A hook for intercepting responses before they are sent back to the client.
    Version:
    1.0
    Author:
    Daniel Flower
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void intercept​(io.muserver.MuRequest clientRequest, java.net.http.HttpRequest targetRequest, java.net.http.HttpResponse.ResponseInfo targetResponseInfo, io.muserver.MuResponse clientResponse)
      This function is called after the response from the target is received, and the response headers for the client are called.
    • Method Detail

      • intercept

        void intercept​(io.muserver.MuRequest clientRequest,
                       java.net.http.HttpRequest targetRequest,
                       java.net.http.HttpResponse.ResponseInfo targetResponseInfo,
                       io.muserver.MuResponse clientResponse)
                throws java.lang.Exception
        This function is called after the response from the target is received, and the response headers for the client are called. One use case is to add or remove headers or even response codes sent to the client.

        Note that the response body is not available for inspection and cannot be changed as the raw bytes will be streamed asynchronously to the client.

        Parameters:
        clientRequest - The original request from the client.
        targetRequest - The request that was sent to the target.
        targetResponseInfo - The responseInfo received from the target server, headers info is available.
        clientResponse - The as-yet unsent response to the client. You can modify the response code, content type and other headers, however you cannot alter the response body.
        Throws:
        java.lang.Exception - Any unhandled exceptions will be logged but will not stop the response being sent.