Class UnconsumedBodyGuard
java.lang.Object
io.micronaut.http.server.netty.binders.UnconsumedBodyGuard
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 Summary
Modifier and TypeMethodDescriptionstatic InputStreamdiscardIfUnconsumed(HttpRequest<?> request, InputStream stream) Discard the given stream if the route fails before it returns, or if the route never reads from it.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.
-
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 withExpect: 100-continueis not sent a100 Continue, and it also releases a body that was already fully received.- Type Parameters:
T- The item type- Parameters:
request- The requestbody- The body, taken from the request by the binderopen- Opens the publisher for the body when the route subscribes- Returns:
- The publisher to pass to the route
-
discardIfUnconsumed
Discard the given stream if the route fails before it returns, or if the route never reads from it.- Parameters:
request- The requeststream- The stream that was bound from the request body- Returns:
- The stream to pass to the route
-