com.crashlytics.tools.android_2.1.0

questMinorVersionIsTooHighMajorVersionsMatch(request))) {
      request.setProtocolVersion(HttpVersion.HTTP_1_1);
    }
  }
  
  private void stripOtherFreshnessDirectivesWithNoCache(HttpRequest request)
  {
    List<HeaderElement> outElts = new ArrayList();
    boolean shouldStrip = false;
    for (Header h : request.getHeaders("Cache-Control")) {
      for (HeaderElement elt : h.getElements())
      {
        if (!disallowedWithNoCache.contains(elt.getName())) {
          outElts.add(elt);
        }
        if ("no-cache".equals(elt.getName())) {
          shouldStrip = true;
        }
      }
    }
    if (!shouldStrip) {
      return;
    }
    request.removeHeaders("Cache-Control");
    request.setHeader("Cache-Control", buildHeaderFromElements(outElts));
  }
  
  private String buildHeaderFromElements(List<HeaderElement> outElts)
  {
    StringBuilder newHdr = new StringBuilder("");
    boolean first = true;
    for (HeaderElement elt : outElts)
    {
      if (!first) {
        newHdr.append(",");
      } else {
        first = false;
      }
      newHdr.append(elt.toString());
    }
    return newHdr.toString();
  }
  
  private boolean requestMustNotHaveEntity(HttpRequest request)
  {
    return ("TRACE".equals(request.getRequestLine().getMethod())) && ((request instanceof HttpEntityEnclosingRequest));
  }
  
  private void decrementOPTIONSMaxForwardsIfGreaterThen0(HttpRequest request)
  {
    if (!"OPTIONS".equals(request.getRequestLine().getMethod())) {
      return;
    }
    Header maxForwards = request.getFirstHeader("Max-Forwards");
    if (maxForwards == null) {
      return;
    }
    request.removeHeaders("Max-Forwards");
    int currentMaxForwards = Integer.parseInt(maxForwards.getValue());
    
    request.setHeader("Max-Forwards", Integer.toString(currentMaxForwards - 1));
  }
  
  private void verifyOPTIONSRequestWithBodyHasContentType(HttpRequest request)
  {
    if (!"OPTIONS".equals(request.getRequestLine().getMethod())) {
      return;
    }
    if (!(request instanceof HttpEntityEnclosingRequest)) {
      return;
    }
    addContentTypeHeaderIfMissing((HttpEntityEnclosingRequest)request);
  }
  
  private void addContentTypeHeaderIfMissing(HttpEntityEnclosingRequest request)
  {
    if (request.getEntity().getContentType() == null) {
      ((AbstractHttpEntity)request.getEntity()).setContentType(ContentType.APPLICATION_OCTET_STREAM.getMimeType());
    }
  }
  
  private void verifyRequestWithExpectContinueFlagHas100continueHeader(HttpRequest request)
  {
    if ((request instanceof HttpEntityEnclosingRequest))
    {
      if ((((HttpEntityEnclosingRequest)request).expectContinue()) && (((HttpEntityEnclosingRequest)request).getEntity() != null)) {
        add100ContinueHeaderIfMissing(request);
      } else {
        remove100ContinueHeaderIfExists(request);
      }
    }
    else {
      remove100ContinueHeaderIfExists(request);
    }
  }
  
  private void remove100ContinueHeaderIfExists(HttpRequest request)
  {
    boolean hasHeader = false;
    
    Header[] expectHeaders = request.getHeaders("Expect");
    List<HeaderElement> expectElementsThatAreNot100Continue = new ArrayList();
    for (Header h : expectHeaders)
    {
      for (HeaderElement elt : h.getElements()) {
        if (!"100-continue".equalsIgnoreCase(elt.getName())) {
          expectElementsThatAreNot100Continue.add(elt);
        } else {
          hasHeader = true;
        }
      }
      if (hasHeader)
      {
        request.removeHeader(h);
        for (HeaderElement elt : expectElementsThatAreNot100Continue)
        {
          BasicHeader newHeader = new BasicHeader("Expect", elt.getName());
          request.addHeader(newHeader);
        }
        return;
      }
      expectElementsThatAreNot100Continue = new ArrayList();
    }
  }
  
  private void add100ContinueHeaderIfMissing(HttpRequest request)
  {
    boolean hasHeader = false;
    for (Header h : request.getHeaders("Expect")) {
      for (HeaderElement elt : h.getElements()) {
        if ("100-continue".equalsIgnoreCase(elt.getName())) {
          hasHeader = true;
        }
      }
    }
    if (!hasHeader) {
      request.addHeader("Expect", "100-continue");
    }
  }
  
  protected boolean requestMinorVersionIsTooHighMajorVersionsMatch(HttpRequest request)
  {
    ProtocolVersion requestProtocol = request.getProtocolVersion();
    if (requestProtocol.getMajor() != HttpVersion.HTTP_1_1.getMajor()) {
      return false;
    }
    if (requestProtocol.getMinor() > HttpVersion.HTTP_1_1.getMinor()) {
      return true;
    }
    return false;
  }
  
  protected boolean requestVersionIsTooLow(HttpRequest request)
  {
    return request.getProtocolVersion().compareToVersion(HttpVersion.HTTP_1_1) < 0;
  }
  
  public HttpResponse getErrorForRequest(RequestProtocolError errorCheck)
  {
    switch (errorCheck)
    {
    case BODY_BUT_NO_LENGTH_ERROR: 
      return new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, 411, ""));
    case WEAK_ETAG_AND_RANGE_ERROR: 
      return new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, 400, "Weak eTag not compatible with byte range"));
    case WEAK_ETAG_ON_PUTDELETE_METHOD_ERROR: 
      return new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, 400, "Weak eTag not compatible with PUT or DELETE requests"));
    case NO_CACHE_DIRECTIVE_WITH_FIELD_NAME: 
      return new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, 400, "No-Cache directive MUST NOT include a field name"));
    }
    throw new IllegalStateException("The request was compliant, therefore no error can be generated for it.");
  }
  
  private RequestProtocolError requestHasWeakETagAndRange(HttpRequest request)
  {
    String method = request.getRequestLine().getMethod();
    if (!"GET".equals(method)) {
      return null;
    }
    Header range = request.getFirstHeader("Range");
    if (range == null) {
      return null;
    }
    Header ifRange = request.getFirstHeader("If-Range");
    if (ifRange == null) {
      return null;
    }
    String val = ifRange.getValue();
    if (val.startsWith("W/")) {
      return RequestProtocolError.WEAK_ETAG_AND_RANGE_ERROR;
    }
    return null;
  }
  
  private RequestProtocolError requestHasWeekETagForPUTOrDELETEIfMatch(HttpRequest request)
  {
    String method = request.getRequestLine().getMethod();
    if ((!"PUT".equals(method)) && (!"DELETE".equals(method))) {
      return null;
    }
    Header ifMatch = request.getFirstHeader("If-Match");
    if (ifMatch != null)
    {
      String val = ifMatch.getValue();
      if (val.startsWith("W/")) {
        return RequestProtocolError.WEAK_ETAG_ON_PUTDELETE_METHOD_ERROR;
      }
    }
    else
    {
      Header ifNoneMatch = request.getFirstHeader("If-None-Match");
      if (ifNoneMatch == null) {
        return null;
      }
      String val2 = ifNoneMatch.getValue();
      if (val2.startsWith("W/")) {
        return RequestProtocolError.WEAK_ETAG_ON_PUTDELETE_METHOD_ERROR;
      }
    }
    return null;
  }
  
  private RequestProtocolError requestContainsNoCacheDirectiveWithFieldName(HttpRequest request)
  {
    for (Header h : request.getHeaders("Cache-Control")) {
      for (HeaderElement elt : h.getElements()) {
        if (("no-cache".equalsIgnoreCase(elt.getName())) && (elt.getValue() != null)) {
          return RequestProtocolError.NO_CACHE_DIRECTIVE_WITH_FIELD_NAME;
        }
      }
    }
    return null;
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.client.cache.RequestProtocolCompliance
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.client.cache;

 enum RequestProtocolError
{
  UNKNOWN,  BODY_BUT_NO_LENGTH_ERROR,  WEAK_ETAG_ON_PUTDELETE_METHOD_ERROR,  WEAK_ETAG_AND_RANGE_ERROR,  NO_CACHE_DIRECTIVE_WITH_FIELD_NAME;
  
  private RequestProtocolError() {}
}

/* Location:
 * Qualified Name:     org.apache.http.impl.client.cache.RequestProtocolError
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.client.cache;

import java.lang.ref.PhantomReference;
import java.lang.ref.ReferenceQueue;
import org.apache.http.annotation.Immutable;
import org.apache.http.client.cache.HttpCacheEntry;
import org.apache.http.client.cache.Resource;
import org.apache.http.util.Args;

@Immutable
class ResourceReference
  extends PhantomReference<HttpCacheEntry>
{
  private final Resource resource;
  
  public ResourceReference(HttpCacheEntry entry, ReferenceQueue<HttpCacheEntry> q)
  {
    super(entry, q);
    Args.notNull(entry.getResource(), "Resource");
    resource = entry.getResource();
  }
  
  public Resource getResource()
  {
    return resource;
  }
  
  public int hashCode()
  {
    return resource.hashCode();
  }
  
  public boolean equals(Object obj)
  {
    return resource.equals(obj);
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.client.cache.ResourceReference
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.client.cache;

import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.Header;
import org.apache.http.HeaderElement;
import org.apache.http.HttpMessage;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.HttpVersion;
import org.apache.http.ProtocolVersion;
import org.apache.http.RequestLine;
import org.apache.http.StatusLine;
import org.apache.http.annotation.Immutable;
import org.apache.http.client.utils.DateUtils;

@Immutable
class ResponseCachingPolicy
{
  private static final String[] AUTH_CACHEABLE_PARAMS = { "s-maxage", "must-revalidate", "public" };
  private final long maxObjectSizeBytes;
  private final boolean sharedCache;
  private final boolean neverCache1_0ResponsesWithQueryString;
  private final Log log = LogFactory.getLog(getClass());
  private static final Set<Integer> cacheableStatuses = new HashSet(Arrays.asList(new Integer[] { Integer.valueOf(200), Integer.valueOf(203), Integer.valueOf(300), Integer.valueOf(301), Integer.valueOf(410) }));
  private final Set<Integer> uncacheableStatuses;
  
  public ResponseCachingPolicy(long maxObjectSizeBytes, boolean sharedCache, boolean neverCache1_0ResponsesWithQueryString, boolean allow303Caching)
  {
    this.maxObjectSizeBytes = maxObjectSizeBytes;
    this.sharedCache = sharedCache;
    this.neverCache1_0ResponsesWithQueryString = neverCache1_0ResponsesWithQueryString;
    if (allow303Caching) {
      uncacheableStatuses = new HashSet(Arrays.asList(new Integer[] { Integer.valueOf(206) }));
    } else {
      uncacheableStatuses = new HashSet(Arrays.asList(new Integer[] { Integer.valueOf(206), Integer.valueOf(303) }));
    }
  }
  
  public boolean isResponseCacheable(String httpMethod, HttpResponse response)
  {
    boolean cacheable = false;
    if (!"GET".equals(httpMethod))
    {
      log.debug("Response was not cacheable.");
      return false;
    }
    int status = response.getStatusLine().getStatusCode();
    if (cacheableStatuses.contains(Integer.valueOf(status)))
    {
      cacheable = true;
    }
    else
    {
      if (uncacheableStatuses.contains(Integer.valueOf(status))) {
        return false;
      }
      if (unknownStatusCode(status)) {
        return false;
      }
    }
    Header contentLength = response.getFirstHeader("Content-Length");
    if (contentLength != null)
    {
      int contentLengthValue = Integer.parseInt(contentLength.getValue());
      if (contentLengthValue > maxObjectSizeBytes) {
        return false;
      }
    }
    Header[] ageHeaders = response.getHeaders("Age");
    if (ageHeaders.length > 1) {
      return false;
    }
    Header[] expiresHeaders = response.getHeaders("Expires");
    if (expiresHeaders.length > 1) {
      return false;
    }
    Header[] dateHeaders = response.getHeaders("Date");
    if (dateHeaders.length != 1) {
      return false;
    }
    Date date = DateUtils.parseDate(dateHeaders[0].getValue());
    if (date == null) {
      return false;
    }
    for (Header varyHdr : response.getHeaders("Vary")) {
      for (HeaderElement elem : varyHdr.getElements()) {
        if ("*".equals(elem.getName())) {
          return false;
        }
      }
    }
    if (isExplicitlyNonCacheable(response)) {
      return false;
    }
    return (cacheable) || (isExplicitlyCacheable(response));
  }
  
  private boolean unknownStatusCode(int status)
  {
    if ((status >= 100) && (status <= 101)) {
      return false;
    }
    if ((status >= 200) && (status <= 206)) {
      return false;
    }
    if ((status >= 300) && (status <= 307)) {
      return false;
    }
    if ((status >= 400) && (status <= 417)) {
      return false;
    }
    if ((status >= 500) && (status <= 505)) {
      return false;
    }
    return true;
  }
  
  protected boolean isExplicitlyNonCacheable(HttpResponse response)
  {
    Header[] cacheControlHeaders = response.getHeaders("Cache-Control");
    for (Header header : cacheControlHeaders) {
      for (HeaderElement elem : header.getElements()) {
        if (("no-store".equals(elem.getName())) || ("no-cache".equals(elem.getName())) || ((sharedCache) && ("private".equals(elem.getName())))) {
          return true;
        }
      }
    }
    return false;
  }
  
  protected boolean hasCacheControlParameterFrom(HttpMessage msg, String[] params)
  {
    Header[] cacheControlHeaders = msg.getHeaders("Cache-Control");
    for (Header header : cacheControlHeaders) {
      for (HeaderElement elem : header.getElements()) {
        for (String param : params) {
          if (param.equalsIgnoreCase(elem.getName())) {
            return true;
          }
        }
      }
    }
    return false;
  }
  
  protected boolean isExplicitlyCacheable(HttpResponse response)
  {
    if (response.getFirstHeader("Expires") != null) {
      return true;
    }
    String[] cacheableParams = { "max-age", "s-maxage", "must-revalidate", "proxy-revalidate", "public" };
    
    return hasCacheControlParameterFrom(response, cacheableParams);
  }
  
  public boolean isResponseCacheable(HttpRequest request, HttpResponse response)
  {
    if (requestProtocolGreaterThanAccepted(request))
    {
      log.debug("Response was not cacheable.");
      return false;
    }
    String[] uncacheableRequestDirectives = { "no-store" };
    if (hasCacheControlParameterFrom(request, uncacheableRequestDirectives)) {
      return false;
    }
    if (request.getRequestLine().getUri().contains("?"))
    {
      if ((neverCache1_0ResponsesWithQueryString) && (from1_0Origin(response)))
      {
        log.debug("Response was not cacheable as it had a query string.");
        return false;
      }
      if (!isExplicitlyCacheable(response))
      {
        log.debug("Response was not cacheable as it is missing explicit caching headers.");
        return false;
      }
    }
    if (expiresHeaderLessOrEqualToDateHeaderAndNoCacheControl(response)) {
      return false;
    }
    if (sharedCache)
    {
      Header[] authNHeaders = request.getHeaders("Authorization");
      if ((authNHeaders != null) && (authNHeaders.length > 0) && (!hasCacheControlParameterFrom(response, AUTH_CACHEABLE_PARAMS))) {
        return false;
      }
    }
    String method = request.getRequestLine().getMethod();
    return isResponseCacheable(method, response);
  }
  
  private boolean expiresHeaderLessOrEqualToDateHeaderAndNoCacheControl(HttpResponse response)
  {
    if (response.getFirstHeader("Cache-Control") != null) {
      return false;
    }
    Header expiresHdr = response.getFirstHeader("Expires");
    Header dateHdr = response.getFirstHeader("Date");
    if ((expiresHdr == null) || (dateHdr == null)) {
      return false;
    }
    Date expires = DateUtils.parseDate(expiresHdr.getValue());
    Date date = DateUtils.parseDate(dateHdr.getValue());
    if ((expires == null) || (date == null)) {
      return false;
    }
    return (expires.equals(date)) || (expires.before(date));
  }
  
  private boolean from1_0Origin(HttpResponse response)
  {
    Header via = response.getFirstHeader("Via");
    if (via != null)
    {
      HeaderElement[] arr$ = via.getElements();int len$ = arr$.length;int i$ = 0;
      if (i$ < len$)
      {
        HeaderElement elt = arr$[i$];
        String proto = elt.toString().split("\\s")[0];
        if (proto.contains("/")) {
          return proto.equals("HTTP/1.0");
        }
        return proto.equals("1.0");
      }
    }
    return HttpVersion.HTTP_1_0.equals(response.getProtocolVersion());
  }
  
  private boolean requestProtocolGreaterThanAccepted(HttpRequest req)
  {
    return req.getProtocolVersion().compareToVersion(HttpVersion.HTTP_1_1) > 0;
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.client.cache.ResponseCachingPolicy
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.client.cache;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.apache.http.Header;
import org.apache.http.HeaderElement;
import org.apache.http.HttpEntity;
import org.apache.http.HttpEntityEnclosingRequest;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.HttpVersion;
import org.apache.http.ProtocolVersion;
import org.apache.http.RequestLine;
import org.apache.http.StatusLine;
import org.apache.http.annotation.Immutable;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpRequestWrapper;
import org.apache.http.client.utils.DateUtils;
import org.apache.http.message.BasicHeader;
import org.apache.http.util.EntityUtils;

@Immutable
class ResponseProtocolCompliance
{
  private static final String UNEXPECTED_100_CONTINUE = "The incoming request did not contain a 100-continue header, but the response was a Status 100, continue.";
  private static final String UNEXPECTED_PARTIAL_CONTENT = "partial content was returned for a request that did not ask for it";
  
  public void ensureProtocolCompliance(HttpRequestWrapper request, HttpResponse response)
    throws IOException
  {
    if (backendResponseMustNotHaveBody(request, response))
    {
      consumeBody(response);
      response.setEntity(null);
    }
    requestDidNotExpect100ContinueButResponseIsOne(request, response);
    
    transferEncodingIsNotReturnedTo1_0Client(request, response);
    
    ensurePartialContentIsNotSentToAClientThatDidNotRequestIt(request, response);
    
    ensure200ForOPTIONSRequestWithNoBodyHasContentLengthZero(request, response);
    
    ensure206ContainsDateHeader(response);
    
    ensure304DoesNotContainExtraEntityHeaders(response);
    
    identityIsNotUsedInContentEncoding(response);
    
    warningsWithNonMatchingWarnDatesAreRemoved(response);
  }
  
  private void consumeBody(HttpResponse response)
    throws IOException
  {
    HttpEntity body = response.getEntity();
    if (body != null) {
      EntityUtils.consume(body);
    }
  }
  
  private void warningsWithNonMatchingWarnDatesAreRemoved(HttpResponse response)
  {
    Date responseDate = DateUtils.parseDate(response.getFirstHeader("Date").getValue());
    if (responseDate == null) {
      return;
    }
    Header[] warningHeaders = response.getHeaders("Warning");
    if ((warningHeaders == null) || (warningHeaders.length == 0)) {
      return;
    }
    List<Header> newWarningHeaders = new ArrayList();
    boolean modified = false;
    for (Header h : warningHeaders) {
      for (WarningValue wv : WarningValue.getWarningValues(h))
      {
        Date warnDate = wv.getWarnDate();
        if ((warnDate == null) || (warnDate.equals(responseDate))) {
          newWarningHeaders.add(new BasicHeader("Warning", wv.toString()));
        } else {
          modified = true;
        }
      }
    }
    if (modified)
    {
      response.removeHeaders("Warning");
      for (Header h : newWarningHeaders) {
        response.addHeader(h);
      }
    }
  }
  
  private void identityIsNotUsedInContentEncoding(HttpResponse response)
  {
    Header[] hdrs = response.getHeaders("Content-Encoding");
    if ((hdrs == null) || (hdrs.length == 0)) {
      return;
    }
    List<Header> newHeaders = new ArrayList();
    boolean modified = false;
    for (Header h : hdrs)
    {
      StringBuilder buf = new StringBuilder();
      boolean first = true;
      for (HeaderElement elt : h.getElements()) {
        if ("identity".equalsIgnoreCase(elt.getName()))
        {
          modified = true;
        }
        else
        {
          if (!first) {
            buf.append(",");
          }
          buf.append(elt.toString());
          first = false;
        }
      }
      String newHeaderValue = buf.toString();
      if (!"".equals(newHeaderValue)) {
        newHeaders.add(new BasicHeader("Content-Encoding", newHeaderValue));
      }
    }
    if (!modified) {
      return;
    }
    response.removeHeaders("Content-Encoding");
    for (Header h : newHeaders) {
      response.addHeader(h);
    }
  }
  
  private void ensure206ContainsDateHeader(HttpResponse response)
  {
    if (response.getFirstHeader("Date") == null) {
      response.addHeader("Date", DateUtils.formatDate(new Date()));
    }
  }
  
  private void ensurePartialContentIsNotSentToAClientThatDidNotRequestIt(HttpRequest request, HttpResponse response)
    throws IOException
  {
    if ((request.getFirstHeader("Range") != null) || (response.getStatusLine().getStatusCode() != 206)) {
      return;
    }
    consumeBody(response);
    throw new ClientProtocolException("partial content was returned for a request that did not ask for it");
  }
  
  private void ensure200ForOPTIONSRequestWithNoBodyHasContentLengthZero(HttpRequest request, HttpResponse response)
  {
    if (!request.getRequestLine().getMethod().equalsIgnoreCase("OPTIONS")) {
      return;
    }
    if (response.getStatusLine().getStatusCode() != 200) {
      return;
    }
    if (response.getFirstHeader("Content-Length") == null) {
      response.addHeader("Content-Length", "0");
    }
  }
  
  private void ensure304DoesNotContainExtraEntityHeaders(HttpResponse response)
  {
    String[] disallowedEntityHeaders = { "Allow", "Content-Encoding", "Content-Language", "Content-Length", "Content-MD5", "Content-Range", "Content-Type", "Last-Modified" };
    if (response.getStatusLine().getStatusCode() == 304) {
      for (String hdr : disallowedEntityHeaders) {
        response.removeHeaders(hdr);
      }
    }
  }
  
  private boolean backendResponseMustNotHaveBody(HttpRequest request, HttpResponse backendResponse)
  {
    return ("HEAD".equals(request.getRequestLine().getMethod())) || (backendResponse.getStatusLine().getStatusCode() == 204) || (backendResponse.getStatusLine().getStatusCode() == 205) || (backendResponse.getStatusLine().getStatusCode() == 304);
  }
  
  private void requestDidNotExpect100ContinueButResponseIsOne(HttpRequestWrapper request, HttpResponse response)
    throws IOException
  {
    if (response.getStatusLine().getStatusCode() != 100) {
      return;
    }
    HttpRequest originalRequest = request.getOriginal();
    if (((originalRequest instanceof HttpEntityEnclosingRequest)) && 
      (((HttpEntityEnclosingRequest)originalRequest).expectContinue())) {
      return;
    }
    consumeBody(response);
    throw new ClientProtocolException("The incoming request did not contain a 100-continue header, but the response was a Status 100, continue.");
  }
  
  private void transferEncodingIsNotReturnedTo1_0Client(HttpRequestWrapper request, HttpResponse response)
  {
    HttpRequest originalRequest = request.getOriginal();
    if (originalRequest.getProtocolVersion().compareToVersion(HttpVersion.HTTP_1_1) >= 0) {
      return;
    }
    removeResponseTransferEncoding(response);
  }
  
  private void removeResponseTransferEncoding(HttpResponse response)
  {
    response.removeHeaders("TE");
    response.removeHeaders("Transfer-Encoding");
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.client.cache.ResponseProtocolCompliance
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.client.cache;

import java.io.Closeable;
import java.io.IOException;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.apache.http.HttpResponse;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.util.EntityUtils;

@NotThreadSafe
class ResponseProxyHandler
  implements InvocationHandler
{
  private static final Method CLOSE_METHOD;
  private final HttpResponse original;
  
  static
  {
    try
    {
      CLOSE_METHOD = Closeable.class.getMethod("close", new Class[0]);
    }
    catch (NoSuchMethodException ex)
    {
      throw new Error(ex);
    }
  }
  
  ResponseProxyHandler(HttpResponse original)
  {
    this.original = original;
  }
  
  public void close()
    throws IOException
  {
    EntityUtils.consume(original.getEntity());
  }
  
  public Object invoke(Object proxy, Method method, Object[] args)
    throws Throwable
  {
    if (method.equals(CLOSE_METHOD))
    {
      close();
      return null;
    }
    try
    {
      return method.invoke(original, args);
    }
    catch (InvocationTargetException ex)
    {
      Throwable cause = ex.getCause();
      if (cause != null) {
        throw cause;
      }
      throw ex;
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.client.cache.ResponseProxyHandler
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.client.cache;

import java.io.Closeable;

public abstract interface SchedulingStrategy
  extends Closeable
{
  public abstract void schedule(AsynchronousValidationRequest paramAsynchronousValidationRequest);
}

/* Location:
 * Qualified Name:     org.apache.http.impl.client.cache.SchedulingStrategy
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.client.cache;

import java.io.IOException;
import java.io.InputStream;
import org.apache.http.HttpEntity;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
import org.apache.http.RequestLine;
import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.client.cache.InputLimit;
import org.apache.http.client.cache.Resource;
import org.apache.http.client.cache.ResourceFactory;
import org.apache.http.message.BasicHttpResponse;

@NotThreadSafe
class SizeLimitedResponseReader
{
  private final ResourceFactory resourceFactory;
  private final long maxResponseSizeBytes;
  private final HttpRequest request;
  private final HttpResponse response;
  private InputStream instream;
  private InputLimit limit;
  private Resource resource;
  private boolean consumed;
  
  public SizeLimitedResponseReader(ResourceFactory resourceFactory, long maxResponseSizeBytes, HttpRequest request, HttpResponse response)
  {
    this.resourceFactory = resourceFactory;
    this.maxResponseSizeBytes = maxResponseSizeBytes;
    this.request = request;
    this.response = response;
  }
  
  protected void readResponse()
    throws IOException
  {
    if (!consumed) {
      doConsume();
    }
  }
  
  private void ensureNotConsumed()
  {
    if (consumed) {
      throw new IllegalStateException("Response has already been consumed");
    }
  }
  
  private void ensureConsumed()
  {
    if (!consumed) {
      throw new IllegalStateException("Response has not been consumed");
    }
  }
  
  private void doConsume()
    throws IOException
  {
    ensureNotConsumed();
    consumed = true;
    
    limit = new InputLimit(maxResponseSizeBytes);
    
    HttpEntity entity = response.getEntity();
    if (entity == null) {
      return;
    }
    String uri = request.getRequestLine().getUri();
    instream = entity.getContent();
    try
    {
      resource = resourceFactory.generate(uri, instream, limit);
    }
    finally
    {
      if (!limit.isReached()) {
        instream.close();
      }
    }
  }
  
  boolean isLimitReached()
  {
    ensureConsumed();
    return limit.isReached();
  }
  
  Resource getResource()
  {
    ensureConsumed();
    return resource;
  }
  
  HttpResponse getReconstructedResponse()
    throws IOException
  {
    ensureConsumed();
    HttpResponse reconstructed = new BasicHttpResponse(response.getStatusLine());
    reconstructed.setHeaders(response.getAllHeaders());
    
    CombinedEntity combinedEntity = new CombinedEntity(resource, instream);
    HttpEntity entity = response.getEntity();
    if (entity != null)
    {
      combinedEntity.setContentType(entity.getContentType());
      combinedEntity.setContentEncoding(entity.getContentEncoding());
      combinedEntity.setChunked(entity.isChunked());
    }
    reconstructed.setEntity(combinedEntity);
    return reconstructed;
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.client.cache.SizeLimitedResponseReader
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.client.cache;

import org.apache.http.client.cache.HttpCacheEntry;

class Variant
{
  private final String variantKey;
  private final String cacheKey;
  private final HttpCacheEntry entry;
  
  public Variant(String variantKey, String cacheKey, HttpCacheEntry entry)
  {
    this.variantKey = variantKey;
    this.cacheKey = cacheKey;
    this.entry = entry;
  }
  
  public String getVariantKey()
  {
    return variantKey;
  }
  
  public String getCacheKey()
  {
    return cacheKey;
  }
  
  public HttpCacheEntry getEntry()
  {
    return entry;
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.client.cache.Variant
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.client.cache;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.http.Header;
import org.apache.http.client.utils.DateUtils;

class WarningValue
{
  private int offs;
  private int init_offs;
  private final String src;
  private int warnCode;
  private String warnAgent;
  private String warnText;
  private Date warnDate;
  private static final String TOPLABEL = "\\p{Alpha}([\\p{Alnum}-]*\\p{Alnum})?";
  private static final String DOMAINLABEL = "\\p{Alnum}([\\p{Alnum}-]*\\p{Alnum})?";
  private static final String HOSTNAME = "(\\p{Alnum}([\\p{Alnum}-]*\\p{Alnum})?\\.)*\\p{Alpha}([\\p{Alnum}-]*\\p{Alnum})?\\.?";
  private static final String IPV4ADDRESS = "\\d+\\.\\d+\\.\\d+\\.\\d+";
  private static final String HOST = "((\\p{Alnum}([\\p{Alnum}-]*\\p{Alnum})?\\.)*\\p{Alpha}([\\p{Alnum}-]*\\p{Alnum})?\\.?)|(\\d+\\.\\d+\\.\\d+\\.\\d+)";
  private static final String PORT = "\\d*";
  private static final String HOSTPORT = "(((\\p{Alnum}([\\p{Alnum}-]*\\p{Alnum})?\\.)*\\p{Alpha}([\\p{Alnum}-]*\\p{Alnum})?\\.?)|(\\d+\\.\\d+\\.\\d+\\.\\d+))(\\:\\d*)?";
  
  WarningValue(String s)
  {
    this(s, 0);
  }
  
  WarningValue(String s, int offs)
  {
    this.offs = (init_offs = offs);
    src = s;
    consumeWarnValue();
  }
  
  public static WarningValue[] getWarningValues(Header h)
  {
    List<WarningValue> out = new ArrayList();
    String src = h.getValue();
    int offs = 0;
    for (;;)
    {
      if (offs < src.length()) {
        try
        {
          WarningValue wv = new WarningValue(src, offs);
          out.add(wv);
          offs = offs;
        }
        catch (IllegalArgumentException e)
        {
          int nextComma = src.indexOf(',', offs);
          if (nextComma != -1) {
            offs = nextComma + 1;
          }
        }
      }
    }
    WarningValue[] wvs = new WarningValue[0];
    return (WarningValue[])out.toArray(wvs);
  }
  
  protected void consumeLinearWhitespace()
  {
    while (offs < src.length())
    {
      switch (src.charAt(offs))
      {
      case '\r': 
        if ((offs + 2 >= src.length()) || (src.charAt(offs + 1) != '\n') || ((src.charAt(offs + 2) != ' ') && (src.charAt(offs + 2) != '\t'))) {
          return;
        }
        offs += 2;
        break;
      case '\t': 
      case ' ': 
        break;
      default: 
        return;
      }
      offs += 1;
    }
  }
  
  private boolean isChar(char c)
  {
    int i = c;
    return (i >= 0) && (i <= 127);
  }
  
  private boolean isControl(char c)
  {
    int i = c;
    return (i == 127) || ((i >= 0) && (i <= 31));
  }
  
  private boolean isSeparator(char c)
  {
    return (c == '(') || (c == ')') || (c == '<') || (c == '>') || (c == '@') || (c == ',') || (c == ';') || (c == ':') || (c == '\\') || (c == '"') || (c == '/') || (c == '[') || (c == ']') || (c == '?') || (c == '=') || (c == '{') || (c == '}') || (c == ' ') || (c == '\t');
  }
  
  protected void consumeToken()
  {
    if (!isTokenChar(src.charAt(offs))) {
      parseError();
    }
    while ((offs < src.length()) && 
      (isTokenChar(src.charAt(offs)))) {
      offs += 1;
    }
  }
  
  private boolean isTokenChar(char c)
  {
    return (isChar(c)) && (!isControl(c)) && (!isSeparator(c));
  }
  
  private static final Pattern HOSTPORT_PATTERN = Pattern.compile("(((\\p{Alnum}([\\p{Alnum}-]*\\p{Alnum})?\\.)*\\p{Alpha}([\\p{Alnum}-]*\\p{Alnum})?\\.?)|(\\d+\\.\\d+\\.\\d+\\.\\d+))(\\:\\d*)?");
  private static final String MONTH = "Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec";
  private static final String WEEKDAY = "Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday";
  private static final String WKDAY = "Mon|Tue|Wed|Thu|Fri|Sat|Sun";
  private static final String TIME = "\\d{2}:\\d{2}:\\d{2}";
  private static final String DATE3 = "(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ( |\\d)\\d";
  private static final String DATE2 = "\\d{2}-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-\\d{2}";
  private static final String DATE1 = "\\d{2} (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \\d{4}";
  private static final String ASCTIME_DATE = "(Mon|Tue|Wed|Thu|Fri|Sat|Sun) ((Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ( |\\d)\\d) (\\d{2}:\\d{2}:\\d{2}) \\d{4}";
  private static final String RFC850_DATE = "(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), (\\d{2}-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-\\d{2}) (\\d{2}:\\d{2}:\\d{2}) GMT";
  private static final String RFC1123_DATE = "(Mon|Tue|Wed|Thu|Fri|Sat|Sun), (\\d{2} (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \\d{4}) (\\d{2}:\\d{2}:\\d{2}) GMT";
  private static final String HTTP_DATE = "((Mon|Tue|Wed|Thu|Fri|Sat|Sun), (\\d{2} (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \\d{4}) (\\d{2}:\\d{2}:\\d{2}) GMT)|((Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), (\\d{2}-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-\\d{2}) (\\d{2}:\\d{2}:\\d{2}) GMT)|((Mon|Tue|Wed|Thu|Fri|Sat|Sun) ((Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ( |\\d)\\d) (\\d{2}:\\d{2}:\\d{2}) \\d{4})";
  private static final String WARN_DATE = "\"(((Mon|Tue|Wed|Thu|Fri|Sat|Sun), (\\d{2} (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \\d{4}) (\\d{2}:\\d{2}:\\d{2}) GMT)|((Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), (\\d{2}-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-\\d{2}) (\\d{2}:\\d{2}:\\d{2}) GMT)|((Mon|Tue|Wed|Thu|Fri|Sat|Sun) ((Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ( |\\d)\\d) (\\d{2}:\\d{2}:\\d{2}) \\d{4}))\"";
  
  protected void consumeHostPort()
  {
    Matcher m = HOSTPORT_PATTERN.matcher(src.substring(offs));
    if (!m.find()) {
      parseError();
    }
    if (m.start() != 0) {
      parseError();
    }
    offs += m.end();
  }
  
  protected void consumeWarnAgent()
  {
    int curr_offs = offs;
    try
    {
      consumeHostPort();
      warnAgent = src.substring(curr_offs, offs);
      consumeCharacter(' ');
      return;
    }
    catch (IllegalArgumentException e)
    {
      offs = curr_offs;
      
      consumeToken();
      warnAgent = src.substring(curr_offs, offs);
      consumeCharacter(' ');
    }
  }
  
  protected void consumeQuotedString()
  {
    if (src.charAt(offs) != '"') {
      parseError();
    }
    offs += 1;
    boolean foundEnd = false;
    while ((offs < src.length()) && (!foundEnd))
    {
      char c = src.charAt(offs);
      if ((offs + 1 < src.length()) && (c == '\\') && (isChar(src.charAt(offs + 1))))
      {
        offs += 2;
      }
      else if (c == '"')
      {
        foundEnd = true;
        offs += 1;
      }
      else if ((c != '"') && (!isControl(c)))
      {
        offs += 1;
      }
      else
      {
        parseError();
      }
    }
    if (!foundEnd) {
      parseError();
    }
  }
  
  protected void consumeWarnText()
  {
    int curr = offs;
    consumeQuotedString();
    warnText = src.substring(curr, offs);
  }
  
  private static final Pattern WARN_DATE_PATTERN = Pattern.compile("\"(((Mon|Tue|Wed|Thu|Fri|Sat|Sun), (\\d{2} (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \\d{4}) (\\d{2}:\\d{2}:\\d{2}) GMT)|((Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), (\\d{2}-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-\\d{2}) (\\d{2}:\\d{2}:\\d{2}) GMT)|((Mon|Tue|Wed|Thu|Fri|Sat|Sun) ((Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ( |\\d)\\d) (\\d{2}:\\d{2}:\\d{2}) \\d{4}))\"");
  
  protected void consumeWarnDate()
  {
    int curr = offs;
    Matcher m = WARN_DATE_PATTERN.matcher(src.substring(offs));
    if (!m.lookingAt()) {
      parseError();
    }
    offs += m.end();
    warnDate = DateUtils.parseDate(src.substring(curr + 1, offs - 1));
  }
  
  protected void consumeWarnValue()
  {
    consumeLinearWhitespace();
    consumeWarnCode();
    consumeWarnAgent();
    consumeWarnText();
    if ((offs + 1 < src.length()) && (src.charAt(offs) == ' ') && (src.charAt(offs + 1) == '"'))
    {
      consumeCharacter(' ');
      consumeWarnDate();
    }
    consumeLinearWhitespace();
    if (offs != src.length()) {
      consumeCharacter(',');
    }
  }
  
  protected void consumeCharacter(char c)
  {
    if ((offs + 1 > src.length()) || (c != src.charAt(offs))) {
      parseError();
    }
    offs += 1;
  }
  
  protected void consumeWarnCode()
  {
    if ((offs + 4 > src.length()) || (!Character.isDigit(src.charAt(offs))) || (!Character.isDigit(src.charAt(offs + 1))) || (!Character.isDigit(src.charAt(offs + 2))) || (src.charAt(offs + 3) != ' ')) {
      parseError();
    }
    warnCode = Integer.parseInt(src.substring(offs, offs + 3));
    offs += 4;
  }
  
  private void parseError()
  {
    String s = src.substring(init_offs);
    throw new IllegalArgumentException("Bad warn code \"" + s + "\"");
  }
  
  public int getWarnCode()
  {
    return warnCode;
  }
  
  public String getWarnAgent()
  {
    return warnAgent;
  }
  
  public String getWarnText()
  {
    return warnText;
  }
  
  public Date getWarnDate()
  {
    return warnDate;
  }
  
  public String toString()
  {
    if (warnDate != null) {
      return String.format("%d %s %s \"%s\"", new Object[] { Integer.valueOf(warnCode), warnAgent, warnText, DateUtils.formatDate(warnDate) });
    }
    return String.format("%d %s %s", new Object[] { Integer.valueOf(warnCode), warnAgent, warnText });
  }
}

/* Location:
 * Qualified Name:     org.apache.http.impl.client.cache.WarningValue
 * Java Class Version: 5 (49.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.http.impl.client.cache.ehcache;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import net.sf.ehcache.Ehcache;
import net.sf.ehcache.Element;
import org.apache.http.client.cache.HttpCacheEntry;
import org.apache.http.client.cache.HttpCacheEntrySerializer;
import org.apache.http.client.cache.HttpCacheStorage;
import org.apache.http.client.cache.HttpCacheUpdateCallback;
import org.apache.http.client.cache.HttpCacheUpdateException;
import o
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2019. Infinite Loop Ltd