Class UnconsumedBodyGuard

java.lang.Object
io.micronaut.http.server.netty.binders.UnconsumedBodyGuard

@Internal public final class UnconsumedBodyGuard extends Object
Registers streaming body arguments that claim the request body when they are bound, so that the body is discarded if the route fails before it returns, or never subscribes to it (see BasicHttpAttributes.discardUnconsumedBodies(HttpRequest)). Without this, the data received so far stays buffered and the connection stops reading.
Since:
5.2.21
  • Method Details

    • openWhenSubscribed

      public static <T> Publisher<T> openWhenSubscribed(HttpRequest<?> request, CloseableByteBody body, Function<? super CloseableByteBody, ? extends Publisher<T>> open)
      Open a streaming body argument from the given body only once the route subscribes to it. If the route fails before it subscribes, the body is closed instead. Closing discards the body without asking the client for it, so a request with Expect: 100-continue is not sent a 100 Continue, and it also releases a body that was already fully received.
      Type Parameters:
      T - The item type
      Parameters:
      request - The request
      body - The body, taken from the request by the binder
      open - Opens the publisher for the body when the route subscribes
      Returns:
      The publisher to pass to the route
    • discardIfUnconsumed

      public static InputStream discardIfUnconsumed(HttpRequest<?> request, InputStream stream)
      Discard the given stream if the route fails before it returns, or if the route never reads from it.
      Parameters:
      request - The request
      stream - The stream that was bound from the request body
      Returns:
      The stream to pass to the route