package t9; import java.io.IOException; import java.net.ProtocolException; import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.concurrent.TimeUnit; import n9.b0; import n9.c0; import n9.e0; import n9.g0; import n9.x; import n9.z; import x9.u; import x9.v; import x9.w; /* loaded from: classes2.dex */ public final class g implements r9.c { /* renamed from: g, reason: collision with root package name */ private static final List f14574g = o9.e.u("connection", "host", "keep-alive", "proxy-connection", "te", "transfer-encoding", "encoding", "upgrade", ":method", ":path", ":scheme", ":authority"); /* renamed from: h, reason: collision with root package name */ private static final List f14575h = o9.e.u("connection", "host", "keep-alive", "proxy-connection", "te", "transfer-encoding", "encoding", "upgrade"); /* renamed from: a, reason: collision with root package name */ private final z.a f14576a; /* renamed from: b, reason: collision with root package name */ private final q9.e f14577b; /* renamed from: c, reason: collision with root package name */ private final f f14578c; /* renamed from: d, reason: collision with root package name */ private volatile i f14579d; /* renamed from: e, reason: collision with root package name */ private final c0 f14580e; /* renamed from: f, reason: collision with root package name */ private volatile boolean f14581f; public g(b0 b0Var, q9.e eVar, z.a aVar, f fVar) { this.f14577b = eVar; this.f14576a = aVar; this.f14578c = fVar; List v10 = b0Var.v(); c0 c0Var = c0.H2_PRIOR_KNOWLEDGE; this.f14580e = v10.contains(c0Var) ? c0Var : c0.HTTP_2; } public static List i(e0 e0Var) { x d10 = e0Var.d(); ArrayList arrayList = new ArrayList(d10.h() + 4); arrayList.add(new c(c.f14473f, e0Var.f())); arrayList.add(new c(c.f14474g, r9.i.c(e0Var.h()))); String c10 = e0Var.c("Host"); if (c10 != null) { arrayList.add(new c(c.f14476i, c10)); } arrayList.add(new c(c.f14475h, e0Var.h().D())); int h10 = d10.h(); for (int i10 = 0; i10 < h10; i10++) { String lowerCase = d10.e(i10).toLowerCase(Locale.US); if (!f14574g.contains(lowerCase) || (lowerCase.equals("te") && d10.i(i10).equals("trailers"))) { arrayList.add(new c(lowerCase, d10.i(i10))); } } return arrayList; } public static g0.a j(x xVar, c0 c0Var) { x.a aVar = new x.a(); int h10 = xVar.h(); r9.k kVar = null; for (int i10 = 0; i10 < h10; i10++) { String e10 = xVar.e(i10); String i11 = xVar.i(i10); if (e10.equals(":status")) { kVar = r9.k.a("HTTP/1.1 " + i11); } else if (!f14575h.contains(e10)) { o9.a.f12822a.b(aVar, e10, i11); } } if (kVar != null) { return new g0.a().o(c0Var).g(kVar.f13765b).l(kVar.f13766c).j(aVar.d()); } throw new ProtocolException("Expected ':status' header not present"); } @Override // r9.c public void a() { this.f14579d.h().close(); } @Override // r9.c public g0.a b(boolean z10) { g0.a j10 = j(this.f14579d.p(), this.f14580e); if (z10 && o9.a.f12822a.d(j10) == 100) { return null; } return j10; } @Override // r9.c public void c() { this.f14578c.flush(); } @Override // r9.c public void cancel() { this.f14581f = true; if (this.f14579d != null) { this.f14579d.f(b.CANCEL); } } @Override // r9.c public void d(e0 e0Var) { if (this.f14579d != null) { return; } this.f14579d = this.f14578c.u0(i(e0Var), e0Var.a() != null); if (this.f14581f) { this.f14579d.f(b.CANCEL); throw new IOException("Canceled"); } w l10 = this.f14579d.l(); long a10 = this.f14576a.a(); TimeUnit timeUnit = TimeUnit.MILLISECONDS; l10.g(a10, timeUnit); this.f14579d.r().g(this.f14576a.b(), timeUnit); } @Override // r9.c public q9.e e() { return this.f14577b; } @Override // r9.c public long f(g0 g0Var) { return r9.e.b(g0Var); } @Override // r9.c public v g(g0 g0Var) { return this.f14579d.i(); } @Override // r9.c public u h(e0 e0Var, long j10) { return this.f14579d.h(); } }