Class NettyRequest
- java.lang.Object
-
- org.asynchttpclient.netty.request.NettyRequest
-
public final class NettyRequest extends Object
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description NettyBodygetBody()io.netty.handler.codec.http.HttpRequestgetHttpRequest()booleanisHandedToChannel()booleanmarkHandedToChannel()Atomically claimsgetHttpRequest()for a channel write (the HTTP/1.1 path), after which Netty's encoder owns its release.voidrelease()Releases the underlying HTTP/1.1HttpRequest(and the request-bodyByteBufit holds) — but only while AsyncHttpClient still owns it (it was never handed to a channel write).
-
-
-
Method Detail
-
getHttpRequest
public io.netty.handler.codec.http.HttpRequest getHttpRequest()
-
getBody
public NettyBody getBody()
-
release
public void release()
Releases the underlying HTTP/1.1HttpRequest(and the request-bodyByteBufit holds) — but only while AsyncHttpClient still owns it (it was never handed to a channel write). OncemarkHandedToChannel()has claimed it, Netty's encoder owns the release and this becomes a no-op, so the two can never double-free. The atomic CAS also closes the check-then-release TOCTOU an externalisHandedToChannel()test would leave between an abort thread and the event-loop write.In the HTTP/2 path the
httpRequestobject is never written to a channel — its content is re-encoded as HTTP/2 frames — so AHC always owns its release and this performs it. The early-abort paths (a draining/closed/queued-then-dropped connection, or a crashingonRequestSend) call it too. Idempotent and thread-safe — extra calls are no-ops.
-
markHandedToChannel
public boolean markHandedToChannel()
Atomically claimsgetHttpRequest()for a channel write (the HTTP/1.1 path), after which Netty's encoder owns its release. Returnstrueif the caller may proceed with the write; returnsfalsewhen a concurrent abort/cancel/timeout has ALREADY released the request body — in which case the caller MUST NOT write the now-freed buffer. This single CAS resolves the double-free/use-after-free race a separatehandedToChannelflag plus a non-atomicrelease()would otherwise allow (e.g. asetBody(ByteBuf)request cancelled on one thread while the event loop writes it).
-
isHandedToChannel
public boolean isHandedToChannel()
-
-