package l5; import h5.d0; import h5.e0; import h5.g0; import h5.h0; import h5.i0; import h5.k0; import h5.p; import h5.q; import h5.y; import java.util.List; /* loaded from: classes2.dex */ public final class a implements d0 { /* renamed from: a, reason: collision with root package name */ private final q f11598a; public a(q qVar) { this.f11598a = qVar; } private String b(List list) { StringBuilder sb = new StringBuilder(); int size = list.size(); for (int i10 = 0; i10 < size; i10++) { if (i10 > 0) { sb.append("; "); } p pVar = (p) list.get(i10); sb.append(pVar.h()); sb.append('='); sb.append(pVar.k()); } return sb.toString(); } @Override // h5.d0 public i0 a(d0.a aVar) { h0 d10 = aVar.d(); h0.a g10 = d10.g(); k0 a10 = d10.a(); if (a10 != null) { e0 b10 = a10.b(); if (b10 != null) { g10.c("Content-Type", b10.toString()); } long a11 = a10.a(); if (a11 != -1) { g10.c("Content-Length", Long.toString(a11)); g10.g("Transfer-Encoding"); } else { g10.c("Transfer-Encoding", "chunked"); g10.g("Content-Length"); } } boolean z10 = false; if (d10.c("Host") == null) { g10.c("Host", i5.c.s(d10.h(), false)); } if (d10.c("Connection") == null) { g10.c("Connection", "Keep-Alive"); } if (d10.c("Accept-Encoding") == null && d10.c("Range") == null) { g10.c("Accept-Encoding", "gzip"); z10 = true; } List b11 = this.f11598a.b(d10.h()); if (!b11.isEmpty()) { g10.c("Cookie", b(b11)); } if (d10.c("User-Agent") == null) { g10.c("User-Agent", i5.d.a()); } i0 e10 = aVar.e(g10.b()); e.f(this.f11598a, d10.h(), e10.R()); i0.a o10 = e10.a0().o(d10); if (z10 && "gzip".equalsIgnoreCase(e10.O("Content-Encoding")) && e.d(e10)) { y yVar = new y(e10.c().P()); o10.i(e10.R().d().f("Content-Encoding").f("Content-Length").e()); o10.d(new h(e10.O("Content-Type"), -1L, g0.f(yVar))); } return o10.e(); } }