// 
// Decompiled by Procyon v0.6.0
// 

package io.netty.handler.codec.http;

import io.netty.buffer.Unpooled;
import io.netty.util.AsciiString;

public class HttpRequestDecoder extends HttpObjectDecoder
{
    private static final AsciiString Accept;
    private static final AsciiString Host;
    private static final AsciiString Connection;
    private static final AsciiString ContentType;
    private static final AsciiString ContentLength;
    private static final int GET_AS_INT = 5522759;
    private static final int POST_AS_INT = 1414745936;
    private static final long HTTP_1_1_AS_LONG = 3543824036068086856L;
    private static final long HTTP_1_0_AS_LONG = 3471766442030158920L;
    private static final int HOST_AS_INT = 1953722184;
    private static final long CONNECTION_AS_LONG_0 = 7598807758576447299L;
    private static final short CONNECTION_AS_SHORT_1 = 28271;
    private static final long CONTENT_AS_LONG = 3275364211029339971L;
    private static final int TYPE_AS_INT = 1701869908;
    private static final long LENGTH_AS_LONG = 114849160783180L;
    private static final long ACCEPT_AS_LONG = 128026086171457L;
    
    public HttpRequestDecoder() {
    }
    
    public HttpRequestDecoder(final int maxInitialLineLength, final int maxHeaderSize, final int maxChunkSize) {
        this(new HttpDecoderConfig().setMaxInitialLineLength(maxInitialLineLength).setMaxHeaderSize(maxHeaderSize).setMaxChunkSize(maxChunkSize));
    }
    
    @Deprecated
    public HttpRequestDecoder(final int maxInitialLineLength, final int maxHeaderSize, final int maxChunkSize, final boolean validateHeaders) {
        super(maxInitialLineLength, maxHeaderSize, maxChunkSize, true, validateHeaders);
    }
    
    @Deprecated
    public HttpRequestDecoder(final int maxInitialLineLength, final int maxHeaderSize, final int maxChunkSize, final boolean validateHeaders, final int initialBufferSize) {
        super(maxInitialLineLength, maxHeaderSize, maxChunkSize, true, validateHeaders, initialBufferSize);
    }
    
    @Deprecated
    public HttpRequestDecoder(final int maxInitialLineLength, final int maxHeaderSize, final int maxChunkSize, final boolean validateHeaders, final int initialBufferSize, final boolean allowDuplicateContentLengths) {
        super(maxInitialLineLength, maxHeaderSize, maxChunkSize, true, validateHeaders, initialBufferSize, allowDuplicateContentLengths);
    }
    
    @Deprecated
    public HttpRequestDecoder(final int maxInitialLineLength, final int maxHeaderSize, final int maxChunkSize, final boolean validateHeaders, final int initialBufferSize, final boolean allowDuplicateContentLengths, final boolean allowPartialChunks) {
        super(maxInitialLineLength, maxHeaderSize, maxChunkSize, true, validateHeaders, initialBufferSize, allowDuplicateContentLengths, allowPartialChunks);
    }
    
    public HttpRequestDecoder(final HttpDecoderConfig config) {
        super(config);
    }
    
    @Override
    protected HttpMessage createMessage(final String[] initialLine) throws Exception {
        return new DefaultHttpRequest(HttpVersion.valueOf(initialLine[2], true), HttpMethod.valueOf(initialLine[0]), initialLine[1], this.headersFactory);
    }
    
    @Override
    protected AsciiString splitHeaderName(final byte[] sb, final int start, final int length) {
        final byte firstChar = sb[start];
        if (firstChar == 72) {
            if (length == 4 && isHost(sb, start)) {
                return HttpRequestDecoder.Host;
            }
        }
        else if (firstChar == 65) {
            if (length == 6 && isAccept(sb, start)) {
                return HttpRequestDecoder.Accept;
            }
        }
        else if (firstChar == 67) {
            if (length == 10) {
                if (isConnection(sb, start)) {
                    return HttpRequestDecoder.Connection;
                }
            }
            else if (length == 12) {
                if (isContentType(sb, start)) {
                    return HttpRequestDecoder.ContentType;
                }
            }
            else if (length == 14 && isContentLength(sb, start)) {
                return HttpRequestDecoder.ContentLength;
            }
        }
        return super.splitHeaderName(sb, start, length);
    }
    
    private static boolean isAccept(final byte[] sb, final int start) {
        final long maybeAccept = (long)(sb[start] | sb[start + 1] << 8 | sb[start + 2] << 16 | sb[start + 3] << 24) | (long)sb[start + 4] << 32 | (long)sb[start + 5] << 40;
        return maybeAccept == 128026086171457L;
    }
    
    private static boolean isHost(final byte[] sb, final int start) {
        final int maybeHost = sb[start] | sb[start + 1] << 8 | sb[start + 2] << 16 | sb[start + 3] << 24;
        return maybeHost == 1953722184;
    }
    
    private static boolean isConnection(final byte[] sb, final int start) {
        final long maybeConnecti = (long)(sb[start] | sb[start + 1] << 8 | sb[start + 2] << 16 | sb[start + 3] << 24) | (long)sb[start + 4] << 32 | (long)sb[start + 5] << 40 | (long)sb[start + 6] << 48 | (long)sb[start + 7] << 56;
        if (maybeConnecti != 7598807758576447299L) {
            return false;
        }
        final short maybeOn = (short)(sb[start + 8] | sb[start + 9] << 8);
        return maybeOn == 28271;
    }
    
    private static boolean isContentType(final byte[] sb, final int start) {
        final long maybeContent = (long)(sb[start] | sb[start + 1] << 8 | sb[start + 2] << 16 | sb[start + 3] << 24) | (long)sb[start + 4] << 32 | (long)sb[start + 5] << 40 | (long)sb[start + 6] << 48 | (long)sb[start + 7] << 56;
        if (maybeContent != 3275364211029339971L) {
            return false;
        }
        final int maybeType = sb[start + 8] | sb[start + 9] << 8 | sb[start + 10] << 16 | sb[start + 11] << 24;
        return maybeType == 1701869908;
    }
    
    private static boolean isContentLength(final byte[] sb, final int start) {
        final long maybeContent = (long)(sb[start] | sb[start + 1] << 8 | sb[start + 2] << 16 | sb[start + 3] << 24) | (long)sb[start + 4] << 32 | (long)sb[start + 5] << 40 | (long)sb[start + 6] << 48 | (long)sb[start + 7] << 56;
        if (maybeContent != 3275364211029339971L) {
            return false;
        }
        final long maybeLength = (long)(sb[start + 8] | sb[start + 9] << 8 | sb[start + 10] << 16 | sb[start + 11] << 24) | (long)sb[start + 12] << 32 | (long)sb[start + 13] << 40;
        return maybeLength == 114849160783180L;
    }
    
    private static boolean isGetMethod(final byte[] sb, final int start) {
        final int maybeGet = sb[start] | sb[start + 1] << 8 | sb[start + 2] << 16;
        return maybeGet == 5522759;
    }
    
    private static boolean isPostMethod(final byte[] sb, final int start) {
        final int maybePost = sb[start] | sb[start + 1] << 8 | sb[start + 2] << 16 | sb[start + 3] << 24;
        return maybePost == 1414745936;
    }
    
    @Override
    protected String splitFirstWordInitialLine(final byte[] sb, final int start, final int length) {
        if (length == 3) {
            if (isGetMethod(sb, start)) {
                return HttpMethod.GET.name();
            }
        }
        else if (length == 4 && isPostMethod(sb, start)) {
            return HttpMethod.POST.name();
        }
        return super.splitFirstWordInitialLine(sb, start, length);
    }
    
    @Override
    protected String splitThirdWordInitialLine(final byte[] sb, final int start, final int length) {
        if (length == 8) {
            final long maybeHttp1_x = (long)(sb[start] | sb[start + 1] << 8 | sb[start + 2] << 16 | sb[start + 3] << 24) | (long)sb[start + 4] << 32 | (long)sb[start + 5] << 40 | (long)sb[start + 6] << 48 | (long)sb[start + 7] << 56;
            if (maybeHttp1_x == 3543824036068086856L) {
                return "HTTP/1.1";
            }
            if (maybeHttp1_x == 3471766442030158920L) {
                return "HTTP/1.0";
            }
        }
        return super.splitThirdWordInitialLine(sb, start, length);
    }
    
    @Override
    protected HttpMessage createInvalidMessage() {
        return new DefaultFullHttpRequest(HttpVersion.HTTP_1_0, HttpMethod.GET, "/bad-request", Unpooled.buffer(0), this.headersFactory, this.trailersFactory);
    }
    
    @Override
    protected boolean isDecodingRequest() {
        return true;
    }
    
    @Override
    protected boolean isContentAlwaysEmpty(final HttpMessage msg) {
        return msg.getClass() != DefaultHttpRequest.class && super.isContentAlwaysEmpty(msg);
    }
    
    static {
        Accept = AsciiString.cached("Accept");
        Host = AsciiString.cached("Host");
        Connection = AsciiString.cached("Connection");
        ContentType = AsciiString.cached("Content-Type");
        ContentLength = AsciiString.cached("Content-Length");
    }
}
