Package org.jclouds.http
Class HttpUtils
- java.lang.Object
-
- org.jclouds.http.HttpUtils
-
@Singleton public class HttpUtils extends Object
-
-
Constructor Summary
Constructors Constructor Description HttpUtils(int connectionTimeout, int soTimeout, int globalMaxConnections, int globalMaxConnectionsPerHost)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Long
attemptToParseSizeAndRangeFromHeaders(HttpMessage from)
static void
checkRequestHasContentLengthOrChunkedEncoding(HttpMessage request, String message)
void
checkRequestHasRequiredProperties(HttpRequest message)
static byte[]
closeClientButKeepContentStream(PayloadEnclosing response)
Content stream may need to be read.static boolean
contains404(Throwable t)
static void
copy(ContentMetadata fromMd, MutableContentMetadata toMd)
static com.google.common.collect.Multimap<String,String>
filterOutContentHeaders(com.google.common.collect.Multimap<String,String> headers)
int
getConnectionTimeout()
int
getMaxConnections()
int
getMaxConnectionsPerHost()
int
getSocketOpenTimeout()
void
logRequest(Logger logger, HttpRequest request, String prefix)
void
logResponse(Logger logger, HttpResponse response, String prefix)
static String
nullToEmpty(byte[] md5)
static String
nullToEmpty(Collection<String> collection)
boolean
relaxHostname()
static void
releasePayload(HttpMessage from)
static <T> T
returnValueOnCodeOrNull(Throwable from, T value, com.google.common.base.Predicate<Integer> codePredicate)
static byte[]
toByteArrayOrNull(PayloadEnclosing response)
boolean
trustAllCerts()
static com.google.common.base.Optional<String>
tryFindHttpMethod(com.google.common.reflect.Invokable<?,?> method)
static void
wirePayloadIfEnabled(Wire wire, HttpMessage request)
-
-
-
Constructor Detail
-
HttpUtils
@Inject public HttpUtils(@Named("jclouds.connection-timeout") int connectionTimeout, @Named("jclouds.so-timeout") int soTimeout, @Named("jclouds.max-connections-per-context") int globalMaxConnections, @Named("jclouds.max-connections-per-host") int globalMaxConnectionsPerHost)
-
-
Method Detail
-
getSocketOpenTimeout
public int getSocketOpenTimeout()
-
getConnectionTimeout
public int getConnectionTimeout()
-
relaxHostname
public boolean relaxHostname()
-
trustAllCerts
public boolean trustAllCerts()
-
getMaxConnections
public int getMaxConnections()
-
getMaxConnectionsPerHost
public int getMaxConnectionsPerHost()
-
toByteArrayOrNull
public static byte[] toByteArrayOrNull(PayloadEnclosing response)
-
tryFindHttpMethod
public static com.google.common.base.Optional<String> tryFindHttpMethod(com.google.common.reflect.Invokable<?,?> method)
-
closeClientButKeepContentStream
public static byte[] closeClientButKeepContentStream(PayloadEnclosing response)
Content stream may need to be read. However, we should always close the http stream.- Throws:
IOException
-
copy
public static void copy(ContentMetadata fromMd, MutableContentMetadata toMd)
-
logRequest
public void logRequest(Logger logger, HttpRequest request, String prefix)
-
logResponse
public void logResponse(Logger logger, HttpResponse response, String prefix)
-
checkRequestHasRequiredProperties
public void checkRequestHasRequiredProperties(HttpRequest message)
-
releasePayload
public static void releasePayload(HttpMessage from)
-
nullToEmpty
public static String nullToEmpty(byte[] md5)
-
nullToEmpty
public static String nullToEmpty(Collection<String> collection)
-
attemptToParseSizeAndRangeFromHeaders
public static Long attemptToParseSizeAndRangeFromHeaders(HttpMessage from) throws HttpException
- Throws:
HttpException
-
checkRequestHasContentLengthOrChunkedEncoding
public static void checkRequestHasContentLengthOrChunkedEncoding(HttpMessage request, String message)
-
wirePayloadIfEnabled
public static void wirePayloadIfEnabled(Wire wire, HttpMessage request)
-
returnValueOnCodeOrNull
public static <T> T returnValueOnCodeOrNull(Throwable from, T value, com.google.common.base.Predicate<Integer> codePredicate)
-
filterOutContentHeaders
public static com.google.common.collect.Multimap<String,String> filterOutContentHeaders(com.google.common.collect.Multimap<String,String> headers)
-
contains404
public static boolean contains404(Throwable t)
-
-