Class SdkHttpUtils
- java.lang.Object
-
- software.amazon.awssdk.utils.http.SdkHttpUtils
-
public final class SdkHttpUtils extends Object
A set of utilities that assist with HTTP message-related interactions.
-
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static Stream<String>
allMatchingHeaders(Map<String,List<String>> headers, String header)
Deprecated.UseSdkHttpHeaders#matchingHeaders
static Stream<String>
allMatchingHeadersFromCollection(Map<String,List<String>> headersToSearch, Collection<String> headersToFind)
Deprecated.UseSdkHttpHeaders#matchingHeaders
static String
appendUri(String baseUri, String path)
Append the given path to the given baseUri, separating them with a slash, if required.static Optional<String>
encodeAndFlattenFormData(Map<String,List<String>> rawFormData)
Encode the provided form data usingencodeFormData(Map)
and then flatten them into a string that can be used as the body of a form data request.static Optional<String>
encodeAndFlattenQueryParameters(Map<String,List<String>> rawQueryParameters)
Encode the provided query parameters usingencodeQueryParameters(Map)
and then flatten them into a string that can be used as the query string in a URL.static Map<String,List<String>>
encodeFormData(Map<String,List<String>> rawFormData)
Encode each of the keys and values in the provided form data usingformDataEncode(String)
.static Map<String,List<String>>
encodeQueryParameters(Map<String,List<String>> rawQueryParameters)
Encode each of the keys and values in the provided query parameters usingurlEncode(String)
.static Optional<String>
firstMatchingHeader(Map<String,List<String>> headers, String header)
Deprecated.UseSdkHttpHeaders#firstMatchingHeader
static Optional<String>
firstMatchingHeaderFromCollection(Map<String,List<String>> headersToSearch, Collection<String> headersToFind)
Deprecated.UseSdkHttpHeaders#firstMatchingHeader
static void
flattenQueryParameters(StringBuilder result, Map<String,List<String>> toFlatten)
Flatten the provided query parameters into a string that can be used as the query string in a URL.static Optional<String>
flattenQueryParameters(Map<String,List<String>> toFlatten)
Flatten the provided query parameters into a string that can be used as the query string in a URL.static String
formDataEncode(String value)
Encode a string according to RFC 1630: encoding for form data.static boolean
isSingleHeader(String h)
static boolean
isUsingStandardPort(String protocol, Integer port)
Returns true if the specified port is the standard port for the given protocol.static Set<String>
parseNonProxyHostsEnvironmentVariable()
static Set<String>
parseNonProxyHostsProperty()
Returns the Java system property for nonProxyHosts as set of Strings.static List<String>
splitQueryString(String queryString)
static int
standardPort(String protocol)
Retrieve the standard port for the provided protocol.static Map<String,List<String>>
uriParams(URI uri)
Extracts query parameters from the given URIstatic String
urlDecode(String value)
Decode the string according to RFC 3986: encoding for URI paths, query strings, etc.static String
urlEncode(String value)
Encode a string according to RFC 3986: encoding for URI paths, query strings, etc.static String
urlEncodeIgnoreSlashes(String value)
Encode a string according to RFC 3986, but ignore "/" characters.
-
-
-
Method Detail
-
urlEncode
public static String urlEncode(String value)
Encode a string according to RFC 3986: encoding for URI paths, query strings, etc.
-
urlEncodeIgnoreSlashes
public static String urlEncodeIgnoreSlashes(String value)
Encode a string according to RFC 3986, but ignore "/" characters. This is useful for encoding the components of a path, without encoding the path separators.
-
formDataEncode
public static String formDataEncode(String value)
Encode a string according to RFC 1630: encoding for form data.
-
urlDecode
public static String urlDecode(String value)
Decode the string according to RFC 3986: encoding for URI paths, query strings, etc.Assumes the decoded string is UTF-8 encoded.
- Parameters:
value
- The string to decode.- Returns:
- The decoded string.
-
encodeQueryParameters
public static Map<String,List<String>> encodeQueryParameters(Map<String,List<String>> rawQueryParameters)
Encode each of the keys and values in the provided query parameters usingurlEncode(String)
.
-
encodeFormData
public static Map<String,List<String>> encodeFormData(Map<String,List<String>> rawFormData)
Encode each of the keys and values in the provided form data usingformDataEncode(String)
.
-
encodeAndFlattenQueryParameters
public static Optional<String> encodeAndFlattenQueryParameters(Map<String,List<String>> rawQueryParameters)
Encode the provided query parameters usingencodeQueryParameters(Map)
and then flatten them into a string that can be used as the query string in a URL. The result is not prepended with "?".
-
encodeAndFlattenFormData
public static Optional<String> encodeAndFlattenFormData(Map<String,List<String>> rawFormData)
Encode the provided form data usingencodeFormData(Map)
and then flatten them into a string that can be used as the body of a form data request.
-
flattenQueryParameters
public static Optional<String> flattenQueryParameters(Map<String,List<String>> toFlatten)
Flatten the provided query parameters into a string that can be used as the query string in a URL. The result is not prepended with "?". This is useful when you have already-encoded query parameters you wish to flatten.
-
flattenQueryParameters
public static void flattenQueryParameters(StringBuilder result, Map<String,List<String>> toFlatten)
Flatten the provided query parameters into a string that can be used as the query string in a URL. The result is not prepended with "?". This is useful when you have already-encoded query parameters you wish to flatten.
-
isUsingStandardPort
public static boolean isUsingStandardPort(String protocol, Integer port)
Returns true if the specified port is the standard port for the given protocol. (i.e. 80 for HTTP or 443 for HTTPS). Null or -1 ports (to simplify interaction withURI
's default value) are treated as standard ports.- Returns:
- True if the specified port is standard for the specified protocol, otherwise false.
-
standardPort
public static int standardPort(String protocol)
Retrieve the standard port for the provided protocol.
-
appendUri
public static String appendUri(String baseUri, String path)
Append the given path to the given baseUri, separating them with a slash, if required. The result will preserve the trailing slash of the provided path.
-
allMatchingHeaders
@Deprecated public static Stream<String> allMatchingHeaders(Map<String,List<String>> headers, String header)
Deprecated.UseSdkHttpHeaders#matchingHeaders
Perform a case-insensitive search for a particular header in the provided map of headers.- Parameters:
headers
- The headers to search.header
- The header to search for (case insensitively).- Returns:
- A stream providing the values for the headers that matched the requested header.
-
allMatchingHeadersFromCollection
@Deprecated public static Stream<String> allMatchingHeadersFromCollection(Map<String,List<String>> headersToSearch, Collection<String> headersToFind)
Deprecated.UseSdkHttpHeaders#matchingHeaders
Perform a case-insensitive search for a particular header in the provided map of headers.- Parameters:
headersToSearch
- The headers to search.headersToFind
- The headers to search for (case insensitively).- Returns:
- A stream providing the values for the headers that matched the requested header.
-
firstMatchingHeader
@Deprecated public static Optional<String> firstMatchingHeader(Map<String,List<String>> headers, String header)
Deprecated.UseSdkHttpHeaders#firstMatchingHeader
Perform a case-insensitive search for a particular header in the provided map of headers, returning the first matching header, if one is found.
This is useful for headers like 'Content-Type' or 'Content-Length' of which there is expected to be only one value present.- Parameters:
headers
- The headers to search.header
- The header to search for (case insensitively).- Returns:
- The first header that matched the requested one, or empty if one was not found.
-
firstMatchingHeaderFromCollection
@Deprecated public static Optional<String> firstMatchingHeaderFromCollection(Map<String,List<String>> headersToSearch, Collection<String> headersToFind)
Deprecated.UseSdkHttpHeaders#firstMatchingHeader
Perform a case-insensitive search for a set of headers in the provided map of headers, returning the first matching header, if one is found.- Parameters:
headersToSearch
- The headers to search.headersToFind
- The header to search for (case insensitively).- Returns:
- The first header that matched a requested one, or empty if one was not found.
-
isSingleHeader
public static boolean isSingleHeader(String h)
-
uriParams
public static Map<String,List<String>> uriParams(URI uri)
Extracts query parameters from the given URI
-
parseNonProxyHostsProperty
public static Set<String> parseNonProxyHostsProperty()
Returns the Java system property for nonProxyHosts as set of Strings. See http://docs.oracle.com/javase/7/docs/api/java/net/doc-files/net-properties.html
-
-