Search in sources :

Example 1 with ProxyInfoFW

use of io.aklivity.zilla.runtime.binding.http.internal.types.ProxyInfoFW in project zilla by aklivity.

the class HttpServerFactory method newStream.

@Override
public MessageConsumer newStream(int msgTypeId, DirectBuffer buffer, int index, int length, MessageConsumer network) {
    final BeginFW begin = beginRO.wrap(buffer, index, index + length);
    final long routeId = begin.routeId();
    HttpBindingConfig binding = bindings.get(routeId);
    MessageConsumer newStream = null;
    if (binding != null) {
        final long initialId = begin.streamId();
        final long affinity = begin.affinity();
        HttpVersion version = null;
        boolean secure = false;
        ProxyBeginExFW beginEx = begin.extension().get(proxyBeginExRO::tryWrap);
        if (beginEx != null && beginEx.typeId() == proxyTypeId) {
            Array32FW<ProxyInfoFW> infos = beginEx.infos();
            ProxyInfoFW alpn = infos.matchFirst(i -> i.kind() == ALPN);
            secure = infos.matchFirst(i -> i.kind() == SECURE && i.secure().kind() == VERSION) != null;
            if (secure && alpn != null) {
                version = HttpVersion.of(alpn.alpn().asString());
            }
        }
        SortedSet<HttpVersion> supportedVersions = binding.versions();
        if (version == null && !supportedVersions.isEmpty()) {
            // defaults to HTTP/1.1 if supported
            version = supportedVersions.first();
        }
        if (supportedVersions.contains(version)) {
            switch(version) {
                case HTTP_1_1:
                    final boolean upgrade = !secure && supportedVersions.contains(HttpVersion.HTTP_2);
                    final HttpServer http11 = new HttpServer(binding, network, routeId, initialId, affinity, secure, upgrade);
                    newStream = upgrade ? http11::onNetworkUpgradeable : http11::onNetwork;
                    break;
                case HTTP_2:
                    final Http2Server http2 = new Http2Server(binding, network, routeId, initialId, affinity);
                    newStream = http2::onNetwork;
                    break;
            }
        }
    }
    return newStream;
}
Also used : MessageConsumer(io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer) ProxyInfoFW(io.aklivity.zilla.runtime.binding.http.internal.types.ProxyInfoFW) BeginFW(io.aklivity.zilla.runtime.binding.http.internal.types.stream.BeginFW) ProxyBeginExFW(io.aklivity.zilla.runtime.binding.http.internal.types.stream.ProxyBeginExFW) HttpBindingConfig(io.aklivity.zilla.runtime.binding.http.internal.config.HttpBindingConfig) HttpVersion(io.aklivity.zilla.runtime.binding.http.internal.config.HttpVersion)

Aggregations

HttpBindingConfig (io.aklivity.zilla.runtime.binding.http.internal.config.HttpBindingConfig)1 HttpVersion (io.aklivity.zilla.runtime.binding.http.internal.config.HttpVersion)1 ProxyInfoFW (io.aklivity.zilla.runtime.binding.http.internal.types.ProxyInfoFW)1 BeginFW (io.aklivity.zilla.runtime.binding.http.internal.types.stream.BeginFW)1 ProxyBeginExFW (io.aklivity.zilla.runtime.binding.http.internal.types.stream.ProxyBeginExFW)1 MessageConsumer (io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer)1