## com.baidubce.util
Class HttpUtils

    java.lang.Object
      com.baidubce.util.HttpUtils

    public class HttpUtils

extends Object

Constructor Summary
`HttpUtils()`

Method Summary
`static URI` `appendUri(URI baseUri, String... pathComponents)` Append the given path to the given baseUri.
`static String` `generateHostHeader(URI uri)` Returns a host header according to the specified URI.
`static String` `getCanonicalQueryString(Map<String,String> parameters, boolean forSignature)`
`static boolean` `isUsingNonDefaultPort(URI uri)` Returns true if the specified URI is using a non-standard port (i.e.
`static String` `normalize(String value)` Normalize a string for use in BCE web service APIs.
`static String` `normalizePath(String path)` Normalize a string for use in url path.
`static void` `printRequest(org.apache.http.client.methods.HttpRequestBase request)`
`static void` `printResponse(org.apache.http.client.methods.CloseableHttpResponse response)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### HttpUtils

    public HttpUtils()

Method Detail

### normalizePath

    public static String normalizePath(String path)

  Normalize a string for use in url path. The algorithm is:

  1. Normalize the string
  2. replace all "%2F" with "/"
  3. replace all "//" with "/%2F"

  Bos object key can contain arbitrary characters, which may result double slash in the url path. Apache http client will replace "//" in the path with a single '/', which makes the object key incorrect. Thus we replace "//" with "/%2F" here.

  Parameters:
    `path` - the path string to normalize.
  Returns:
    the normalized path string.
  See Also:
    `normalize(String)`

### normalize

    public static String normalize(String value)

  Normalize a string for use in BCE web service APIs. The normalization algorithm is:

  1. Convert the string into a UTF-8 byte array.
  2. Encode all octets into percent-encoding, except all URI unreserved characters per the RFC 3986.

  All letters used in the percent-encoding are in uppercase.

  Parameters:
    `value` - the string to normalize.
  Returns:
    the normalized string.
  Throws:
    `UnsupportedEncodingException`

### generateHostHeader

    public static String generateHostHeader(URI uri)

  Returns a host header according to the specified URI. The host header is generated with the same logic used by apache http client, that is, append the port to hostname only if it is not the default port.

  Parameters:
    `uri` - the URI
  Returns:
    a host header according to the specified URI.

### isUsingNonDefaultPort

    public static boolean isUsingNonDefaultPort(URI uri)

  Returns true if the specified URI is using a non-standard port (i.e. any port other than 80 for HTTP URIs or any port other than 443 for HTTPS URIs).

  Parameters:
    `uri` - the URI
  Returns:
    True if the specified URI is using a non-standard port, otherwise false.

### getCanonicalQueryString

    public static String getCanonicalQueryString(Map<String,String> parameters,
                                                 boolean forSignature)

### appendUri

    public static URI appendUri(URI baseUri,
                                String... pathComponents)

  Append the given path to the given baseUri.

  This method will encode the given path but not the given baseUri.

  Parameters:
    `baseUri` -
    `pathComponents` -

### printRequest

    public static void printRequest(org.apache.http.client.methods.HttpRequestBase request)

### printResponse

    public static void printResponse(org.apache.http.client.methods.CloseableHttpResponse response)

Copyright © 2016. All rights reserved.