package r9; import java.net.ProtocolException; import n9.e0; import n9.g0; import n9.z; import x9.n; /* loaded from: classes2.dex */ public final class b implements z { /* renamed from: a, reason: collision with root package name */ private final boolean f13744a; public b(boolean z10) { this.f13744a = z10; } @Override // n9.z public g0 a(z.a aVar) { boolean z10; g gVar = (g) aVar; q9.c f10 = gVar.f(); e0 d10 = gVar.d(); long currentTimeMillis = System.currentTimeMillis(); f10.p(d10); g0.a aVar2 = null; if (!f.a(d10.f()) || d10.a() == null) { f10.j(); z10 = false; } else { if ("100-continue".equalsIgnoreCase(d10.c("Expect"))) { f10.g(); f10.n(); aVar2 = f10.l(true); z10 = true; } else { z10 = false; } if (aVar2 != null) { f10.j(); if (!f10.c().n()) { f10.i(); } } else if (d10.a().f()) { f10.g(); d10.a().h(n.b(f10.d(d10, true))); } else { x9.d b10 = n.b(f10.d(d10, false)); d10.a().h(b10); b10.close(); } } if (d10.a() == null || !d10.a().f()) { f10.f(); } if (!z10) { f10.n(); } if (aVar2 == null) { aVar2 = f10.l(false); } g0 c10 = aVar2.q(d10).h(f10.c().k()).r(currentTimeMillis).p(System.currentTimeMillis()).c(); int G = c10.G(); if (G == 100) { c10 = f10.l(false).q(d10).h(f10.c().k()).r(currentTimeMillis).p(System.currentTimeMillis()).c(); G = c10.G(); } f10.m(c10); g0 c11 = (this.f13744a && G == 101) ? c10.a0().b(o9.e.f12829d).c() : c10.a0().b(f10.k(c10)).c(); if ("close".equalsIgnoreCase(c11.j0().c("Connection")) || "close".equalsIgnoreCase(c11.O("Connection"))) { f10.i(); } if ((G != 204 && G != 205) || c11.c().G() <= 0) { return c11; } throw new ProtocolException("HTTP " + G + " had non-zero Content-Length: " + c11.c().G()); } }