- /**
- * Block this thread from executing HTTP requests.
- * Used to guard against HTTP requests blocking the main application thread.
- *
- * @param blocked if HTTP requests run on this thread should be denied
- */
- public static void setThreadBlocked(boolean blocked) {
- sThreadBlocked.set(blocked);
- }
-
- /**
- * Modifies a request to indicate to the server that we would like a
- * gzipped response. (Uses the "Accept-Encoding" HTTP header.)
- *
- * @param request the request to modify
- * @see #getUngzippedContent
- */
- public static void modifyRequestToAcceptGzipResponse(HttpMessage request) {
- request.addHeader("Accept-Encoding", "gzip");
- }
-
- /**
- * Gets the input stream from a response entity. If the entity is gzipped
- * then this will get a stream over the uncompressed data.
- *
- * @param entity the entity whose content should be read
- * @return the input stream to read from
- * @throws IOException
- */
- public static InputStream getUngzippedContent(HttpEntity entity) throws IOException {
- InputStream responseStream = entity.getContent();
- if (responseStream == null) {
- return responseStream;
- }
- Header header = entity.getContentEncoding();
- if (header == null) {
- return responseStream;
- }
- String contentEncoding = header.getValue();
- if (contentEncoding == null) {
- return responseStream;
- }
- if (contentEncoding.contains("gzip")) {
- responseStream = new GZIPInputStream(responseStream);
- }
- return responseStream;
- }
-