public final class ConnectionHeaders extends ObjectUtility class to handle the encoding and decoding of the connection headers. Connections headers are encoded as a flat JSON object with exclusively
Stringvalues. We use a pure text based format as this information will be used to decide whether to accept a connection with the remote end, thus, until the connection has been accepted we should not trust
ObjectInputStreamor an equivalent based mechanism for exchange of pre-connection headers. We could use a header format equivalent to that of HTTP headers, the JSON format of mapping two/from a
Stringkeys and values has the advantages
there is a 1:1 mapping between a
Mapand a JSON object
A JSON object cannot have
nullkeys and neither can a
A JSON object can have
nullvalues and so can a
- A JSON object can only have one value for any key whereas something like the HTTP Header format allows for multiple values on any specific header
- Tooling such as wireshark can detect JSON formatted data and present it nicely. (We are assuming here that most usage of the headers will be after a TLS connection has been set-up and thus anyone using wireshark to sniff the packets has access to both side's private keys and as such is trusted to actually be peeking into the headers!)
- there is a 1:1 mapping between a
Nested Class Summary
Nested Classes Modifier and Type Class Description
All Methods Static Methods Concrete Methods Modifier and Type Method Description
appendEscaped(StringBuilder b, String str)
fromString(String data)Converts the headers from the String format.
toString(Map<String,String> data)Converts the headers into the String format.
toStringConverts the headers into the String format.
data- the headers.
- the string encoded header.
@NonNull public static Map<String,String> fromString(@NonNull String data) throws ConnectionHeaders.ParseExceptionConverts the headers from the String format.
data- the string encoded headers.
- the headers.
public static String encodeEscape(int c)