Package org.mockserver.netty.http3
Class Http3RequestBridge
java.lang.Object
org.mockserver.netty.http3.Http3RequestBridge
Converts between HTTP/3 frames and MockServer's
HttpRequest/HttpResponse model.
These are pure conversion helpers with no Netty channel dependencies, so they can be unit-tested without the native QUIC transport.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classParsed HTTP/3 pseudo-headers and regular headers. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaccumulateBody(io.netty.buffer.CompositeByteBuf composite, io.netty.handler.codec.http3.Http3DataFrame dataFrame) Accumulate body data from an HTTP/3 data frame into a composite buffer.static intlimitComponents(io.netty.buffer.CompositeByteBuf composite, int componentLimit, int merged) KeepscompositeundercomponentLimitcomponents whenaccumulateBody(io.netty.buffer.CompositeByteBuf, io.netty.handler.codec.http3.Http3DataFrame)alone does not, which takes pieces alternating between small and 16 KiB or more.parseHeaders(io.netty.handler.codec.http3.Http3HeadersFrame headersFrame) Extract pseudo-headers and regular headers from an HTTP/3 headers frame.static byte[]readAccumulatedBody(io.netty.buffer.CompositeByteBuf composite) Read the accumulated composite buffer into a byte array.static io.netty.handler.codec.http3.DefaultHttp3DataFrametoHttp3DataFrame(org.mockserver.model.HttpResponse response) Convert the body of a MockServerHttpResponseinto an HTTP/3 data frame.static io.netty.handler.codec.http3.DefaultHttp3HeadersFrametoHttp3HeadersFrame(org.mockserver.model.HttpResponse response) Convert a MockServerHttpResponseinto an HTTP/3 headers frame.static io.netty.handler.codec.http3.DefaultHttp3HeadersFrametoHttp3HeadersFrame(org.mockserver.model.HttpResponse response, boolean streaming) static io.netty.handler.codec.http3.DefaultHttp3HeadersFrametoHttp3TrailersFrame(org.mockserver.model.HttpResponse response) Build a trailing HTTP/3 HEADERS frame from the response trailers, or null when the response carries no trailers.static org.mockserver.model.HttpRequesttoHttpRequest(String method, String path, String scheme, String authority, List<Map.Entry<String, String>> headers, byte[] body) Build a MockServerHttpRequestfrom the HTTP/3 pseudo-headers and accumulated body bytes.static org.mockserver.model.HttpRequesttoHttpRequest(String method, String path, String scheme, String authority, List<Map.Entry<String, String>> headers, io.netty.buffer.ByteBuf body) AstoHttpRequest(String, String, String, String, List, byte[]), but reads the accumulated request body from theByteBufit was accumulated into, copying it once.static org.mockserver.model.HttpRequesttoHttpRequest(String method, String path, String scheme, String authority, List<Map.Entry<String, String>> headers, io.netty.buffer.ByteBuf body, io.netty.buffer.ByteBuf decompressedBody) AstoHttpRequest(String, String, String, String, List, ByteBuf), unlessdecompressedBody(the bodyHttp3RequestDecompressordecompressed) is non-null: the request is then the one HTTP/1.1's decompressor, aggregator and request mapper build.
-
Method Details
-
toHttpRequest
public static org.mockserver.model.HttpRequest toHttpRequest(String method, String path, String scheme, String authority, List<Map.Entry<String, String>> headers, byte[] body) Build a MockServerHttpRequestfrom the HTTP/3 pseudo-headers and accumulated body bytes.- Parameters:
method- the :method pseudo-header valuepath- the :path pseudo-header value (may include query string)scheme- the :scheme pseudo-header value (nullable)authority- the :authority pseudo-header value (nullable)headers- list of non-pseudo-header name/value pairsbody- the accumulated request body bytes (may be empty)- Returns:
- a fully populated HttpRequest
-
toHttpRequest
public static org.mockserver.model.HttpRequest toHttpRequest(String method, String path, String scheme, String authority, List<Map.Entry<String, String>> headers, io.netty.buffer.ByteBuf body) AstoHttpRequest(String, String, String, String, List, byte[]), but reads the accumulated request body from theByteBufit was accumulated into, copying it once.The body is decoded by
BodyDecoderEncoder.bytesToBody(byte[], java.lang.String), exactly as the HTTP/1.1 and HTTP/2 mappers do, so it keeps the wire bytes as its raw bytes and gets the same body type and charset for everyContent-Type.Buffer ownership: the body is read non-destructively (reader index is not advanced) and the buffer is not released here — the caller retains ownership and must release it (the production handler does so in a
finally, on every path including errors). -
toHttpRequest
public static org.mockserver.model.HttpRequest toHttpRequest(String method, String path, String scheme, String authority, List<Map.Entry<String, String>> headers, io.netty.buffer.ByteBuf body, io.netty.buffer.ByteBuf decompressedBody) AstoHttpRequest(String, String, String, String, List, ByteBuf), unlessdecompressedBody(the bodyHttp3RequestDecompressordecompressed) is non-null: the request is then the one HTTP/1.1's decompressor, aggregator and request mapper build. The body is the decompressed bytes and the wire bytes are kept as its original body (when they differ); acontent-lengthis replaced by the decompressed size, andcontent-encodingis kept but moved after the other headers. Neither buffer is released here. -
parseHeaders
public static Http3RequestBridge.ParsedHeaders parseHeaders(io.netty.handler.codec.http3.Http3HeadersFrame headersFrame) Extract pseudo-headers and regular headers from an HTTP/3 headers frame. -
toHttp3HeadersFrame
public static io.netty.handler.codec.http3.DefaultHttp3HeadersFrame toHttp3HeadersFrame(org.mockserver.model.HttpResponse response) Convert a MockServerHttpResponseinto an HTTP/3 headers frame. -
toHttp3HeadersFrame
public static io.netty.handler.codec.http3.DefaultHttp3HeadersFrame toHttp3HeadersFrame(org.mockserver.model.HttpResponse response, boolean streaming) AstoHttp3HeadersFrame(HttpResponse), additionally droppingcontent-lengthwhenstreamingis true. A streamed response's length is not known when the headers are sent, and acontent-lengthcopied from (for example) a relayed upstream response describes a different body than the one actually streamed - which a conforming client treats as a malformed message rather than merely ignoring. -
toHttp3TrailersFrame
public static io.netty.handler.codec.http3.DefaultHttp3HeadersFrame toHttp3TrailersFrame(org.mockserver.model.HttpResponse response) Build a trailing HTTP/3 HEADERS frame from the response trailers, or null when the response carries no trailers. The trailer field names are lower-cased per HTTP/3 (HTTP/2-style) header conventions. This is the general-purpose (non-gRPC) trailer frame; gRPC trailers (grpc-status / grpc-message) are emitted separately byHttp3GrpcResponseWriter. -
toHttp3DataFrame
public static io.netty.handler.codec.http3.DefaultHttp3DataFrame toHttp3DataFrame(org.mockserver.model.HttpResponse response) Convert the body of a MockServerHttpResponseinto an HTTP/3 data frame. Returns null if the response has no body. -
accumulateBody
public static void accumulateBody(io.netty.buffer.CompositeByteBuf composite, io.netty.handler.codec.http3.Http3DataFrame dataFrame) Accumulate body data from an HTTP/3 data frame into a composite buffer. HTTP/3 hands a body over in pieces of about one QUIC packet (1.1 KiB) whatever DATA frame size the client sent, so once the body has 64 components, pieces under 16 KiB are copied into 16 KiB blocks rather than kept one component each: each byte is copied at most once, and a body of one-byte pieces needs one component per 16 KiB. -
limitComponents
public static int limitComponents(io.netty.buffer.CompositeByteBuf composite, int componentLimit, int merged) KeepscompositeundercomponentLimitcomponents whenaccumulateBody(io.netty.buffer.CompositeByteBuf, io.netty.handler.codec.http3.Http3DataFrame)alone does not, which takes pieces alternating between small and 16 KiB or more.CompositeByteBuf's own consolidation copies the whole body each time; this copies only the components after the leadingmergedones into one. The whole-body copy once half the limit is merged blocks needs a component limit far smaller than the body bound it is derived from, whichmaxRequestBodySizecannot produce.- Returns:
- how many leading components are now merged blocks, to pass back on the next call
-
readAccumulatedBody
public static byte[] readAccumulatedBody(io.netty.buffer.CompositeByteBuf composite) Read the accumulated composite buffer into a byte array.
-