Class UrlConnectionUtils

java.lang.Object
google.registry.request.UrlConnectionUtils

public final class UrlConnectionUtils extends Object
Utilities for common functionality relating to URLConnections.
  • Method Details

    • getResponseBytes

      public static byte[] getResponseBytes(HttpURLConnection connection) throws IOException
      Retrieves the response from the given connection as a byte array.

      Note that in the event the response code is 4XX or 5XX, we use the error stream as any payload is included there.

      Throws:
      IOException
      See Also:
    • gUnzipBytes

      public static byte[] gUnzipBytes(byte[] bytes) throws IOException
      Decodes compressed data in GZIP format.
      Throws:
      IOException
    • isGZipped

      public static boolean isGZipped(byte[] bytes)
      Checks whether bytes are GZIP encoded.
    • setBasicAuth

      public static void setBasicAuth(HttpURLConnection connection, String username, String password)
      Sets auth on the given connection with the given username/password.
    • setBasicAuth

      public static void setBasicAuth(HttpURLConnection connection, String usernameAndPassword)
      Sets auth on the given connection with the given string, formatted "username:password".
    • setPayload

      public static void setPayload(HttpURLConnection connection, byte[] bytes, String contentType) throws IOException
      Sets the given byte[] payload on the given connection with a particular content type.
      Throws:
      IOException
    • setPayloadMultipart

      public static void setPayloadMultipart(HttpURLConnection connection, String name, String filename, com.google.common.net.MediaType contentType, String data, Random random) throws IOException
      Sets payload on request as a multipart/form-data request.

      This is equivalent to running the command: curl -F fieldName=@payload.txt URL

      Throws:
      IOException
      See Also: