@UnstableApi
public final class HttpUtil


Utility methods for HTTP.

Summary

Public methods

static @Nullable String
buildRangeRequestHeader(long position, long length)

Builds a Range header for the given position and length.

static long
getContentLength(
    @Nullable String contentLengthHeader,
    @Nullable String contentRangeHeader
)

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

static long
getDocumentSize(@Nullable String contentRangeHeader)

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

Public methods

buildRangeRequestHeader

public static @Nullable String buildRangeRequestHeader(long position, long length)

Builds a Range header for the given position and length.

Parameters
long position

The request position.

long length

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

Returns
@Nullable String

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

getContentLength

public static long getContentLength(
    @Nullable String contentLengthHeader,
    @Nullable String contentRangeHeader
)

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

Parameters
@Nullable String contentLengthHeader

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

@Nullable String contentRangeHeader

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.

getDocumentSize

public static long getDocumentSize(@Nullable String contentRangeHeader)

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

Parameters
@Nullable String contentRangeHeader

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

Returns
long

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