Class SdkHttpUtils


  • public final class SdkHttpUtils
    extends Object
    A set of utilities that assist with HTTP message-related interactions.
    • 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.
      • encodeAndFlattenQueryParameters

        public static Optional<String> encodeAndFlattenQueryParameters​(Map<String,​List<String>> rawQueryParameters)
        Encode the provided query parameters using encodeQueryParameters(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 using encodeFormData(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 with URI'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.
        Use SdkHttpHeaders#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.
        Use SdkHttpHeaders#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.
        Use SdkHttpHeaders#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.
        Use SdkHttpHeaders#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
      • splitQueryString

        public static List<String> splitQueryString​(String queryString)
      • 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
      • parseNonProxyHostsEnvironmentVariable

        public static Set<String> parseNonProxyHostsEnvironmentVariable()