package io.netty.handler.codec.http;

import g.a.a.a.a;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import io.netty.handler.codec.DecoderResult;
import io.netty.handler.codec.PrematureChannelClosureException;
import io.netty.handler.codec.TooLongFrameException;
import io.netty.util.ByteProcessor;
import io.netty.util.internal.AppendableCharSequence;
import java.util.List;

/* JADX INFO: loaded from: classes.dex */
public abstract class HttpObjectDecoder extends ByteToMessageDecoder {
    public static final /* synthetic */ boolean $assertionsDisabled = false;
    private static final String EMPTY_VALUE = "";
    private long chunkSize;
    private final boolean chunkedSupported;
    private long contentLength;
    private State currentState;
    private final HeaderParser headerParser;
    private final LineParser lineParser;
    private final int maxChunkSize;
    private HttpMessage message;
    private CharSequence name;
    private volatile boolean resetRequested;
    private LastHttpContent trailer;
    public final boolean validateHeaders;
    private CharSequence value;

    /* JADX INFO: renamed from: io.netty.handler.codec.http.HttpObjectDecoder$1, reason: invalid class name */
    public static /* synthetic */ class AnonymousClass1 {
        public static final /* synthetic */ int[] $SwitchMap$io$netty$handler$codec$http$HttpObjectDecoder$State;

        static {
            State.values();
            int[] iArr = new int[11];
            $SwitchMap$io$netty$handler$codec$http$HttpObjectDecoder$State = iArr;
            try {
                iArr[State.SKIP_CONTROL_CHARS.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                $SwitchMap$io$netty$handler$codec$http$HttpObjectDecoder$State[State.READ_CHUNK_SIZE.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                $SwitchMap$io$netty$handler$codec$http$HttpObjectDecoder$State[State.READ_INITIAL.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            try {
                $SwitchMap$io$netty$handler$codec$http$HttpObjectDecoder$State[State.READ_HEADER.ordinal()] = 4;
            } catch (NoSuchFieldError unused4) {
            }
            try {
                $SwitchMap$io$netty$handler$codec$http$HttpObjectDecoder$State[State.READ_VARIABLE_LENGTH_CONTENT.ordinal()] = 5;
            } catch (NoSuchFieldError unused5) {
            }
            try {
                $SwitchMap$io$netty$handler$codec$http$HttpObjectDecoder$State[State.READ_FIXED_LENGTH_CONTENT.ordinal()] = 6;
            } catch (NoSuchFieldError unused6) {
            }
            try {
                $SwitchMap$io$netty$handler$codec$http$HttpObjectDecoder$State[State.READ_CHUNKED_CONTENT.ordinal()] = 7;
            } catch (NoSuchFieldError unused7) {
            }
            try {
                $SwitchMap$io$netty$handler$codec$http$HttpObjectDecoder$State[State.READ_CHUNK_DELIMITER.ordinal()] = 8;
            } catch (NoSuchFieldError unused8) {
            }
            try {
                $SwitchMap$io$netty$handler$codec$http$HttpObjectDecoder$State[State.READ_CHUNK_FOOTER.ordinal()] = 9;
            } catch (NoSuchFieldError unused9) {
            }
            try {
                $SwitchMap$io$netty$handler$codec$http$HttpObjectDecoder$State[State.BAD_MESSAGE.ordinal()] = 10;
            } catch (NoSuchFieldError unused10) {
            }
            try {
                $SwitchMap$io$netty$handler$codec$http$HttpObjectDecoder$State[State.UPGRADED.ordinal()] = 11;
            } catch (NoSuchFieldError unused11) {
            }
        }
    }

    public static class HeaderParser implements ByteProcessor {
        private final int maxLength;
        private final AppendableCharSequence seq;
        private int size;

        public HeaderParser(AppendableCharSequence appendableCharSequence, int i2) {
            this.seq = appendableCharSequence;
            this.maxLength = i2;
        }

        public TooLongFrameException newException(int i2) {
            return new TooLongFrameException(a.n("HTTP header is larger than ", i2, " bytes."));
        }

        public AppendableCharSequence parse(ByteBuf byteBuf) {
            int i2 = this.size;
            this.seq.reset();
            int iForEachByte = byteBuf.forEachByte(this);
            if (iForEachByte == -1) {
                this.size = i2;
                return null;
            }
            byteBuf.readerIndex(iForEachByte + 1);
            return this.seq;
        }

        @Override // io.netty.util.ByteProcessor
        public boolean process(byte b2) {
            char c2 = (char) (b2 & 255);
            if (c2 == '\r') {
                return true;
            }
            if (c2 == '\n') {
                return false;
            }
            int i2 = this.size + 1;
            this.size = i2;
            int i3 = this.maxLength;
            if (i2 > i3) {
                throw newException(i3);
            }
            this.seq.append(c2);
            return true;
        }

        public void reset() {
            this.size = 0;
        }
    }

    public static final class LineParser extends HeaderParser {
        public LineParser(AppendableCharSequence appendableCharSequence, int i2) {
            super(appendableCharSequence, i2);
        }

        @Override // io.netty.handler.codec.http.HttpObjectDecoder.HeaderParser
        public TooLongFrameException newException(int i2) {
            return new TooLongFrameException(a.n("An HTTP line is larger than ", i2, " bytes."));
        }

        @Override // io.netty.handler.codec.http.HttpObjectDecoder.HeaderParser
        public AppendableCharSequence parse(ByteBuf byteBuf) {
            reset();
            return super.parse(byteBuf);
        }
    }

    public enum State {
        SKIP_CONTROL_CHARS,
        READ_INITIAL,
        READ_HEADER,
        READ_VARIABLE_LENGTH_CONTENT,
        READ_FIXED_LENGTH_CONTENT,
        READ_CHUNK_SIZE,
        READ_CHUNKED_CONTENT,
        READ_CHUNK_DELIMITER,
        READ_CHUNK_FOOTER,
        BAD_MESSAGE,
        UPGRADED
    }

    public HttpObjectDecoder() {
        this(4096, 8192, 8192, true);
    }

    public HttpObjectDecoder(int i2, int i3, int i4, boolean z2) {
        this(i2, i3, i4, z2, true);
    }

    public HttpObjectDecoder(int i2, int i3, int i4, boolean z2, boolean z3) {
        this(i2, i3, i4, z2, z3, 128);
    }

    public HttpObjectDecoder(int i2, int i3, int i4, boolean z2, boolean z3, int i5) {
        this.contentLength = Long.MIN_VALUE;
        this.currentState = State.SKIP_CONTROL_CHARS;
        if (i2 <= 0) {
            throw new IllegalArgumentException(a.l("maxInitialLineLength must be a positive integer: ", i2));
        }
        if (i3 <= 0) {
            throw new IllegalArgumentException(a.l("maxHeaderSize must be a positive integer: ", i3));
        }
        if (i4 <= 0) {
            throw new IllegalArgumentException(a.l("maxChunkSize must be a positive integer: ", i4));
        }
        AppendableCharSequence appendableCharSequence = new AppendableCharSequence(i5);
        this.lineParser = new LineParser(appendableCharSequence, i2);
        this.headerParser = new HeaderParser(appendableCharSequence, i3);
        this.maxChunkSize = i4;
        this.chunkedSupported = z2;
        this.validateHeaders = z3;
    }

    private long contentLength() {
        if (this.contentLength == Long.MIN_VALUE) {
            this.contentLength = HttpUtil.getContentLength(this.message, -1L);
        }
        return this.contentLength;
    }

    private static int findEndOfString(AppendableCharSequence appendableCharSequence) {
        for (int length = appendableCharSequence.length() - 1; length > 0; length--) {
            if (!Character.isWhitespace(appendableCharSequence.charAtUnsafe(length))) {
                return length + 1;
            }
        }
        return 0;
    }

    private static int findNonWhitespace(AppendableCharSequence appendableCharSequence, int i2) {
        while (i2 < appendableCharSequence.length()) {
            if (!Character.isWhitespace(appendableCharSequence.charAtUnsafe(i2))) {
                return i2;
            }
            i2++;
        }
        return appendableCharSequence.length();
    }

    private static int findWhitespace(AppendableCharSequence appendableCharSequence, int i2) {
        while (i2 < appendableCharSequence.length()) {
            if (Character.isWhitespace(appendableCharSequence.charAtUnsafe(i2))) {
                return i2;
            }
            i2++;
        }
        return appendableCharSequence.length();
    }

    private static int getChunkSize(String str) {
        String strTrim = str.trim();
        for (int i2 = 0; i2 < strTrim.length(); i2++) {
            char cCharAt = strTrim.charAt(i2);
            if (cCharAt == ';' || Character.isWhitespace(cCharAt) || Character.isISOControl(cCharAt)) {
                strTrim = strTrim.substring(0, i2);
                break;
            }
        }
        return Integer.parseInt(strTrim, 16);
    }

    private HttpContent invalidChunk(ByteBuf byteBuf, Exception exc) {
        this.currentState = State.BAD_MESSAGE;
        byteBuf.skipBytes(byteBuf.readableBytes());
        DefaultLastHttpContent defaultLastHttpContent = new DefaultLastHttpContent(Unpooled.EMPTY_BUFFER);
        defaultLastHttpContent.setDecoderResult(DecoderResult.failure(exc));
        this.message = null;
        this.trailer = null;
        return defaultLastHttpContent;
    }

    private HttpMessage invalidMessage(ByteBuf byteBuf, Exception exc) {
        this.currentState = State.BAD_MESSAGE;
        byteBuf.skipBytes(byteBuf.readableBytes());
        HttpMessage httpMessageCreateInvalidMessage = this.message;
        if (httpMessageCreateInvalidMessage == null) {
            httpMessageCreateInvalidMessage = createInvalidMessage();
            this.message = httpMessageCreateInvalidMessage;
        }
        httpMessageCreateInvalidMessage.setDecoderResult(DecoderResult.failure(exc));
        HttpMessage httpMessage = this.message;
        this.message = null;
        return httpMessage;
    }

    private State readHeaders(ByteBuf byteBuf) {
        HttpMessage httpMessage = this.message;
        HttpHeaders httpHeadersHeaders = httpMessage.headers();
        AppendableCharSequence appendableCharSequence = this.headerParser.parse(byteBuf);
        if (appendableCharSequence == null) {
            return null;
        }
        if (appendableCharSequence.length() > 0) {
            do {
                char cCharAt = appendableCharSequence.charAt(0);
                CharSequence charSequence = this.name;
                if (charSequence == null || !(cCharAt == ' ' || cCharAt == '\t')) {
                    if (charSequence != null) {
                        httpHeadersHeaders.add(charSequence, this.value);
                    }
                    splitHeader(appendableCharSequence);
                } else {
                    this.value = a.k(String.valueOf(this.value), ' ', appendableCharSequence.toString().trim());
                }
                appendableCharSequence = this.headerParser.parse(byteBuf);
                if (appendableCharSequence == null) {
                    return null;
                }
            } while (appendableCharSequence.length() > 0);
        }
        CharSequence charSequence2 = this.name;
        if (charSequence2 != null) {
            httpHeadersHeaders.add(charSequence2, this.value);
        }
        this.name = null;
        this.value = null;
        if (!isContentAlwaysEmpty(httpMessage)) {
            return HttpUtil.isTransferEncodingChunked(httpMessage) ? State.READ_CHUNK_SIZE : contentLength() >= 0 ? State.READ_FIXED_LENGTH_CONTENT : State.READ_VARIABLE_LENGTH_CONTENT;
        }
        HttpUtil.setTransferEncodingChunked(httpMessage, false);
        return State.SKIP_CONTROL_CHARS;
    }

    private LastHttpContent readTrailingHeaders(ByteBuf byteBuf) {
        AppendableCharSequence appendableCharSequence = this.headerParser.parse(byteBuf);
        if (appendableCharSequence == null) {
            return null;
        }
        if (appendableCharSequence.length() <= 0) {
            return LastHttpContent.EMPTY_LAST_CONTENT;
        }
        LastHttpContent defaultLastHttpContent = this.trailer;
        if (defaultLastHttpContent == null) {
            defaultLastHttpContent = new DefaultLastHttpContent(Unpooled.EMPTY_BUFFER, this.validateHeaders);
            this.trailer = defaultLastHttpContent;
        }
        CharSequence charSequence = null;
        do {
            char cCharAt = appendableCharSequence.charAt(0);
            if (charSequence == null || !(cCharAt == ' ' || cCharAt == '\t')) {
                splitHeader(appendableCharSequence);
                CharSequence charSequence2 = this.name;
                if (!HttpHeaderNames.CONTENT_LENGTH.contentEqualsIgnoreCase(charSequence2) && !HttpHeaderNames.TRANSFER_ENCODING.contentEqualsIgnoreCase(charSequence2) && !HttpHeaderNames.TRAILER.contentEqualsIgnoreCase(charSequence2)) {
                    defaultLastHttpContent.trailingHeaders().add(charSequence2, this.value);
                }
                charSequence = this.name;
                this.name = null;
                this.value = null;
            } else {
                List<String> all = defaultLastHttpContent.trailingHeaders().getAll(charSequence);
                if (!all.isEmpty()) {
                    int size = all.size() - 1;
                    String strTrim = appendableCharSequence.toString().trim();
                    all.set(size, all.get(size) + strTrim);
                }
            }
            appendableCharSequence = this.headerParser.parse(byteBuf);
            if (appendableCharSequence == null) {
                return null;
            }
        } while (appendableCharSequence.length() > 0);
        this.trailer = null;
        return defaultLastHttpContent;
    }

    private void resetNow() {
        State state;
        HttpResponse httpResponse;
        HttpMessage httpMessage = this.message;
        this.message = null;
        this.name = null;
        this.value = null;
        this.contentLength = Long.MIN_VALUE;
        this.lineParser.reset();
        this.headerParser.reset();
        this.trailer = null;
        if (isDecodingRequest() || (httpResponse = (HttpResponse) httpMessage) == null || !isSwitchingToNonHttp1Protocol(httpResponse)) {
            this.resetRequested = false;
            state = State.SKIP_CONTROL_CHARS;
        } else {
            state = State.UPGRADED;
        }
        this.currentState = state;
    }

    private static boolean skipControlCharacters(ByteBuf byteBuf) {
        boolean z2;
        int iWriterIndex = byteBuf.writerIndex();
        int i2 = byteBuf.readerIndex();
        while (true) {
            if (iWriterIndex <= i2) {
                z2 = false;
                break;
            }
            int i3 = i2 + 1;
            short unsignedByte = byteBuf.getUnsignedByte(i2);
            if (!Character.isISOControl(unsignedByte) && !Character.isWhitespace(unsignedByte)) {
                i2 = i3 - 1;
                z2 = true;
                break;
            }
            i2 = i3;
        }
        byteBuf.readerIndex(i2);
        return z2;
    }

    private void splitHeader(AppendableCharSequence appendableCharSequence) {
        char cCharAt;
        int length = appendableCharSequence.length();
        int iFindNonWhitespace = findNonWhitespace(appendableCharSequence, 0);
        int i2 = iFindNonWhitespace;
        while (i2 < length && (cCharAt = appendableCharSequence.charAt(i2)) != ':' && !Character.isWhitespace(cCharAt)) {
            i2++;
        }
        int i3 = i2;
        while (i3 < length) {
            char cCharAt2 = appendableCharSequence.charAt(i3);
            i3++;
            if (cCharAt2 == ':') {
                break;
            }
        }
        this.name = appendableCharSequence.subStringUnsafe(iFindNonWhitespace, i2);
        int iFindNonWhitespace2 = findNonWhitespace(appendableCharSequence, i3);
        this.value = iFindNonWhitespace2 == length ? "" : appendableCharSequence.subStringUnsafe(iFindNonWhitespace2, findEndOfString(appendableCharSequence));
    }

    private static String[] splitInitialLine(AppendableCharSequence appendableCharSequence) {
        int iFindNonWhitespace = findNonWhitespace(appendableCharSequence, 0);
        int iFindWhitespace = findWhitespace(appendableCharSequence, iFindNonWhitespace);
        int iFindNonWhitespace2 = findNonWhitespace(appendableCharSequence, iFindWhitespace);
        int iFindWhitespace2 = findWhitespace(appendableCharSequence, iFindNonWhitespace2);
        int iFindNonWhitespace3 = findNonWhitespace(appendableCharSequence, iFindWhitespace2);
        int iFindEndOfString = findEndOfString(appendableCharSequence);
        String[] strArr = new String[3];
        strArr[0] = appendableCharSequence.subStringUnsafe(iFindNonWhitespace, iFindWhitespace);
        strArr[1] = appendableCharSequence.subStringUnsafe(iFindNonWhitespace2, iFindWhitespace2);
        strArr[2] = iFindNonWhitespace3 < iFindEndOfString ? appendableCharSequence.subStringUnsafe(iFindNonWhitespace3, iFindEndOfString) : "";
        return strArr;
    }

    public abstract HttpMessage createInvalidMessage();

    public abstract HttpMessage createMessage(String[] strArr);

    @Override // io.netty.handler.codec.ByteToMessageDecoder
    public void decode(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) {
        Object objInvalidChunk;
        if (this.resetRequested) {
            resetNow();
        }
        try {
            switch (this.currentState) {
                case SKIP_CONTROL_CHARS:
                    if (skipControlCharacters(byteBuf)) {
                        this.currentState = State.READ_INITIAL;
                        break;
                    } else {
                        return;
                    }
                case READ_INITIAL:
                    try {
                        AppendableCharSequence appendableCharSequence = this.lineParser.parse(byteBuf);
                        if (appendableCharSequence == null) {
                            return;
                        }
                        String[] strArrSplitInitialLine = splitInitialLine(appendableCharSequence);
                        if (strArrSplitInitialLine.length < 3) {
                            this.currentState = State.SKIP_CONTROL_CHARS;
                            return;
                        } else {
                            this.message = createMessage(strArrSplitInitialLine);
                            this.currentState = State.READ_HEADER;
                        }
                        break;
                    } catch (Exception e2) {
                        objInvalidChunk = invalidMessage(byteBuf, e2);
                        list.add(objInvalidChunk);
                        return;
                    }
                case READ_HEADER:
                    State headers = readHeaders(byteBuf);
                    if (headers == null) {
                        return;
                    }
                    this.currentState = headers;
                    int iOrdinal = headers.ordinal();
                    if (iOrdinal == 0) {
                        list.add(this.message);
                        list.add(LastHttpContent.EMPTY_LAST_CONTENT);
                        resetNow();
                        return;
                    }
                    if (iOrdinal == 5) {
                        if (!this.chunkedSupported) {
                            throw new IllegalArgumentException("Chunked messages not supported");
                        }
                        list.add(this.message);
                        return;
                    }
                    long jContentLength = contentLength();
                    if (jContentLength != 0 && (jContentLength != -1 || !isDecodingRequest())) {
                        list.add(this.message);
                        if (headers == State.READ_FIXED_LENGTH_CONTENT) {
                            this.chunkSize = jContentLength;
                            return;
                        }
                        return;
                    }
                    list.add(this.message);
                    list.add(LastHttpContent.EMPTY_LAST_CONTENT);
                    resetNow();
                    return;
                case READ_VARIABLE_LENGTH_CONTENT:
                    int iMin = Math.min(byteBuf.readableBytes(), this.maxChunkSize);
                    if (iMin > 0) {
                        list.add(new DefaultHttpContent(byteBuf.readRetainedSlice(iMin)));
                        return;
                    }
                    return;
                case READ_FIXED_LENGTH_CONTENT:
                    int i2 = byteBuf.readableBytes();
                    if (i2 == 0) {
                        return;
                    }
                    int iMin2 = Math.min(i2, this.maxChunkSize);
                    long j2 = iMin2;
                    long j3 = this.chunkSize;
                    if (j2 > j3) {
                        iMin2 = (int) j3;
                    }
                    ByteBuf retainedSlice = byteBuf.readRetainedSlice(iMin2);
                    long j4 = this.chunkSize - ((long) iMin2);
                    this.chunkSize = j4;
                    if (j4 != 0) {
                        list.add(new DefaultHttpContent(retainedSlice));
                        return;
                    } else {
                        list.add(new DefaultLastHttpContent(retainedSlice, this.validateHeaders));
                        resetNow();
                        return;
                    }
                case READ_CHUNK_SIZE:
                    AppendableCharSequence appendableCharSequence2 = this.lineParser.parse(byteBuf);
                    if (appendableCharSequence2 != null) {
                        int chunkSize = getChunkSize(appendableCharSequence2.toString());
                        this.chunkSize = chunkSize;
                        if (chunkSize == 0) {
                            this.currentState = State.READ_CHUNK_FOOTER;
                            return;
                        }
                        this.currentState = State.READ_CHUNKED_CONTENT;
                        break;
                    } else {
                        return;
                    }
                case READ_CHUNKED_CONTENT:
                    int iMin3 = Math.min(Math.min((int) this.chunkSize, this.maxChunkSize), byteBuf.readableBytes());
                    if (iMin3 != 0) {
                        DefaultHttpContent defaultHttpContent = new DefaultHttpContent(byteBuf.readRetainedSlice(iMin3));
                        this.chunkSize -= (long) iMin3;
                        list.add(defaultHttpContent);
                        if (this.chunkSize != 0) {
                            return;
                        } else {
                            this.currentState = State.READ_CHUNK_DELIMITER;
                        }
                        break;
                    } else {
                        return;
                    }
                case READ_CHUNK_DELIMITER:
                    int iWriterIndex = byteBuf.writerIndex();
                    int i3 = byteBuf.readerIndex();
                    while (true) {
                        if (iWriterIndex > i3) {
                            int i4 = i3 + 1;
                            if (byteBuf.getByte(i3) == 10) {
                                this.currentState = State.READ_CHUNK_SIZE;
                                i3 = i4;
                            } else {
                                i3 = i4;
                            }
                        }
                    }
                    byteBuf.readerIndex(i3);
                    return;
                case READ_CHUNK_FOOTER:
                    LastHttpContent trailingHeaders = readTrailingHeaders(byteBuf);
                    if (trailingHeaders == null) {
                        return;
                    }
                    list.add(trailingHeaders);
                    resetNow();
                    return;
                case BAD_MESSAGE:
                    byteBuf.skipBytes(byteBuf.readableBytes());
                    return;
                case UPGRADED:
                    int i5 = byteBuf.readableBytes();
                    if (i5 > 0) {
                        list.add(byteBuf.readBytes(i5));
                        return;
                    }
                    return;
                default:
                    return;
            }
        } catch (Exception e3) {
            objInvalidChunk = invalidChunk(byteBuf, e3);
        }
    }

    @Override // io.netty.handler.codec.ByteToMessageDecoder
    public void decodeLast(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf, List<Object> list) {
        Object objInvalidMessage;
        super.decodeLast(channelHandlerContext, byteBuf, list);
        if (this.resetRequested) {
            resetNow();
        }
        HttpMessage httpMessage = this.message;
        if (httpMessage != null) {
            boolean zIsTransferEncodingChunked = HttpUtil.isTransferEncodingChunked(httpMessage);
            if (this.currentState == State.READ_VARIABLE_LENGTH_CONTENT && !byteBuf.isReadable() && !zIsTransferEncodingChunked) {
                objInvalidMessage = LastHttpContent.EMPTY_LAST_CONTENT;
            } else {
                if (this.currentState != State.READ_HEADER) {
                    boolean z2 = true;
                    if (!isDecodingRequest() && !zIsTransferEncodingChunked && contentLength() <= 0) {
                        z2 = false;
                    }
                    if (!z2) {
                        list.add(LastHttpContent.EMPTY_LAST_CONTENT);
                    }
                    resetNow();
                    return;
                }
                objInvalidMessage = invalidMessage(Unpooled.EMPTY_BUFFER, new PrematureChannelClosureException("Connection closed before received headers"));
            }
            list.add(objInvalidMessage);
            resetNow();
        }
    }

    public boolean isContentAlwaysEmpty(HttpMessage httpMessage) {
        if (httpMessage instanceof HttpResponse) {
            HttpResponse httpResponse = (HttpResponse) httpMessage;
            int iCode = httpResponse.status().code();
            if (iCode >= 100 && iCode < 200) {
                return (iCode == 101 && !httpResponse.headers().contains(HttpHeaderNames.SEC_WEBSOCKET_ACCEPT) && httpResponse.headers().contains((CharSequence) HttpHeaderNames.UPGRADE, (CharSequence) HttpHeaderValues.WEBSOCKET, true)) ? false : true;
            }
            if (iCode == 204 || iCode == 304) {
                return true;
            }
        }
        return false;
    }

    public abstract boolean isDecodingRequest();

    public boolean isSwitchingToNonHttp1Protocol(HttpResponse httpResponse) {
        if (httpResponse.status().code() != HttpResponseStatus.SWITCHING_PROTOCOLS.code()) {
            return false;
        }
        String str = httpResponse.headers().get(HttpHeaderNames.UPGRADE);
        return str == null || !(str.contains(HttpVersion.HTTP_1_0.text()) || str.contains(HttpVersion.HTTP_1_1.text()));
    }

    public void reset() {
        this.resetRequested = true;
    }

    @Override // io.netty.handler.codec.ByteToMessageDecoder, io.netty.channel.ChannelInboundHandlerAdapter, io.netty.channel.ChannelInboundHandler
    public void userEventTriggered(ChannelHandlerContext channelHandlerContext, Object obj) {
        int iOrdinal;
        if ((obj instanceof HttpExpectationFailedEvent) && ((iOrdinal = this.currentState.ordinal()) == 3 || iOrdinal == 4 || iOrdinal == 5)) {
            reset();
        }
        super.userEventTriggered(channelHandlerContext, obj);
    }
}
