Package google.registry.request
Class UrlConnectionUtils
java.lang.Object
google.registry.request.UrlConnectionUtils
Utilities for common functionality relating to
URLConnection
s.-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
getResponseBytes
(HttpURLConnection connection) Retrieves the response from the given connection as a byte array.static byte[]
gUnzipBytes
(byte[] bytes) Decodes compressed data in GZIP format.static boolean
isGZipped
(byte[] bytes) Checks whetherbytes
are GZIP encoded.static void
setBasicAuth
(HttpURLConnection connection, String usernameAndPassword) Sets auth on the given connection with the given string, formatted "username:password".static void
setBasicAuth
(HttpURLConnection connection, String username, String password) Sets auth on the given connection with the given username/password.static void
setPayload
(HttpURLConnection connection, byte[] bytes, String contentType) Sets the given byte[] payload on the given connection with a particular content type.static void
setPayloadMultipart
(HttpURLConnection connection, String name, String filename, com.google.common.net.MediaType contentType, String data, Random random) Sets payload on request as amultipart/form-data
request.
-
Method Details
-
getResponseBytes
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
Decodes compressed data in GZIP format.- Throws:
IOException
-
isGZipped
public static boolean isGZipped(byte[] bytes) Checks whetherbytes
are GZIP encoded. -
setBasicAuth
Sets auth on the given connection with the given username/password. -
setBasicAuth
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 amultipart/form-data
request.This is equivalent to running the command:
curl -F fieldName=@payload.txt URL
- Throws:
IOException
- See Also:
-