Example #1
0
  @Override
  public Response execute(Request request) throws IOException {
    Response response = wrappedClient.execute(request);

    boolean gzipped = false;
    for (Header h : response.getHeaders()) {
      if (h.getName() != null
          && h.getName().toLowerCase().equals("content-encoding")
          && h.getValue() != null
          && h.getValue().toLowerCase().equals("gzip")) {
        gzipped = true;
        break;
      }
    }

    Response r = null;
    if (gzipped) {
      InputStream is = null;
      ByteArrayOutputStream bos = null;

      try {
        is = new BufferedInputStream(new GZIPInputStream(response.getBody().in()));
        bos = new ByteArrayOutputStream();

        int b;
        while ((b = is.read()) != -1) {
          bos.write(b);
        }

        TypedByteArray body = new TypedByteArray(response.getBody().mimeType(), bos.toByteArray());
        r =
            new Response(
                response.getUrl(),
                response.getStatus(),
                response.getReason(),
                response.getHeaders(),
                body);
      } finally {
        if (is != null) {
          is.close();
        }
        if (bos != null) {
          bos.close();
        }
      }
    } else {
      r = response;
    }
    return r;
  }
Example #2
0
 mq(List<Header> paramList) {
   if (paramList == null) {
     throw new IllegalArgumentException("headers must not be null");
   }
   this.Qu = System.currentTimeMillis();
   paramList = paramList.iterator();
   while (paramList.hasNext()) {
     Header localHeader = (Header) paramList.next();
     if ("x-rate-limit-limit".equals(localHeader.getName())) {
       this.limit = Integer.valueOf(localHeader.getValue()).intValue();
     } else if ("x-rate-limit-remaining".equals(localHeader.getName())) {
       this.Qv = Integer.valueOf(localHeader.getValue()).intValue();
     } else if ("x-rate-limit-reset".equals(localHeader.getName())) {
       this.Qw = Long.valueOf(localHeader.getValue()).longValue();
     }
   }
 }
 @Override
 public Response execute(Request request) throws IOException {
   List<Header> headers = request.getHeaders();
   List<retrofit.client.Header> modified = new ArrayList<Header>();
   for (int i = 0; i < headers.size(); i++) {
     retrofit.client.Header header = headers.get(i);
     if (!header.getName().equals("Content-Length")) {
       modified.add(header);
     }
   }
   return super.execute(
       new Request(request.getMethod(), request.getUrl(), modified, request.getBody()));
 }