Package org.mockserver.model
Class HttpError
- Author:
- jamesdbloom
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumWell-known stream-level error codes for HTTP/2 (RFC 7540 section 7) and HTTP/3 (RFC 9114 section 8.1).Nested classes/interfaces inherited from class org.mockserver.model.Action
Action.Direction, Action.Type -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanstatic HttpErrorerror()byte[]The stream/RST error code to send, or null when no stream error is configured (the default, preserving the existing dropConnection/responseBytes behaviour).getType()inthashCode()withDropConnection(Boolean dropConnection) Forces the connection to be dropped without any response being returned.withResponseBytes(byte[] responseBytes) The raw response to be returned, allowing the expectation to specify any invalid response as a raw byte[]withStreamError(long streamError) Resets the individual request stream with the supplied error code instead of returning a normal response.withStreamError(HttpError.StreamErrorCode streamErrorCode) Resets the individual request stream with a well-known error code.withStreamErrorCodeName(String streamErrorCodeName) Resets the individual request stream with a well-known error code named by its mnemonic, e.g.Methods inherited from class org.mockserver.model.Action
getDelay, getExpectationId, isPrimary, setExpectationId, withDelay, withDelay, withPrimaryMethods inherited from class org.mockserver.model.ObjectWithJsonToString
toStringMethods inherited from class org.mockserver.model.ObjectWithReflectiveEqualsHashCodeToString
fieldsExcludedFromEqualsAndHashCode
-
Constructor Details
-
HttpError
public HttpError()
-
-
Method Details
-
error
-
withDropConnection
Forces the connection to be dropped without any response being returned.Precedence: when
streamErroris also set it takes precedence anddropConnectionis ignored (the matched request stream is reset instead of the whole connection being dropped). Note that on HTTP/1.1 a streamError has no stream to reset and itself falls back to dropping the connection, so the observable behaviour is the same there.- Parameters:
dropConnection- if true the connection is drop without any response being returned
-
getDropConnection
-
withResponseBytes
The raw response to be returned, allowing the expectation to specify any invalid response as a raw byte[]- Parameters:
responseBytes- the exact bytes that will be returned
-
getResponseBytes
public byte[] getResponseBytes() -
withStreamError
Resets the individual request stream with the supplied error code instead of returning a normal response. Over HTTP/2 this sends a RST_STREAM frame for the matched stream (RFC 7540 section 6.4); over HTTP/3 this sends a RESET_STREAM for the matched QUIC stream (RFC 9114 section 4.1). Other multiplexed streams on the same connection are unaffected. HTTP/1.1 has no stream concept, so a stream error falls back to dropping the whole connection.- Parameters:
streamError- the stream/RST error code to send (32-bit for HTTP/2 per RFC 7540 section 7; HTTP/3 codes per RFC 9114 section 8.1)
-
withStreamError
Resets the individual request stream with a well-known error code. Convenience overload ofwithStreamError(long)that takes aHttpError.StreamErrorCodemnemonic.- Parameters:
streamErrorCode- the well-known error code to send
-
withStreamErrorCodeName
Resets the individual request stream with a well-known error code named by its mnemonic, e.g."REFUSED_STREAM"or"H3_REQUEST_CANCELLED"(case-insensitive). Convenience overload ofwithStreamError(long).- Parameters:
streamErrorCodeName- the mnemonic of aHttpError.StreamErrorCode- Throws:
IllegalArgumentException- if the name is not a known stream error code
-
getStreamError
The stream/RST error code to send, or null when no stream error is configured (the default, preserving the existing dropConnection/responseBytes behaviour). -
getType
-
equals
-
hashCode
public int hashCode()
-