Class HttpUtil

java.lang.Object
com.landawn.abacus.http.HttpUtil

@Internal public final class HttpUtil extends Object
Since:
0.8
Author:
Haiyang Li
  • Field Details

    • DEFAULT_CHARSET

      public static final Charset DEFAULT_CHARSET
    • DEFAULT_CONTENT_FORMAT

      public static final ContentFormat DEFAULT_CONTENT_FORMAT
  • Method Details

    • isSuccessfulResponseCode

      public static boolean isSuccessfulResponseCode(int code)
      Parameters:
      code -
      Returns:
    • isValidHttpHeader

      public static boolean isValidHttpHeader(String key, String value)
      Parameters:
      key -
      value -
      Returns:
    • readHttpHeadValue

      public static String readHttpHeadValue(Object value)
      Parameters:
      value -
      Returns:
    • getContentType

      public static String getContentType(Map<String,?> httpHeaders)
      Parameters:
      httpHeaders -
      Returns:
    • getContentType

      public static String getContentType(HttpHeaders httpHeaders)
      Parameters:
      httpHeaders -
      Returns:
    • getContentType

      public static String getContentType(HttpSettings httpSettings)
      Parameters:
      httpSettings -
      Returns:
    • getContentType

      public static String getContentType(HttpURLConnection connection)
      Parameters:
      connection -
      Returns:
    • getContentEncoding

      public static String getContentEncoding(Map<String,?> httpHeaders)
      Parameters:
      httpHeaders -
      Returns:
    • getContentEncoding

      public static String getContentEncoding(HttpHeaders httpHeaders)
      Parameters:
      httpHeaders -
      Returns:
    • getContentEncoding

      public static String getContentEncoding(HttpSettings httpSettings)
      Parameters:
      httpSettings -
      Returns:
    • getContentEncoding

      public static String getContentEncoding(HttpURLConnection connection)
      Parameters:
      connection -
      Returns:
    • getAccept

      public static String getAccept(Map<String,?> httpHeaders)
      Parameters:
      httpHeaders -
      Returns:
    • getAccept

      public static String getAccept(HttpHeaders httpHeaders)
      Parameters:
      httpHeaders -
      Returns:
    • getAccept

      public static String getAccept(HttpSettings httpSettings)
      Parameters:
      httpSettings -
      Returns:
    • getAccept

      public static String getAccept(HttpURLConnection connection)
      Parameters:
      connection -
      Returns:
    • getAcceptEncoding

      public static String getAcceptEncoding(Map<String,?> httpHeaders)
      Parameters:
      httpHeaders -
      Returns:
    • getAcceptEncoding

      public static String getAcceptEncoding(HttpHeaders httpHeaders)
      Parameters:
      httpHeaders -
      Returns:
    • getAcceptEncoding

      public static String getAcceptEncoding(HttpSettings httpSettings)
      Parameters:
      httpSettings -
      Returns:
    • getAcceptEncoding

      public static String getAcceptEncoding(HttpURLConnection connection)
      Parameters:
      connection -
      Returns:
    • getAcceptCharset

      public static String getAcceptCharset(Map<String,?> httpHeaders)
      Parameters:
      httpHeaders -
      Returns:
    • getAcceptCharset

      public static String getAcceptCharset(HttpHeaders httpHeaders)
      Parameters:
      httpHeaders -
      Returns:
    • getAcceptCharset

      public static String getAcceptCharset(HttpSettings httpSettings)
      Parameters:
      httpSettings -
      Returns:
    • getAcceptCharset

      public static String getAcceptCharset(HttpURLConnection connection)
      Parameters:
      connection -
      Returns:
    • getContentType

      public static String getContentType(ContentFormat contentFormat)
      Gets the content type.
      Parameters:
      contentFormat -
      Returns:
    • getContentEncoding

      public static String getContentEncoding(ContentFormat contentFormat)
      Gets the content encoding.
      Parameters:
      contentFormat -
      Returns:
    • getContentFormat

      public static ContentFormat getContentFormat(String contentType, String contentEncoding)
      Gets the content format.
      Parameters:
      contentType -
      contentEncoding -
      Returns:
    • getContentFormat

      public static ContentFormat getContentFormat(HttpURLConnection connection)
      Gets the content format.
      Parameters:
      connection -
      Returns:
    • getResponseContentFormat

      public static ContentFormat getResponseContentFormat(Map<String,?> respHeaders, ContentFormat requestContentFormat)
      Parameters:
      respHeaders -
      requestContentFormat -
      Returns:
    • getParser

      public static <SC extends SerializationConfig<?>, DC extends DeserializationConfig<?>> Parser<SC,DC> getParser(ContentFormat contentFormat)
      Gets the parser.
      Type Parameters:
      SC -
      DC -
      Parameters:
      contentFormat -
      Returns:
    • wrapInputStream

      public static InputStream wrapInputStream(InputStream is, ContentFormat contentFormat)
      Wrap input stream.
      Parameters:
      is -
      contentFormat -
      Returns:
    • wrapOutputStream

      public static OutputStream wrapOutputStream(OutputStream os, ContentFormat contentFormat)
      Wrap output stream.
      Parameters:
      os -
      contentFormat -
      Returns:
    • getOutputStream

      public static OutputStream getOutputStream(HttpURLConnection connection, ContentFormat contentFormat, String contentType, String contentEncoding) throws IOException
      Gets the output stream.
      Parameters:
      connection -
      contentFormat -
      contentType -
      contentEncoding -
      Returns:
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • getInputStream

      public static InputStream getInputStream(HttpURLConnection connection, ContentFormat contentFormat) throws IOException
      Gets the input stream.
      Parameters:
      connection -
      contentFormat -
      Returns:
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • flush

      public static void flush(OutputStream os) throws IOException
      Parameters:
      os -
      Throws:
      IOException - Signals that an I/O exception has occurred.
    • getRequestCharset

      public static Charset getRequestCharset(HttpHeaders headers)
      Parameters:
      headers -
      Returns:
    • getResponseCharset

      public static Charset getResponseCharset(Map<String,?> headers, Charset requestCharset)
      Parameters:
      headers -
      requestCharset -
      Returns:
    • getCharset

      public static Charset getCharset(String contentType)
      Parameters:
      contentType -
      Returns:
    • getCharset

      public static Charset getCharset(String contentType, Charset defaultIfNull)
      Parameters:
      contentType -
      defaultIfNull -
      Returns:
    • turnOffCertificateValidation

      @Deprecated public static void turnOffCertificateValidation()
      Deprecated.
      For test only. Don't use it on production.