Package io.github.mahmoudimus.http2
Class Http2Exception
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.io.IOException
io.github.mahmoudimus.http2.Http2Exception
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
HeaderListSizeException
A violation of HTTP/2 or HPACK by the peer (or a limit it exceeded), with the error code to send
back and the scope of the error (RFC 9113 §5.4).
- A connection error (
isConnectionError()) leaves the connection unusable: send GOAWAY witherrorCode()and close it. The reader that threw it must not be used again. - A stream error affects only
streamId(): send RST_STREAM witherrorCode()and carry on. When aFrameReaderthrows one it has consumed the whole offending frame, so reading can continue.
Any stream error may be treated as a connection error by a caller that prefers to.
- See Also:
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedHttp2Exception(ErrorCode errorCode, int streamId, boolean connectionError, String message) Creates an error with an explicit protocol scope. -
Method Summary
Modifier and TypeMethodDescriptionstatic Http2ExceptionconnectionError(ErrorCode errorCode, String message) An error that ends the connection.The code to send in GOAWAY (connection error) or RST_STREAM (stream error).booleanReports whether the connection must be closed.static Http2ExceptionstreamError(int streamId, ErrorCode errorCode, String message) An error that ends only the given stream.intstreamId()The stream in error, or 0 for a connection error.Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
Http2Exception
protected Http2Exception(ErrorCode errorCode, int streamId, boolean connectionError, String message) Creates an error with an explicit protocol scope.- Parameters:
errorCode- the non-null code to report to the peerstreamId- the affected stream identifier, or 0 for the connectionconnectionError- whether the entire connection is unusablemessage- the diagnostic message
-
-
Method Details
-
connectionError
An error that ends the connection.- Parameters:
errorCode- the non-null code to report to the peermessage- the diagnostic message- Returns:
- a connection-scoped exception
-
streamError
An error that ends only the given stream.- Parameters:
streamId- the positive identifier of the affected streamerrorCode- the non-null code to report to the peermessage- the diagnostic message- Returns:
- a stream-scoped exception
-
errorCode
The code to send in GOAWAY (connection error) or RST_STREAM (stream error).- Returns:
- the code to report to the peer
-
streamId
public int streamId()The stream in error, or 0 for a connection error.- Returns:
- the affected stream identifier, or 0 for a connection error
-
isConnectionError
public boolean isConnectionError()Reports whether the connection must be closed.- Returns:
- true for a connection error, false for a stream error
-
getMessage
- Overrides:
getMessagein classThrowable
-