package okhttp3.internal.http1;

import g.h0.c.l;
import j.g;
import java.io.IOException;
import okhttp3.Headers;

/* JADX INFO: compiled from: HeadersReader.kt */
/* JADX INFO: loaded from: classes.dex */
public final class HeadersReader {
    public static final Companion Companion = new Companion(null);
    private static final int HEADER_LIMIT = 262144;
    private long headerLimit;
    private final g source;

    /* JADX INFO: compiled from: HeadersReader.kt */
    public static final class Companion {
        private Companion() {
        }

        public /* synthetic */ Companion(g.h0.c.g gVar) {
            this();
        }
    }

    public HeadersReader(g gVar) {
        l.f(gVar, "source");
        this.source = gVar;
        this.headerLimit = HEADER_LIMIT;
    }

    public final g getSource() {
        return this.source;
    }

    public final Headers readHeaders() throws IOException {
        Headers.Builder builder = new Headers.Builder();
        while (true) {
            String line = readLine();
            if (line.length() == 0) {
                return builder.build();
            }
            builder.addLenient$okhttp(line);
        }
    }

    public final String readLine() throws IOException {
        String strU = this.source.u(this.headerLimit);
        this.headerLimit -= (long) strU.length();
        return strU;
    }
}
