Class HttpError


public class HttpError extends Action<HttpError>
Author:
jamesdbloom
  • Constructor Details

    • HttpError

      public HttpError()
  • Method Details

    • error

      public static HttpError error()
    • withDropConnection

      public HttpError withDropConnection(Boolean dropConnection)
      Forces the connection to be dropped without any response being returned.

      Precedence: when streamError is also set it takes precedence and dropConnection is 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

      public Boolean getDropConnection()
    • withResponseBytes

      public HttpError withResponseBytes(byte[] responseBytes)
      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

      public HttpError withStreamError(long streamError)
      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

      public HttpError withStreamError(HttpError.StreamErrorCode streamErrorCode)
      Resets the individual request stream with a well-known error code. Convenience overload of withStreamError(long) that takes a HttpError.StreamErrorCode mnemonic.
      Parameters:
      streamErrorCode - the well-known error code to send
    • withStreamErrorCodeName

      public HttpError withStreamErrorCodeName(String streamErrorCodeName)
      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 of withStreamError(long).
      Parameters:
      streamErrorCodeName - the mnemonic of a HttpError.StreamErrorCode
      Throws:
      IllegalArgumentException - if the name is not a known stream error code
    • getStreamError

      public Long 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

      public Action.Type getType()
      Specified by:
      getType in class Action<HttpError>
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Action<HttpError>
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Action<HttpError>