Package org.microproxy.http
Class HttpUtil
java.lang.Object
org.microproxy.http.HttpUtil
Helpers for connection-management and framing headers.
-
Method Summary
Modifier and TypeMethodDescriptionstatic longgetContentLength(HttpMessage message, long defaultValue) TheContent-Lengthvalue, ordefaultValueif absent or invalid.static booleanis100ContinueExpected(HttpRequest request) Whether the request carriesExpect: 100-continue.static booleanisKeepAlive(HttpMessage message) Whether the sender ofmessagewants the connection kept open afterwards, following theConnectionheader and the protocol version's default.static booleanisTransferEncodingChunked(HttpMessage message) Whether the final transfer coding ischunked.static voidsetContentLength(HttpMessage message, long length) Sets the Content-Length field to the supplied decimal value.static voidsetKeepAlive(HttpMessage message, boolean keepAlive) static voidsetTransferEncodingChunked(HttpMessage message, boolean chunked) Makeschunkedthe final transfer coding (keeping any other codings) and removesContent-Length, or removeschunkedagain whenchunkedis false.
-
Method Details
-
isKeepAlive
Whether the sender ofmessagewants the connection kept open afterwards, following theConnectionheader and the protocol version's default.- Parameters:
message- the message whose connection preference is inspected- Returns:
- whether the connection should remain open after the message
-
setKeepAlive
- Parameters:
message- the message whose Connection header is updatedkeepAlive- whether the connection should remain open
-
isTransferEncodingChunked
Whether the final transfer coding ischunked.- Parameters:
message- the message whose transfer codings are inspected- Returns:
- whether chunked is the final transfer coding
-
setTransferEncodingChunked
Makeschunkedthe final transfer coding (keeping any other codings) and removesContent-Length, or removeschunkedagain whenchunkedis false.- Parameters:
message- the message whose framing headers are updatedchunked- whether to append chunked or remove it from the transfer codings
-
getContentLength
TheContent-Lengthvalue, ordefaultValueif absent or invalid.- Parameters:
message- the message whose Content-Length is inspecteddefaultValue- the fallback for an absent or unparsable value- Returns:
- the parsed long value, or defaultValue
-
setContentLength
Sets the Content-Length field to the supplied decimal value.- Parameters:
message- the message whose Content-Length is updatedlength- the length value to write in decimal
-
is100ContinueExpected
Whether the request carriesExpect: 100-continue.- Parameters:
request- the request whose version and Expect header are inspected- Returns:
- whether persistence is the protocol default and the request expects 100-continue
-