@UnstableApi
class HttpUtil


Utility methods for HTTP.

Summary

Public functions

java-static String?
buildRangeRequestHeader(position: Long, length: Long)

Builds a Range header for the given position and length.

java-static Long
getContentLength(contentLengthHeader: String?, contentRangeHeader: String?)

Attempts to parse the length of a response body from the corresponding response headers.

java-static String!
getCookieHeader(
    url: String!,
    headers: (Mutable)Map<String!, (Mutable)List<String!>!>!,
    cookieHandler: CookieHandler?
)

Returns the stored cookie header for the given response URL and headers.

java-static Long
getDocumentSize(contentRangeHeader: String?)

Attempts to parse the document size from a Content-Range header.

java-static Unit
storeCookiesFromHeaders(
    url: String!,
    headers: (Mutable)Map<String!, (Mutable)List<String!>!>!,
    cookieHandler: CookieHandler?
)

Stores the cookie headers from the response in the provided CookieHandler.

Public functions

buildRangeRequestHeader

java-static fun buildRangeRequestHeader(position: Long, length: Long): String?

Builds a Range header for the given position and length.

Parameters
position: Long

The request position.

length: Long

The request length, or LENGTH_UNSET if the request is unbounded.

Returns
String?

The corresponding range header, or null if a header is unnecessary because the whole resource is being requested.

getContentLength

java-static fun getContentLength(contentLengthHeader: String?, contentRangeHeader: String?): Long

Attempts to parse the length of a response body from the corresponding response headers.

Parameters
contentLengthHeader: String?

The Content-Length header, or null if not set.

contentRangeHeader: String?

The Content-Range header, or null if not set.

Returns
Long

The length of the response body, or LENGTH_UNSET if it could not be determined.

getCookieHeader

java-static fun getCookieHeader(
    url: String!,
    headers: (Mutable)Map<String!, (Mutable)List<String!>!>!,
    cookieHandler: CookieHandler?
): String!

Returns the stored cookie header for the given response URL and headers.

Parameters
url: String!

The URL of the response.

headers: (Mutable)Map<String!, (Mutable)List<String!>!>!

The headers of the response.

cookieHandler: CookieHandler?

The CookieHandler to store the cookies in. If null, no cookies will be available.

Returns
String!

The cookie header string that can be added to requests with COOKIE.

getDocumentSize

java-static fun getDocumentSize(contentRangeHeader: String?): Long

Attempts to parse the document size from a Content-Range header.

Parameters
contentRangeHeader: String?

The Content-Range header, or null if not set.

Returns
Long

The document size, or LENGTH_UNSET if it could not be determined.

storeCookiesFromHeaders

java-static fun storeCookiesFromHeaders(
    url: String!,
    headers: (Mutable)Map<String!, (Mutable)List<String!>!>!,
    cookieHandler: CookieHandler?
): Unit

Stores the cookie headers from the response in the provided CookieHandler.

Parameters
url: String!

The URL of the response.

headers: (Mutable)Map<String!, (Mutable)List<String!>!>!

The headers of the response.

cookieHandler: CookieHandler?

The CookieHandler to store the cookies in. If null, no cookies will be stored.