Class ShortCircuitResponse

java.lang.Object
com.shri.restinpeace.interceptor.ShortCircuitResponse

public final class ShortCircuitResponse extends Object
A synthetic response a RequestInterceptor.shortCircuit(com.shri.restinpeace.interceptor.RequestContext) can hand back to skip the network call entirely - the request is never sent, and this response is decoded exactly as if it had come back from a real one (including throwing RestInPeaceHttpException for a non-2xx status, and being visible to every registered interceptor's own afterResponse). Enables a feature-flag bypass, a canary short-circuit, or a lightweight record/replay mode built on the interceptor chain.

A byte[]-returning method sees getBody() re-encoded as UTF-8 bytes; a File-returning method has those bytes written to its destination file, same as a real response's would be.

  • Method Details

    • ok

      public static ShortCircuitResponse ok(String body)
      A 200 OK response with a body.
      Parameters:
      body - the response body
      Returns:
      the new response
    • status

      public static ShortCircuitResponse status(int status, String body)
      A response with an arbitrary status and body.
      Parameters:
      status - the HTTP status code
      body - the response body
      Returns:
      the new response
    • header

      public ShortCircuitResponse header(String name, String value)
      Adds a header value, in addition to any already added under the same name.
      Parameters:
      name - the header name
      value - the header value
      Returns:
      this response, for chaining
    • getStatus

      public int getStatus()
      Returns the response status code.
      Returns:
      the status code
    • getBody

      public String getBody()
      Returns the response body.
      Returns:
      the response body
    • getHeaders

      public Map<String,List<String>> getHeaders()
      Returns the response headers added via header(java.lang.String, java.lang.String).
      Returns:
      the headers