Package com.shri.restinpeace.interceptor
Class ShortCircuitResponse
java.lang.Object
com.shri.restinpeace.interceptor.ShortCircuitResponse
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 Summary
Modifier and TypeMethodDescriptiongetBody()Returns the response body.Returns the response headers added viaheader(java.lang.String, java.lang.String).intReturns the response status code.Adds a header value, in addition to any already added under the same name.static ShortCircuitResponseA200 OKresponse with a body.static ShortCircuitResponseA response with an arbitrary status and body.
-
Method Details
-
ok
A200 OKresponse with a body.- Parameters:
body- the response body- Returns:
- the new response
-
status
A response with an arbitrary status and body.- Parameters:
status- the HTTP status codebody- the response body- Returns:
- the new response
-
header
Adds a header value, in addition to any already added under the same name.- Parameters:
name- the header namevalue- the header value- Returns:
- this response, for chaining
-
getStatus
public int getStatus()Returns the response status code.- Returns:
- the status code
-
getBody
Returns the response body.- Returns:
- the response body
-
getHeaders
Returns the response headers added viaheader(java.lang.String, java.lang.String).- Returns:
- the headers
-