Class ConnectionHeaders
- java.lang.Object
-
- org.jenkinsci.remoting.protocol.impl.ConnectionHeaders
-
public final class ConnectionHeaders extends Object
Utility class to handle the encoding and decoding of the connection headers. Connections headers are encoded as a flat JSON object with exclusivelyString
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 trustObjectInputStream
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 aMap
withString
keys and values has the advantages-
there is a 1:1 mapping between a
Map
and a JSON object -
A JSON object cannot have
null
keys and neither can aMap
-
A JSON object can have
null
values 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
-
there is a 1:1 mapping between a
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ConnectionHeaders.ParseException
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
appendEscaped(StringBuilder b, String str)
static String
encodeEscape(int c)
static Map<String,String>
fromString(String data)
Converts the headers from the String format.static String
toString(Map<String,String> data)
Converts the headers into the String format.
-
-
-
Method Detail
-
toString
@NonNull public static String toString(@NonNull Map<String,String> data)
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
public static void appendEscaped(StringBuilder b, String str)
-
encodeEscape
public static String encodeEscape(int c)
-
-