Search in sources :

Example 1 with UPGRADE

use of io.aklivity.zilla.runtime.binding.http.internal.hpack.HpackContext.UPGRADE in project zilla by aklivity.

the class HttpServerFactory method decodeHeaderLine.

private DirectBuffer decodeHeaderLine(HttpServer server, DirectBuffer buffer, int startOfHeadersAt, int startOfLineAt, int endOfLineAt, HttpBeginExFW.Builder httpBeginEx, MutableBoolean hasAuthority, MutableReference<String> connection) {
    DirectBuffer error = null;
    if (endOfLineAt - startOfHeadersAt > maximumHeadersSize) {
        error = ERROR_431_HEADERS_TOO_LARGE;
    } else if (headerLine.reset(new AsciiSequenceView(buffer, startOfLineAt, endOfLineAt - startOfLineAt)).matches()) {
        final String name = headerLine.group("name").toLowerCase();
        final String value = headerLine.group("value");
        switch(name) {
            case "connection":
                connection.ref = value;
                if (server.decoder == decodeUpgraded) {
                    httpBeginEx.headersItem(h -> h.name(HEADER_CONNECTION).value(connection.ref));
                }
                break;
            case "content-length":
                if (server.decoder != decodeHeadersOnly) {
                    error = ERROR_400_BAD_REQUEST;
                } else {
                    final int contentLength = parseInt(value);
                    if (contentLength > 0) {
                        server.decodableContentLength = contentLength;
                        server.decoder = decodeContent;
                    }
                    httpBeginEx.headersItem(h -> h.name(HEADER_CONTENT_LENGTH).value(value));
                }
                break;
            case "host":
                if (!hasAuthority.value) {
                    String authority = (value.indexOf(':') == -1) ? String.format("%s:%s", value, SCHEME_PORTS.get(server.decodeScheme)) : value;
                    httpBeginEx.headersItem(h -> h.name(HEADER_AUTHORITY).value(authority));
                    hasAuthority.value = true;
                }
                break;
            case "http2-settings":
                // TODO: h2c
                break;
            case "transfer-encoding":
                if (server.decoder != decodeHeadersOnly) {
                    error = ERROR_400_BAD_REQUEST;
                } else if (!"chunked".equals(value)) {
                    error = ERROR_501_UNSUPPORTED_TRANSFER_ENCODING;
                } else {
                    server.decoder = decodeChunkHeader;
                    httpBeginEx.headersItem(h -> h.name(HEADER_TRANSFER_ENCODING).value(TRANSFER_ENCODING_CHUNKED));
                }
                break;
            case "upgrade":
                if (server.decoder != decodeHeadersOnly) {
                    error = ERROR_400_BAD_REQUEST;
                } else if ("h2c".equals(value)) {
                // TODO: h2c
                } else {
                    // TODO: wait for 101 first
                    server.decoder = decodeUpgraded;
                    httpBeginEx.headersItem(h -> h.name(HEADER_UPGRADE).value(value));
                    if (connection.ref != null) {
                        httpBeginEx.headersItem(h -> h.name(HEADER_CONNECTION).value(connection.ref));
                    }
                }
                break;
            default:
                httpBeginEx.headersItem(h -> h.name(name).value(value));
                break;
        }
    } else if (buffer.getByte(startOfLineAt) == SPACE_BYTE) {
        error = ERROR_400_BAD_REQUEST_OBSOLETE_LINE_FOLDING;
    } else {
        error = ERROR_400_BAD_REQUEST;
    }
    return error;
}
Also used : MutableDirectBuffer(org.agrona.MutableDirectBuffer) DirectBuffer(org.agrona.DirectBuffer) HttpPolicyConfig(io.aklivity.zilla.runtime.binding.http.internal.config.HttpAccessControlConfig.HttpPolicyConfig) NO_DEBITOR_INDEX(io.aklivity.zilla.runtime.engine.budget.BudgetDebitor.NO_DEBITOR_INDEX) HpackHeaderFieldFW(io.aklivity.zilla.runtime.binding.http.internal.hpack.HpackHeaderFieldFW) HpackStringFW(io.aklivity.zilla.runtime.binding.http.internal.hpack.HpackStringFW) LongSupplier(java.util.function.LongSupplier) BindingHandler(io.aklivity.zilla.runtime.engine.binding.BindingHandler) MessageConsumer(io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) INCREMENTAL_INDEXING(io.aklivity.zilla.runtime.binding.http.internal.hpack.HpackLiteralHeaderFieldFW.LiteralType.INCREMENTAL_INDEXING) Http2SettingsFW(io.aklivity.zilla.runtime.binding.http.internal.codec.Http2SettingsFW) Matcher(java.util.regex.Matcher) Arrays.asList(java.util.Arrays.asList) HttpBinding(io.aklivity.zilla.runtime.binding.http.internal.HttpBinding) Http2ErrorCode(io.aklivity.zilla.runtime.binding.http.internal.codec.Http2ErrorCode) Map(java.util.Map) Http2PingFW(io.aklivity.zilla.runtime.binding.http.internal.codec.Http2PingFW) Array32FW(io.aklivity.zilla.runtime.binding.http.internal.types.Array32FW) UNKNOWN(io.aklivity.zilla.runtime.binding.http.internal.hpack.HpackHeaderFieldFW.HeaderFieldType.UNKNOWN) ProxyInfoFW(io.aklivity.zilla.runtime.binding.http.internal.types.ProxyInfoFW) WindowFW(io.aklivity.zilla.runtime.binding.http.internal.types.stream.WindowFW) EngineContext(io.aklivity.zilla.runtime.engine.EngineContext) BufferPool(io.aklivity.zilla.runtime.engine.buffer.BufferPool) EnumMap(java.util.EnumMap) PROXY_CONNECTION(io.aklivity.zilla.runtime.binding.http.internal.hpack.HpackContext.PROXY_CONNECTION) Http2DataFW(io.aklivity.zilla.runtime.binding.http.internal.codec.Http2DataFW) Set(java.util.Set) Signaler(io.aklivity.zilla.runtime.engine.concurrent.Signaler) EndFW(io.aklivity.zilla.runtime.binding.http.internal.types.stream.EndFW) BindingConfig(io.aklivity.zilla.runtime.engine.config.BindingConfig) BufferUtil.limitOfBytes(io.aklivity.zilla.runtime.binding.http.internal.util.BufferUtil.limitOfBytes) CONNECTION(io.aklivity.zilla.runtime.binding.http.internal.hpack.HpackContext.CONNECTION) Http2ContinuationFW(io.aklivity.zilla.runtime.binding.http.internal.codec.Http2ContinuationFW) AsciiSequenceView(org.agrona.AsciiSequenceView) HttpDataExFW(io.aklivity.zilla.runtime.binding.http.internal.types.stream.HttpDataExFW) LongLongConsumer(org.agrona.collections.LongLongConsumer) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Long2ObjectHashMap(org.agrona.collections.Long2ObjectHashMap) MutableReference(org.agrona.collections.MutableReference) BiConsumer(java.util.function.BiConsumer) MutableInteger(org.agrona.collections.MutableInteger) MutableBoolean(org.agrona.collections.MutableBoolean) VERSION(io.aklivity.zilla.runtime.binding.http.internal.types.ProxySecureInfoType.VERSION) HttpEndExFW(io.aklivity.zilla.runtime.binding.http.internal.types.stream.HttpEndExFW) String16FW(io.aklivity.zilla.runtime.binding.http.internal.types.String16FW) KEEP_ALIVE(io.aklivity.zilla.runtime.binding.http.internal.hpack.HpackContext.KEEP_ALIVE) UPGRADE(io.aklivity.zilla.runtime.binding.http.internal.hpack.HpackContext.UPGRADE) ALPN(io.aklivity.zilla.runtime.binding.http.internal.types.ProxyInfoType.ALPN) HpackHuffman(io.aklivity.zilla.runtime.binding.http.internal.hpack.HpackHuffman) LongUnaryOperator(java.util.function.LongUnaryOperator) Http2PriorityFW(io.aklivity.zilla.runtime.binding.http.internal.codec.Http2PriorityFW) AtomicBuffer(org.agrona.concurrent.AtomicBuffer) BufferUtil.indexOfByte(io.aklivity.zilla.runtime.binding.http.internal.util.BufferUtil.indexOfByte) Http2PushPromiseFW(io.aklivity.zilla.runtime.binding.http.internal.codec.Http2PushPromiseFW) SortedSet(java.util.SortedSet) Http2Setting(io.aklivity.zilla.runtime.binding.http.internal.codec.Http2Setting) BudgetCreditor(io.aklivity.zilla.runtime.engine.budget.BudgetCreditor) WITHOUT_INDEXING(io.aklivity.zilla.runtime.binding.http.internal.hpack.HpackLiteralHeaderFieldFW.LiteralType.WITHOUT_INDEXING) SECURE(io.aklivity.zilla.runtime.binding.http.internal.types.ProxyInfoType.SECURE) LongHashSet(org.agrona.collections.LongHashSet) OctetsFW(io.aklivity.zilla.runtime.binding.http.internal.types.OctetsFW) Flyweight(io.aklivity.zilla.runtime.binding.http.internal.types.Flyweight) URI(java.net.URI) Http2WindowUpdateFW(io.aklivity.zilla.runtime.binding.http.internal.codec.Http2WindowUpdateFW) HttpBindingConfig(io.aklivity.zilla.runtime.binding.http.internal.config.HttpBindingConfig) HttpRouteConfig(io.aklivity.zilla.runtime.binding.http.internal.config.HttpRouteConfig) TRAILERS(io.aklivity.zilla.runtime.binding.http.internal.hpack.HpackContext.TRAILERS) Http2FrameType(io.aklivity.zilla.runtime.binding.http.internal.codec.Http2FrameType) Int2ObjectHashMap(org.agrona.collections.Int2ObjectHashMap) SignalFW(io.aklivity.zilla.runtime.binding.http.internal.types.stream.SignalFW) ExpandableArrayBuffer(org.agrona.ExpandableArrayBuffer) Instant(java.time.Instant) Objects(java.util.Objects) FlushFW(io.aklivity.zilla.runtime.binding.http.internal.types.stream.FlushFW) List(java.util.List) HttpBeginExFW(io.aklivity.zilla.runtime.binding.http.internal.types.stream.HttpBeginExFW) HpackContext(io.aklivity.zilla.runtime.binding.http.internal.hpack.HpackContext) MutableDirectBuffer(org.agrona.MutableDirectBuffer) Pattern(java.util.regex.Pattern) DirectBuffer(org.agrona.DirectBuffer) HttpConfiguration(io.aklivity.zilla.runtime.binding.http.internal.HttpConfiguration) Http2PrefaceFW(io.aklivity.zilla.runtime.binding.http.internal.codec.Http2PrefaceFW) HashMap(java.util.HashMap) BeginFW(io.aklivity.zilla.runtime.binding.http.internal.types.stream.BeginFW) HpackHeaderBlockFW(io.aklivity.zilla.runtime.binding.http.internal.hpack.HpackHeaderBlockFW) HttpAccessControlConfig(io.aklivity.zilla.runtime.binding.http.internal.config.HttpAccessControlConfig) HashSet(java.util.HashSet) DataFW(io.aklivity.zilla.runtime.binding.http.internal.types.stream.DataFW) HttpUtil(io.aklivity.zilla.runtime.binding.http.internal.util.HttpUtil) Http2GoawayFW(io.aklivity.zilla.runtime.binding.http.internal.codec.Http2GoawayFW) HpackLiteralHeaderFieldFW(io.aklivity.zilla.runtime.binding.http.internal.hpack.HpackLiteralHeaderFieldFW) TE(io.aklivity.zilla.runtime.binding.http.internal.hpack.HpackContext.TE) String8FW(io.aklivity.zilla.runtime.binding.http.internal.types.String8FW) ProxyBeginExFW(io.aklivity.zilla.runtime.binding.http.internal.types.stream.ProxyBeginExFW) NO_CREDITOR_INDEX(io.aklivity.zilla.runtime.engine.budget.BudgetCreditor.NO_CREDITOR_INDEX) Character.toUpperCase(java.lang.Character.toUpperCase) Http2HeadersFW(io.aklivity.zilla.runtime.binding.http.internal.codec.Http2HeadersFW) Iterator(java.util.Iterator) LongFunction(java.util.function.LongFunction) Http2FrameInfoFW(io.aklivity.zilla.runtime.binding.http.internal.codec.Http2FrameInfoFW) HttpVersion(io.aklivity.zilla.runtime.binding.http.internal.config.HttpVersion) UTF_8(java.nio.charset.StandardCharsets.UTF_8) AbortFW(io.aklivity.zilla.runtime.binding.http.internal.types.stream.AbortFW) HttpHeaderFW(io.aklivity.zilla.runtime.binding.http.internal.types.HttpHeaderFW) BudgetDebitor(io.aklivity.zilla.runtime.engine.budget.BudgetDebitor) Integer.parseInt(java.lang.Integer.parseInt) US_ASCII(java.nio.charset.StandardCharsets.US_ASCII) Consumer(java.util.function.Consumer) Http2RstStreamFW(io.aklivity.zilla.runtime.binding.http.internal.codec.Http2RstStreamFW) NO_SLOT(io.aklivity.zilla.runtime.engine.buffer.BufferPool.NO_SLOT) ResetFW(io.aklivity.zilla.runtime.binding.http.internal.types.stream.ResetFW) CROSS_ORIGIN(io.aklivity.zilla.runtime.binding.http.internal.config.HttpAccessControlConfig.HttpPolicyConfig.CROSS_ORIGIN) Character.toLowerCase(java.lang.Character.toLowerCase) AsciiSequenceView(org.agrona.AsciiSequenceView)

Aggregations

HttpBinding (io.aklivity.zilla.runtime.binding.http.internal.HttpBinding)1 HttpConfiguration (io.aklivity.zilla.runtime.binding.http.internal.HttpConfiguration)1 Http2ContinuationFW (io.aklivity.zilla.runtime.binding.http.internal.codec.Http2ContinuationFW)1 Http2DataFW (io.aklivity.zilla.runtime.binding.http.internal.codec.Http2DataFW)1 Http2ErrorCode (io.aklivity.zilla.runtime.binding.http.internal.codec.Http2ErrorCode)1 Http2FrameInfoFW (io.aklivity.zilla.runtime.binding.http.internal.codec.Http2FrameInfoFW)1 Http2FrameType (io.aklivity.zilla.runtime.binding.http.internal.codec.Http2FrameType)1 Http2GoawayFW (io.aklivity.zilla.runtime.binding.http.internal.codec.Http2GoawayFW)1 Http2HeadersFW (io.aklivity.zilla.runtime.binding.http.internal.codec.Http2HeadersFW)1 Http2PingFW (io.aklivity.zilla.runtime.binding.http.internal.codec.Http2PingFW)1 Http2PrefaceFW (io.aklivity.zilla.runtime.binding.http.internal.codec.Http2PrefaceFW)1 Http2PriorityFW (io.aklivity.zilla.runtime.binding.http.internal.codec.Http2PriorityFW)1 Http2PushPromiseFW (io.aklivity.zilla.runtime.binding.http.internal.codec.Http2PushPromiseFW)1 Http2RstStreamFW (io.aklivity.zilla.runtime.binding.http.internal.codec.Http2RstStreamFW)1 Http2Setting (io.aklivity.zilla.runtime.binding.http.internal.codec.Http2Setting)1 Http2SettingsFW (io.aklivity.zilla.runtime.binding.http.internal.codec.Http2SettingsFW)1 Http2WindowUpdateFW (io.aklivity.zilla.runtime.binding.http.internal.codec.Http2WindowUpdateFW)1 HttpAccessControlConfig (io.aklivity.zilla.runtime.binding.http.internal.config.HttpAccessControlConfig)1 HttpPolicyConfig (io.aklivity.zilla.runtime.binding.http.internal.config.HttpAccessControlConfig.HttpPolicyConfig)1 CROSS_ORIGIN (io.aklivity.zilla.runtime.binding.http.internal.config.HttpAccessControlConfig.HttpPolicyConfig.CROSS_ORIGIN)1