package com.mbridge.msdk.click; import android.text.TextUtils; import android.webkit.URLUtil; import com.google.firebase.perf.network.FirebasePerfUrlConnection; import com.mbridge.msdk.foundation.entity.CampaignEx; import com.mbridge.msdk.foundation.tools.ab; import com.mbridge.msdk.foundation.tools.af; import com.mbridge.msdk.newreward.function.common.MBridgeCommon; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLConnection; /* loaded from: classes4.dex */ public class h { private static final String a = "h"; private com.mbridge.msdk.c.g b; private String c; private boolean d = true; private final int e = 3145728; private com.mbridge.msdk.click.entity.a f; public h() { com.mbridge.msdk.c.g b = com.mbridge.msdk.c.h.a().b(com.mbridge.msdk.foundation.controller.c.m().k()); this.b = b; if (b == null) { com.mbridge.msdk.c.h.a(); this.b = com.mbridge.msdk.c.i.a(); } } public final com.mbridge.msdk.click.entity.a a(String str, boolean z, boolean z2, CampaignEx campaignEx) { HttpURLConnection httpURLConnection; int i; HttpURLConnection httpURLConnection2 = null; if (!URLUtil.isNetworkUrl(str)) { return null; } String replace = str.replace(" ", "%20"); this.f = new com.mbridge.msdk.click.entity.a(); try { httpURLConnection = (HttpURLConnection) ((URLConnection) FirebasePerfUrlConnection.instrument(new URL(replace).openConnection())); } catch (Throwable th) { th = th; } try { httpURLConnection.setRequestMethod("GET"); if ((!z && !z2) || campaignEx == null) { httpURLConnection.setRequestProperty("User-Agent", ab.g()); } if (z && campaignEx != null && campaignEx.getcUA() == 1) { httpURLConnection.setRequestProperty("User-Agent", ab.g()); } if (z2 && campaignEx != null && campaignEx.getImpUA() == 1) { httpURLConnection.setRequestProperty("User-Agent", ab.g()); } httpURLConnection.setRequestProperty("Accept-Encoding", "gzip"); if (this.b.aJ() && !TextUtils.isEmpty(this.c)) { httpURLConnection.setRequestProperty("referer", this.c); } httpURLConnection.setConnectTimeout(MBridgeCommon.DEFAULT_LOAD_TIMEOUT); httpURLConnection.setReadTimeout(MBridgeCommon.DEFAULT_LOAD_TIMEOUT); httpURLConnection.setInstanceFollowRedirects(false); httpURLConnection.connect(); this.f.a = httpURLConnection.getHeaderField("Location"); this.f.d = httpURLConnection.getHeaderField("Referer"); this.f.f = httpURLConnection.getResponseCode(); this.f.b = httpURLConnection.getContentType(); this.f.e = httpURLConnection.getContentLength(); this.f.c = httpURLConnection.getContentEncoding(); boolean equalsIgnoreCase = "gzip".equalsIgnoreCase(this.f.c); com.mbridge.msdk.click.entity.a aVar = this.f; if (aVar.f == 200 && this.d && (i = aVar.e) > 0 && i < 3145728 && !TextUtils.isEmpty(replace)) { try { String a2 = a(httpURLConnection.getInputStream(), equalsIgnoreCase); if (!TextUtils.isEmpty(a2)) { byte[] bytes = a2.getBytes(); if (bytes.length > 0 && bytes.length < 3145728) { this.f.g = a2.trim(); } } } catch (Throwable th2) { af.b(a, th2.getMessage()); } } this.c = replace; httpURLConnection.disconnect(); return this.f; } catch (Throwable th3) { th = th3; httpURLConnection2 = httpURLConnection; try { this.f.h = th.getMessage(); return this.f; } finally { if (httpURLConnection2 != null) { httpURLConnection2.disconnect(); } } } } /* JADX WARN: Removed duplicated region for block: B:10:0x0040 A[Catch: all -> 0x000f, TryCatch #5 {all -> 0x000f, blocks: (B:41:0x0008, B:4:0x0013, B:8:0x003c, B:10:0x0040, B:11:0x004d), top: B:40:0x0008 }] */ /* JADX WARN: Removed duplicated region for block: B:13:0x0058 A[Catch: Exception -> 0x0031, TRY_ENTER, TRY_LEAVE, TryCatch #3 {Exception -> 0x0031, blocks: (B:34:0x002d, B:13:0x0058), top: B:2:0x0006 }] */ /* JADX WARN: Removed duplicated region for block: B:24:0x0062 A[EXC_TOP_SPLITTER, SYNTHETIC] */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct add '--show-bad-code' argument */ private java.lang.String a(java.io.InputStream r4, boolean r5) { /* r3 = this; java.lang.StringBuilder r0 = new java.lang.StringBuilder r0.() r1 = 0 if (r5 == 0) goto L13 java.util.zip.GZIPInputStream r5 = new java.util.zip.GZIPInputStream // Catch: java.lang.Throwable -> Lf java.lang.Exception -> L11 r5.(r4) // Catch: java.lang.Throwable -> Lf java.lang.Exception -> L11 r4 = r5 goto L13 Lf: r4 = move-exception goto L60 L11: r4 = move-exception goto L3c L13: java.io.BufferedReader r5 = new java.io.BufferedReader // Catch: java.lang.Throwable -> Lf java.lang.Exception -> L11 java.io.InputStreamReader r2 = new java.io.InputStreamReader // Catch: java.lang.Throwable -> Lf java.lang.Exception -> L11 r2.(r4) // Catch: java.lang.Throwable -> Lf java.lang.Exception -> L11 r5.(r2) // Catch: java.lang.Throwable -> Lf java.lang.Exception -> L11 L1d: java.lang.String r4 = r5.readLine() // Catch: java.lang.Throwable -> L27 java.lang.Exception -> L2a if (r4 == 0) goto L2d r0.append(r4) // Catch: java.lang.Throwable -> L27 java.lang.Exception -> L2a goto L1d L27: r4 = move-exception r1 = r5 goto L60 L2a: r4 = move-exception r1 = r5 goto L3c L2d: r5.close() // Catch: java.lang.Exception -> L31 goto L5b L31: r4 = move-exception java.lang.String r5 = com.mbridge.msdk.click.h.a java.lang.String r4 = r4.getMessage() com.mbridge.msdk.foundation.tools.af.b(r5, r4) goto L5b L3c: com.mbridge.msdk.click.entity.a r5 = r3.f // Catch: java.lang.Throwable -> Lf if (r5 != 0) goto L4d com.mbridge.msdk.click.entity.a r5 = new com.mbridge.msdk.click.entity.a // Catch: java.lang.Throwable -> Lf r5.() // Catch: java.lang.Throwable -> Lf r3.f = r5 // Catch: java.lang.Throwable -> Lf java.lang.String r2 = r4.getMessage() // Catch: java.lang.Throwable -> Lf r5.h = r2 // Catch: java.lang.Throwable -> Lf L4d: java.lang.String r5 = com.mbridge.msdk.click.h.a // Catch: java.lang.Throwable -> Lf java.lang.String r4 = r4.getMessage() // Catch: java.lang.Throwable -> Lf com.mbridge.msdk.foundation.tools.af.b(r5, r4) // Catch: java.lang.Throwable -> Lf if (r1 == 0) goto L5b r1.close() // Catch: java.lang.Exception -> L31 L5b: java.lang.String r4 = r0.toString() return r4 L60: if (r1 == 0) goto L70 r1.close() // Catch: java.lang.Exception -> L66 goto L70 L66: r5 = move-exception java.lang.String r0 = com.mbridge.msdk.click.h.a java.lang.String r5 = r5.getMessage() com.mbridge.msdk.foundation.tools.af.b(r0, r5) L70: throw r4 */ throw new UnsupportedOperationException("Method not decompiled: com.mbridge.msdk.click.h.a(java.io.InputStream, boolean):java.lang.String"); } }