Module bus.http

Interface PushObserver


public interface PushObserver
An interface for handling server-initiated HTTP requests, specific to HTTP/2.

Implementations of this interface can choose to cancel pushed streams by returning true. Note that this does not guarantee that future frames will not arrive for the canceled stream ID.

Since:
Java 17+
Author:
Kimi Liu
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final PushObserver
    A push observer that cancels all incoming pushed streams.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    onData(int streamId, org.miaixz.bus.core.io.source.BufferSource source, int byteCount, boolean last)
    A block of response data corresponding to the pushed request.
    boolean
    onHeaders(int streamId, List<Http2Header> responseHeaders, boolean last)
    The response headers corresponding to the pushed request.
    boolean
    onRequest(int streamId, List<Http2Header> requestHeaders)
    Describes the request that the server intends to push a response for.
    void
    onReset(int streamId, Http2ErrorCode errorCode)
    Indicates the reason why this stream was canceled.
  • Field Details

    • CANCEL

      static final PushObserver CANCEL
      A push observer that cancels all incoming pushed streams.
  • Method Details

    • onRequest

      boolean onRequest(int streamId, List<Http2Header> requestHeaders)
      Describes the request that the server intends to push a response for.
      Parameters:
      streamId - The server-initiated stream ID, which will be an even number.
      requestHeaders - The request headers, minimally including method, scheme, authority, and path.
      Returns:
      true to cancel the pushed stream, false to accept it.
    • onHeaders

      boolean onHeaders(int streamId, List<Http2Header> responseHeaders, boolean last)
      The response headers corresponding to the pushed request. When last is true, there are no subsequent data frames.
      Parameters:
      streamId - The server-initiated stream ID, which will be an even number.
      responseHeaders - The response headers, minimally including the status.
      last - true if there is no response data.
      Returns:
      true to cancel the pushed stream, false to accept it.
    • onData

      boolean onData(int streamId, org.miaixz.bus.core.io.source.BufferSource source, int byteCount, boolean last) throws IOException
      A block of response data corresponding to the pushed request. This data must be read or skipped.
      Parameters:
      streamId - The server-initiated stream ID, which will be an even number.
      source - The source of the data corresponding to this stream ID.
      byteCount - The number of bytes to read or skip from the source.
      last - true if no more data frames will follow.
      Returns:
      true to cancel the pushed stream, false to accept it.
      Throws:
      IOException - if an I/O error occurs.
    • onReset

      void onReset(int streamId, Http2ErrorCode errorCode)
      Indicates the reason why this stream was canceled.
      Parameters:
      streamId - The server-initiated stream ID, which will be an even number.
      errorCode - The error code indicating the reason for cancellation.