public class HttpRequestUtils
extends java.lang.Object
| Constructor and Description |
|---|
HttpRequestUtils() |
| Modifier and Type | Method and Description |
|---|---|
static java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
getCookieHeaders(java.net.CookieManager cookieManager,
java.net.URL url)
Get the cookie headers for a URL.
|
static java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
mergeHeaders(java.util.Map<java.lang.String,java.util.List<java.lang.String>>... maps)
Merge multiple headers into one map.
|
static java.time.Instant |
parseHttpDate(java.lang.String httpDate)
Parse a HTTP date.
|
static java.lang.Long |
parseSecondsOrHttpDate(java.lang.String value)
Parse an HTTP date or seconds string as milliseconds until the date.
|
static byte[] |
readBody(java.net.HttpURLConnection connection)
Read the body of a connection.
|
static byte[] |
readFromStream(java.io.InputStream is)
Read the body of a connection.
|
static void |
setHeaders(java.net.HttpURLConnection connection,
java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers)
Set the headers for a connection.
|
static void |
updateCookies(java.net.CookieManager cookieManager,
java.net.URL url,
java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers)
Update the cookies for a URL.
|
@SafeVarargs
public static java.util.Map<java.lang.String,java.util.List<java.lang.String>> mergeHeaders(@Nonnull
java.util.Map<java.lang.String,java.util.List<java.lang.String>>... maps)
maps - The headers to mergepublic static java.util.Map<java.lang.String,java.util.List<java.lang.String>> getCookieHeaders(@Nullable
java.net.CookieManager cookieManager,
@Nonnull
java.net.URL url)
throws java.io.IOException
cookieManager - The cookie manager to useurl - The URL to get the cookies forjava.io.IOException - If an I/O error occurspublic static void updateCookies(@Nullable
java.net.CookieManager cookieManager,
@Nonnull
java.net.URL url,
@Nonnull
java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers)
throws java.io.IOException
cookieManager - The cookie manager to useurl - The URL to update the cookies forheaders - The headers to update the cookies fromjava.io.IOException - If an I/O error occurspublic static void setHeaders(@Nonnull
java.net.HttpURLConnection connection,
@Nonnull
java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers)
connection - The connection to set the headers forheaders - The headers to setpublic static byte[] readBody(@Nonnull
java.net.HttpURLConnection connection)
throws java.io.IOException
connection - The connection to read the body fromjava.io.IOException - If an I/O error occurspublic static byte[] readFromStream(@Nonnull @WillNotClose
java.io.InputStream is)
throws java.io.IOException
is - The input stream to read the body fromjava.io.IOException - If an I/O error occurspublic static java.time.Instant parseHttpDate(java.lang.String httpDate)
throws java.time.format.DateTimeParseException
httpDate - The HTTP date to parsejava.time.format.DateTimeParseException - If the date could not be parsed@Nullable public static java.lang.Long parseSecondsOrHttpDate(java.lang.String value)
value - The value to parse