package com.firemonkeys.cloudcellapi; import com.google.firebase.perf.network.FirebasePerfUrlConnection; import com.ironsource.v8; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; import java.util.HashMap; import java.util.Map; import org.apache.http.protocol.HTTP; /* loaded from: classes2.dex */ class HttpThread extends Thread { private static final String CLASSNAME = "HttpRequest"; private boolean m_addDefaultHeaders; private long m_callbackPointer; private byte[] m_data; private boolean m_failOnErrorStatus; private String m_method; HttpRequest m_post; private int m_readCapacity; private String m_url; private Map m_mHeaders = new HashMap(); private boolean m_bClosedBySSLCheck = false; private int m_HttpStatus = 0; public void setClosedBySSLCheck(boolean z) { this.m_bClosedBySSLCheck = z; } public HttpThread(HttpRequest httpRequest, String str, String str2, byte[] bArr, int i, long j, boolean z, boolean z2) { this.m_post = null; this.m_method = ""; this.m_url = ""; this.m_data = null; this.m_readCapacity = 0; this.m_callbackPointer = 0L; this.m_failOnErrorStatus = false; this.m_addDefaultHeaders = false; this.m_post = httpRequest; this.m_method = str; this.m_url = str2; this.m_data = bArr; this.m_readCapacity = i; this.m_callbackPointer = j; this.m_failOnErrorStatus = z; this.m_addDefaultHeaders = z2; } public void addHeader(String str, String str2) { this.m_mHeaders.put(str, str2); } public void shutdown() { interrupt(); } public HttpURLConnection GetHttpConnection(URL url) throws IOException { HttpURLConnection httpURLConnection = (HttpURLConnection) ((URLConnection) FirebasePerfUrlConnection.instrument(url.openConnection())); httpURLConnection.setConnectTimeout(this.m_post.getTimeoutMilliseconds()); httpURLConnection.setReadTimeout(this.m_post.getTimeoutMilliseconds()); httpURLConnection.setUseCaches(false); httpURLConnection.setDoInput(true); for (Map.Entry entry : this.m_mHeaders.entrySet()) { httpURLConnection.addRequestProperty(entry.getKey().toString(), entry.getValue().toString()); } httpURLConnection.addRequestProperty("User-Agent", HttpRequest.s_userAgent); httpURLConnection.setRequestMethod(this.m_method); if (this.m_data.length > 0) { httpURLConnection.setDoOutput(true); httpURLConnection.setFixedLengthStreamingMode(this.m_data.length); if (this.m_addDefaultHeaders) { httpURLConnection.setRequestProperty(HTTP.CONTENT_LEN, Integer.toString(this.m_data.length)); httpURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); } else if (!this.m_mHeaders.containsKey("Content-Type")) { httpURLConnection.setRequestProperty("Content-Type", ""); } } return httpURLConnection; } public boolean ReadHttpData(HttpURLConnection httpURLConnection, InputStream inputStream) throws IOException { if (inputStream == null) { Logging.CC_ERROR(CLASSNAME, "ReadHttpData failed, no input stream"); return false; } String headerField = httpURLConnection.getHeaderField(HTTP.CONTENT_LEN); this.m_post.headerCallback(this.m_callbackPointer, headerField != null ? Integer.parseInt(headerField) : 0, httpURLConnection.getHeaderFields()); byte[] bArr = new byte[this.m_readCapacity]; while (true) { int read = inputStream.read(bArr); if (read == -1) { return false; } if (isInterrupted()) { Logging.CC_WARNING(CLASSNAME, "HTTP thread interrupted"); return true; } this.m_post.dataCallback(this.m_callbackPointer, bArr, read); } } public boolean ReadErrors(HttpURLConnection httpURLConnection) { try { InputStream errorStream = httpURLConnection.getErrorStream(); this.m_HttpStatus = httpURLConnection.getResponseCode(); Logging.CC_TRACE(CLASSNAME, "ReadErrors [ErrorResponseCode=" + this.m_HttpStatus + v8.i.e); if (errorStream == null) { return false; } if (this.m_failOnErrorStatus && this.m_HttpStatus >= 400) { errorStream.close(); return false; } byte[] bArr = new byte[this.m_readCapacity]; while (true) { int read = errorStream.read(bArr); if (read != -1) { if (isInterrupted()) { Logging.CC_WARNING(CLASSNAME, "HTTP thread interrupted"); errorStream.close(); return true; } this.m_post.dataCallback(this.m_callbackPointer, bArr, read); } else { errorStream.close(); break; } } } catch (IOException e) { Logging.CC_ERROR(CLASSNAME, "Error processing HTTP error stream, '" + e.getMessage() + "' Cause: " + e.getCause()); } return false; } /* JADX WARN: Removed duplicated region for block: B:23:0x0154 */ /* JADX WARN: Removed duplicated region for block: B:26:0x015b A[ADDED_TO_REGION] */ /* JADX WARN: Removed duplicated region for block: B:28:0x0163 */ /* JADX WARN: Removed duplicated region for block: B:32:0x016d */ @Override // java.lang.Thread, java.lang.Runnable /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct add '--show-bad-code' argument */ public void run() { /* Method dump skipped, instructions count: 377 To view this dump add '--comments-level debug' option */ throw new UnsupportedOperationException("Method not decompiled: com.firemonkeys.cloudcellapi.HttpThread.run():void"); } }