package com.amazonaws.http; import com.amazonaws.AmazonClientException; import com.amazonaws.AmazonServiceException; import com.amazonaws.AmazonWebServiceRequest; import com.amazonaws.AmazonWebServiceResponse; import com.amazonaws.ClientConfiguration; import com.amazonaws.Request; import com.amazonaws.RequestClientOptions; import com.amazonaws.Response; import com.amazonaws.handlers.RequestHandler2; import com.amazonaws.internal.CRC32MismatchException; import com.amazonaws.logging.Log; import com.amazonaws.logging.LogFactory; import com.amazonaws.metrics.RequestMetricCollector; import com.amazonaws.retry.RetryPolicy; import com.amazonaws.util.AWSRequestMetrics; import com.amazonaws.util.DateUtils; import com.amazonaws.util.TimingInfo; import com.amazonaws.util.URIBuilder; import java.io.IOException; import java.io.InputStream; import java.net.URI; import java.net.URISyntaxException; import java.util.Collections; import java.util.Date; import java.util.Iterator; import java.util.List; import org.apache.http.HttpStatus; import org.apache.http.protocol.HTTP; /* loaded from: classes.dex */ public class AmazonHttpClient { public static final Log REQUEST_LOG = LogFactory.getLog("com.amazonaws.request"); public static final Log log = LogFactory.getLog(AmazonHttpClient.class); public final ClientConfiguration config; public final HttpClient httpClient; public final HttpRequestFactory requestFactory = new HttpRequestFactory(); public final RequestMetricCollector requestMetricCollector = null; public RequestMetricCollector getRequestMetricCollector() { return this.requestMetricCollector; } public AmazonHttpClient(ClientConfiguration clientConfiguration, HttpClient httpClient) { this.config = clientConfiguration; this.httpClient = httpClient; } public Response execute(Request request, HttpResponseHandler httpResponseHandler, HttpResponseHandler httpResponseHandler2, ExecutionContext executionContext) { Response response; if (request.getHostPrefix() != null) { try { URI endpoint = request.getEndpoint(); request.setEndpoint(URIBuilder.builder(endpoint).host(request.getHostPrefix() + endpoint.getHost()).build()); } catch (URISyntaxException e) { Log log2 = log; if (log2.isDebugEnabled()) { log2.debug("Failed to prepend host prefix: " + e.getMessage(), e); } } } if (executionContext == null) { throw new AmazonClientException("Internal SDK Error: No execution context parameter specified."); } List requestHandler2s = requestHandler2s(request, executionContext); AWSRequestMetrics awsRequestMetrics = executionContext.getAwsRequestMetrics(); try { response = executeHelper(request, httpResponseHandler, httpResponseHandler2, executionContext); } catch (AmazonClientException e2) { e = e2; response = null; } try { afterResponse(request, requestHandler2s, response, awsRequestMetrics.getTimingInfo().endTiming()); return response; } catch (AmazonClientException e3) { e = e3; afterError(request, response, requestHandler2s, e); throw e; } } public void afterError(Request request, Response response, List list, AmazonClientException amazonClientException) { Iterator it = list.iterator(); while (it.hasNext()) { ((RequestHandler2) it.next()).afterError(request, response, amazonClientException); } } public void afterResponse(Request request, List list, Response response, TimingInfo timingInfo) { Iterator it = list.iterator(); while (it.hasNext()) { ((RequestHandler2) it.next()).afterResponse(request, response); } } public List requestHandler2s(Request request, ExecutionContext executionContext) { List requestHandler2s = executionContext.getRequestHandler2s(); if (requestHandler2s == null) { return Collections.emptyList(); } Iterator it = requestHandler2s.iterator(); while (it.hasNext()) { ((RequestHandler2) it.next()).beforeRequest(request); } return requestHandler2s; } /* JADX WARN: Removed duplicated region for block: B:41:0x0473 */ /* JADX WARN: Removed duplicated region for block: B:54:? A[SYNTHETIC] */ /* JADX WARN: Removed duplicated region for block: B:64:0x03ec A[Catch: all -> 0x03ab, TRY_ENTER, TryCatch #6 {all -> 0x03ab, blocks: (B:61:0x03e2, B:64:0x03ec, B:65:0x0402, B:67:0x0444, B:81:0x0470, B:246:0x03a5, B:247:0x03aa), top: B:60:0x03e2 }] */ /* JADX WARN: Removed duplicated region for block: B:67:0x0444 A[Catch: all -> 0x03ab, TRY_LEAVE, TryCatch #6 {all -> 0x03ab, blocks: (B:61:0x03e2, B:64:0x03ec, B:65:0x0402, B:67:0x0444, B:81:0x0470, B:246:0x03a5, B:247:0x03aa), top: B:60:0x03e2 }] */ /* JADX WARN: Removed duplicated region for block: B:80:0x0470 A[SYNTHETIC] */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct add '--show-bad-code' argument */ public com.amazonaws.Response executeHelper(com.amazonaws.Request r27, com.amazonaws.http.HttpResponseHandler r28, com.amazonaws.http.HttpResponseHandler r29, com.amazonaws.http.ExecutionContext r30) { /* Method dump skipped, instructions count: 1162 To view this dump add '--comments-level debug' option */ throw new UnsupportedOperationException("Method not decompiled: com.amazonaws.http.AmazonHttpClient.executeHelper(com.amazonaws.Request, com.amazonaws.http.HttpResponseHandler, com.amazonaws.http.HttpResponseHandler, com.amazonaws.http.ExecutionContext):com.amazonaws.Response"); } public final Throwable handleUnexpectedFailure(Throwable th, AWSRequestMetrics aWSRequestMetrics) { AWSRequestMetrics.Field field = AWSRequestMetrics.Field.Exception; aWSRequestMetrics.incrementCounter(field); aWSRequestMetrics.addProperty(field, th); return th; } public void resetRequestAfterError(Request request, Exception exc) { if (request.getContent() == null) { return; } if (!request.getContent().markSupported()) { throw new AmazonClientException("Encountered an exception and stream is not resettable", exc); } try { request.getContent().reset(); } catch (IOException unused) { throw new AmazonClientException("Encountered an exception and couldn't reset the stream to retry", exc); } } public void setUserAgent(Request request) { RequestClientOptions requestClientOptions; String clientMarker; String str = ClientConfiguration.DEFAULT_USER_AGENT; AmazonWebServiceRequest originalRequest = request.getOriginalRequest(); String createUserAgentString = (originalRequest == null || (requestClientOptions = originalRequest.getRequestClientOptions()) == null || (clientMarker = requestClientOptions.getClientMarker(RequestClientOptions.Marker.USER_AGENT)) == null) ? str : createUserAgentString(str, clientMarker); if (!str.equals(this.config.getUserAgent())) { createUserAgentString = createUserAgentString(createUserAgentString, this.config.getUserAgent()); } if (this.config.getUserAgentOverride() != null) { createUserAgentString = this.config.getUserAgentOverride(); } request.addHeader("User-Agent", createUserAgentString); } public static String createUserAgentString(String str, String str2) { if (str.contains(str2)) { return str; } return str.trim() + " " + str2.trim(); } public void shutdown() { this.httpClient.shutdown(); } public final boolean shouldRetry(AmazonWebServiceRequest amazonWebServiceRequest, InputStream inputStream, AmazonClientException amazonClientException, int i, RetryPolicy retryPolicy) { int i2 = i - 1; int maxErrorRetry = this.config.getMaxErrorRetry(); if (maxErrorRetry < 0 || !retryPolicy.isMaxErrorRetryInClientConfigHonored()) { maxErrorRetry = retryPolicy.getMaxErrorRetry(); } if (i2 >= maxErrorRetry) { return false; } if (inputStream != null && !inputStream.markSupported()) { Log log2 = log; if (log2.isDebugEnabled()) { log2.debug("Content not repeatable"); } return false; } return retryPolicy.getRetryCondition().shouldRetry(amazonWebServiceRequest, amazonClientException, i2); } public static boolean isTemporaryRedirect(HttpResponse httpResponse) { int statusCode = httpResponse.getStatusCode(); String str = (String) httpResponse.getHeaders().get("Location"); return (statusCode != 307 || str == null || str.isEmpty()) ? false : true; } public final boolean isRequestSuccessful(HttpResponse httpResponse) { int statusCode = httpResponse.getStatusCode(); return statusCode >= 200 && statusCode < 300; } public Object handleResponse(Request request, HttpResponseHandler httpResponseHandler, HttpResponse httpResponse, ExecutionContext executionContext) { try { AWSRequestMetrics awsRequestMetrics = executionContext.getAwsRequestMetrics(); AWSRequestMetrics.Field field = AWSRequestMetrics.Field.ResponseProcessingTime; awsRequestMetrics.startEvent(field); try { AmazonWebServiceResponse amazonWebServiceResponse = (AmazonWebServiceResponse) httpResponseHandler.handle(httpResponse); awsRequestMetrics.endEvent(field); if (amazonWebServiceResponse == null) { throw new RuntimeException("Unable to unmarshall response metadata. Response Code: " + httpResponse.getStatusCode() + ", Response Text: " + httpResponse.getStatusText()); } Log log2 = REQUEST_LOG; if (log2.isDebugEnabled()) { log2.debug("Received successful response: " + httpResponse.getStatusCode() + ", AWS Request ID: " + amazonWebServiceResponse.getRequestId()); } awsRequestMetrics.addProperty(AWSRequestMetrics.Field.AWSRequestID, amazonWebServiceResponse.getRequestId()); return amazonWebServiceResponse.getResult(); } catch (Throwable th) { awsRequestMetrics.endEvent(AWSRequestMetrics.Field.ResponseProcessingTime); throw th; } } catch (CRC32MismatchException e) { throw e; } catch (IOException e2) { throw e2; } catch (Exception e3) { throw new AmazonClientException("Unable to unmarshall response (" + e3.getMessage() + "). Response Code: " + httpResponse.getStatusCode() + ", Response Text: " + httpResponse.getStatusText(), e3); } } public AmazonServiceException handleErrorResponse(Request request, HttpResponseHandler httpResponseHandler, HttpResponse httpResponse) { AmazonServiceException amazonServiceException; int statusCode = httpResponse.getStatusCode(); try { amazonServiceException = (AmazonServiceException) httpResponseHandler.handle(httpResponse); REQUEST_LOG.debug("Received error response: " + amazonServiceException.toString()); } catch (Exception e) { if (statusCode == 413) { amazonServiceException = new AmazonServiceException("Request entity too large"); amazonServiceException.setServiceName(request.getServiceName()); amazonServiceException.setStatusCode(HttpStatus.SC_REQUEST_TOO_LONG); amazonServiceException.setErrorType(AmazonServiceException.ErrorType.Client); amazonServiceException.setErrorCode("Request entity too large"); } else if (statusCode == 503 && "Service Unavailable".equalsIgnoreCase(httpResponse.getStatusText())) { amazonServiceException = new AmazonServiceException("Service unavailable"); amazonServiceException.setServiceName(request.getServiceName()); amazonServiceException.setStatusCode(HttpStatus.SC_SERVICE_UNAVAILABLE); amazonServiceException.setErrorType(AmazonServiceException.ErrorType.Service); amazonServiceException.setErrorCode("Service unavailable"); } else { if (e instanceof IOException) { throw ((IOException) e); } throw new AmazonClientException("Unable to unmarshall error response (" + e.getMessage() + "). Response Code: " + statusCode + ", Response Text: " + httpResponse.getStatusText() + ", Response Headers: " + httpResponse.getHeaders(), e); } } amazonServiceException.setStatusCode(statusCode); amazonServiceException.setServiceName(request.getServiceName()); amazonServiceException.fillInStackTrace(); return amazonServiceException; } public final long pauseBeforeNextRetry(AmazonWebServiceRequest amazonWebServiceRequest, AmazonClientException amazonClientException, int i, RetryPolicy retryPolicy) { int i2 = i - 2; long delayBeforeNextRetry = retryPolicy.getBackoffStrategy().delayBeforeNextRetry(amazonWebServiceRequest, amazonClientException, i2); Log log2 = log; if (log2.isDebugEnabled()) { log2.debug("Retriable error detected, will retry in " + delayBeforeNextRetry + "ms, attempt number: " + i2); } try { Thread.sleep(delayBeforeNextRetry); return delayBeforeNextRetry; } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new AmazonClientException(e.getMessage(), e); } } public final String getServerDateFromException(String str) { int indexOf; int indexOf2 = str.indexOf("("); if (str.contains(" + 15")) { indexOf = str.indexOf(" + 15"); } else { indexOf = str.indexOf(" - 15"); } return str.substring(indexOf2 + 1, indexOf); } /* JADX WARN: Multi-variable type inference failed */ /* JADX WARN: Type inference failed for: r4v12 */ /* JADX WARN: Type inference failed for: r4v3, types: [java.lang.String] */ public long parseClockSkewOffset(HttpResponse httpResponse, AmazonServiceException amazonServiceException) { Date parseRFC822Date; Date date = new Date(); String str = (String) httpResponse.getHeaders().get(HTTP.DATE_HEADER); try { if (str != 0) { try { if (!str.isEmpty()) { parseRFC822Date = DateUtils.parseRFC822Date(str); long time = date.getTime() - parseRFC822Date.getTime(); str = 1000; return time / 1000; } } catch (RuntimeException e) { e = e; str = 0; log.warn("Unable to parse clock skew offset from response: " + str, e); return 0L; } } parseRFC822Date = DateUtils.parseCompressedISO8601Date(getServerDateFromException(amazonServiceException.getMessage())); long time2 = date.getTime() - parseRFC822Date.getTime(); str = 1000; return time2 / 1000; } catch (RuntimeException e2) { e = e2; } } public void finalize() { shutdown(); super.finalize(); } }