Package org.microproxy.quic
Class QuicMessage
java.lang.Object
org.microproxy.quic.QuicMessage
One whole message of a stream of an intercepted QUIC connection, as
QuicInterceptor.streamMessage(org.microproxy.quic.QuicMessage, org.microproxy.quic.QuicStreamContext) sees it: the payload a MessageFramer cut out of the stream
(without its length prefix or delimiter), which side sent it, on which stream, and when it was
complete.
Messages are immutable apart from data(), which a hook may change in place; the
with methods make changed copies, which the hook returns to send instead. The decoders
read the payload: dns() as DNS (DNS over QUIC), protobuf() as protobuf, and
render() with the content views, for logging.
-
Constructor Summary
ConstructorsConstructorDescriptionQuicMessage(byte[] data, boolean fromClient, long streamId, String alpn, Instant timestamp) A message. -
Method Summary
Modifier and TypeMethodDescriptionalpn()Returns the connection's ALPN protocol, or null.byte[]data()The payload.dns()The payload as a DNS message, as DNS over QUIC (doq) carries them.booleanReturns whether the client sent the message (it goes to the server), rather than the server.intlength()Returns the payload's length in bytes.protobuf()The payload as a protobuf message, without a schema: fields by number.protobuf(ProtoSchema schema, String messageType) The payload as a protobuf message ofmessageType, its fields named byschema.render()The payload rendered by the best of the default content views that can: as DNS for DNS over QUIC, else as what the bytes look like (protobuf, JSON, ...).render(ContentViews views) The payload rendered by the best ofviewsthat can.longstreamId()Returns the stream's ID on the client's connection.text()The payload decoded as UTF-8, malformed sequences replaced with U+FFFD.Returns when the proxy had the whole message.toString()withData(byte[] data) A copy of this message with another payload, the same direction, stream and timestamp.withDns(DnsMessage dns) A copy of this message whose payload isdns, encoded.withFromClient(boolean fromClient) A copy of this message going the other way, or the same: withfromClientit goes to the server, else to the client, on the same stream.A copy of this message with the UTF-8 encoding oftext.
-
Constructor Details
-
QuicMessage
A message.- Parameters:
data- the payload, which the message holds as it is (not copied)fromClient- whether the client sent it (it goes to the server), rather than the serverstreamId- the stream's ID on the client's connectionalpn- the connection's ALPN protocol, or nulltimestamp- when the proxy had the whole message
-
-
Method Details
-
data
public byte[] data()The payload. The array is the message's own, not a copy: a hook may change it in place and return the message.- Returns:
- the payload
-
length
public int length()Returns the payload's length in bytes.- Returns:
- the payload's length in bytes
-
fromClient
public boolean fromClient()Returns whether the client sent the message (it goes to the server), rather than the server.- Returns:
- whether the client sent the message (it goes to the server), rather than the server
-
streamId
public long streamId()Returns the stream's ID on the client's connection.- Returns:
- the stream's ID on the client's connection
-
alpn
Returns the connection's ALPN protocol, or null.- Returns:
- the connection's ALPN protocol, or null
-
timestamp
Returns when the proxy had the whole message.- Returns:
- when the proxy had the whole message
-
text
The payload decoded as UTF-8, malformed sequences replaced with U+FFFD.- Returns:
- the text
-
withData
A copy of this message with another payload, the same direction, stream and timestamp.- Parameters:
data- the payload of the copy (not copied)- Returns:
- the copy
-
withText
A copy of this message with the UTF-8 encoding oftext.- Parameters:
text- the text of the copy- Returns:
- the copy
-
withFromClient
A copy of this message going the other way, or the same: withfromClientit goes to the server, else to the client, on the same stream. A hook returns one to answer a side itself.- Parameters:
fromClient- whether the copy goes to the server- Returns:
- the copy
-
dns
The payload as a DNS message, as DNS over QUIC (doq) carries them.- Returns:
- the DNS message
- Throws:
IllegalArgumentException- if the payload is not a well-formed DNS message
-
withDns
A copy of this message whose payload isdns, encoded.- Parameters:
dns- the DNS message- Returns:
- the copy
-
protobuf
The payload as a protobuf message, without a schema: fields by number.- Returns:
- the message
- Throws:
DecodeException- if the payload is not a protobuf message
-
protobuf
The payload as a protobuf message ofmessageType, its fields named byschema.- Parameters:
schema- the schema, as fromProtoSchema.load(java.nio.file.Path)messageType- the message type's full name, such asshop.Order- Returns:
- the message
- Throws:
DecodeException- if the payload is not a protobuf message
-
render
The payload rendered by the best of the default content views that can: as DNS for DNS over QUIC, else as what the bytes look like (protobuf, JSON, ...).- Returns:
- the rendering, or empty when no view could render the payload
-
render
The payload rendered by the best ofviewsthat can. For DNS over QUIC, the views are told the payload is anapplication/dns-message.- Parameters:
views- the views- Returns:
- the rendering, or empty when no view could render the payload
-
toString
-