Class ConnectionHeaders
java.lang.Object
org.jenkinsci.remoting.protocol.impl.ConnectionHeaders
Utility class to handle the encoding and decoding of the connection headers. Connections headers are encoded
as a flat JSON object with exclusively
String values. 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 ObjectInputStream or 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 Map with String keys 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 aMap -
A JSON object can have
nullvalues and so can aMap - 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!)
- Since:
- 3.0
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic voidappendEscaped(StringBuilder b, String str) static StringencodeEscape(int c) fromString(String data) Converts the headers from the String format.static StringConverts the headers into the String format.
-
Method Details
-
toString
Converts the headers into the String format.- Parameters:
data- the headers.- Returns:
- the string encoded header.
-
fromString
@NonNull public static Map<String,String> fromString(@NonNull String data) throws ConnectionHeaders.ParseException Converts the headers from the String format.- Parameters:
data- the string encoded headers.- Returns:
- the headers.
- Throws:
ConnectionHeaders.ParseException
-
appendEscaped
-
encodeEscape
-