Class HttpRequestUtils
- java.lang.Object
-
- net.lenni0451.commons.httpclient.utils.HttpRequestUtils
-
public class HttpRequestUtils extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description HttpRequestUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method 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.InstantparseHttpDate(java.lang.String httpDate)Parse a HTTP date.static java.lang.LongparseSecondsOrHttpDate(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 voidsetHeaders(java.net.HttpURLConnection connection, java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers)Set the headers for a connection.static voidupdateCookies(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.
-
-
-
Method Detail
-
mergeHeaders
@SafeVarargs public 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.- Parameters:
maps- The headers to merge- Returns:
- The merged headers
-
getCookieHeaders
public static java.util.Map<java.lang.String,java.util.List<java.lang.String>> getCookieHeaders(@Nullable java.net.CookieManager cookieManager, java.net.URL url) throws java.io.IOExceptionGet the cookie headers for a URL.- Parameters:
cookieManager- The cookie manager to useurl- The URL to get the cookies for- Returns:
- The cookie headers
- Throws:
java.io.IOException- If an I/O error occurs
-
updateCookies
public static void updateCookies(@Nullable java.net.CookieManager cookieManager, java.net.URL url, java.util.Map<java.lang.String,java.util.List<java.lang.String>> headers) throws java.io.IOExceptionUpdate the cookies for a URL.- Parameters:
cookieManager- The cookie manager to useurl- The URL to update the cookies forheaders- The headers to update the cookies from- Throws:
java.io.IOException- If an I/O error occurs
-
setHeaders
public 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.- Parameters:
connection- The connection to set the headers forheaders- The headers to set
-
readBody
public static byte[] readBody(java.net.HttpURLConnection connection) throws java.io.IOExceptionRead the body of a connection.- Parameters:
connection- The connection to read the body from- Returns:
- The body of the connection
- Throws:
java.io.IOException- If an I/O error occurs
-
readFromStream
public static byte[] readFromStream(@WillNotClose java.io.InputStream is) throws java.io.IOExceptionRead the body of a connection.- Parameters:
is- The input stream to read the body from- Returns:
- The body of the connection
- Throws:
java.io.IOException- If an I/O error occurs
-
parseHttpDate
public static java.time.Instant parseHttpDate(java.lang.String httpDate) throws java.time.format.DateTimeParseExceptionParse a HTTP date.- Parameters:
httpDate- The HTTP date to parse- Returns:
- The parsed date
- Throws:
java.time.format.DateTimeParseException- If the date could not be parsed
-
parseSecondsOrHttpDate
@Nullable public static java.lang.Long parseSecondsOrHttpDate(java.lang.String value)
Parse an HTTP date or seconds string as milliseconds until the date.- Parameters:
value- The value to parse- Returns:
- The parsed value in milliseconds
-
-