Search in sources :

Example 1 with BeginFW

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

the class HttpClientFactory method doBegin.

private void doBegin(MessageConsumer receiver, long routeId, long streamId, long sequence, long acknowledge, int maximum, long traceId, long authorization, long affinity, Flyweight extension) {
    final BeginFW begin = beginRW.wrap(writeBuffer, 0, writeBuffer.capacity()).routeId(routeId).streamId(streamId).sequence(sequence).acknowledge(acknowledge).maximum(maximum).traceId(traceId).authorization(authorization).affinity(affinity).extension(extension.buffer(), extension.offset(), extension.sizeof()).build();
    receiver.accept(begin.typeId(), begin.buffer(), begin.offset(), begin.sizeof());
}
Also used : BeginFW(io.aklivity.zilla.runtime.binding.http.internal.types.stream.BeginFW)

Example 2 with BeginFW

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

the class HttpServerFactory method newStream.

private MessageConsumer newStream(MessageConsumer sender, long routeId, long streamId, long sequence, long acknowledge, int maximum, long traceId, long authorization, long affinity, Flyweight extension) {
    final BeginFW begin = beginRW.wrap(writeBuffer, 0, writeBuffer.capacity()).routeId(routeId).streamId(streamId).sequence(sequence).acknowledge(acknowledge).maximum(maximum).traceId(traceId).authorization(authorization).affinity(affinity).extension(extension.buffer(), extension.offset(), extension.sizeof()).build();
    MessageConsumer receiver = streamFactory.newStream(begin.typeId(), begin.buffer(), begin.offset(), begin.sizeof(), sender);
    receiver.accept(begin.typeId(), begin.buffer(), begin.offset(), begin.sizeof());
    return receiver;
}
Also used : MessageConsumer(io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer) BeginFW(io.aklivity.zilla.runtime.binding.http.internal.types.stream.BeginFW)

Example 3 with BeginFW

use of io.aklivity.zilla.runtime.binding.http.internal.types.stream.BeginFW 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)

Example 4 with BeginFW

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

the class HttpServerFactory method doBegin.

private void doBegin(MessageConsumer receiver, long routeId, long streamId, long sequence, long acknowledge, int maximum, long traceId, long authorization, long affinity, Flyweight extension) {
    final BeginFW begin = beginRW.wrap(writeBuffer, 0, writeBuffer.capacity()).routeId(routeId).streamId(streamId).sequence(sequence).acknowledge(acknowledge).maximum(maximum).traceId(traceId).authorization(authorization).affinity(affinity).extension(extension.buffer(), extension.offset(), extension.sizeof()).build();
    receiver.accept(begin.typeId(), begin.buffer(), begin.offset(), begin.sizeof());
}
Also used : BeginFW(io.aklivity.zilla.runtime.binding.http.internal.types.stream.BeginFW)

Example 5 with BeginFW

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

the class HttpClientFactory method newStream.

@Override
public MessageConsumer newStream(int msgTypeId, DirectBuffer buffer, int index, int length, MessageConsumer application) {
    final BeginFW begin = beginRO.wrap(buffer, index, index + length);
    final long routeId = begin.routeId();
    final long authorization = begin.authorization();
    final HttpBeginExFW beginEx = begin.extension().get(beginExRO::tryWrap);
    final HttpBindingConfig binding = bindings.get(routeId);
    HttpRouteConfig route = null;
    if (binding != null) {
        // TODO: avoid object creation
        final Map<String, String> headers = beginEx != null ? asHeadersMap(beginEx.headers()) : EMPTY_HEADERS;
        route = binding.resolve(authorization, headers::get);
    }
    MessageConsumer newStream = null;
    if (route != null) {
        final long resolvedId = route.id;
        final Map<String8FW, String16FW> overrides = binding.options != null && binding.options.overrides != null ? binding.options.overrides : EMPTY_OVERRIDES;
        final HttpClientPool clientPool = clientPools.computeIfAbsent(resolvedId, HttpClientPool::new);
        newStream = clientPool.newStream(application, begin, overrides);
    }
    return newStream;
}
Also used : MessageConsumer(io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer) BeginFW(io.aklivity.zilla.runtime.binding.http.internal.types.stream.BeginFW) HttpRouteConfig(io.aklivity.zilla.runtime.binding.http.internal.config.HttpRouteConfig) HttpBeginExFW(io.aklivity.zilla.runtime.binding.http.internal.types.stream.HttpBeginExFW) String8FW(io.aklivity.zilla.runtime.binding.http.internal.types.String8FW) HttpBindingConfig(io.aklivity.zilla.runtime.binding.http.internal.config.HttpBindingConfig) String16FW(io.aklivity.zilla.runtime.binding.http.internal.types.String16FW)

Aggregations

BeginFW (io.aklivity.zilla.runtime.binding.http.internal.types.stream.BeginFW)6 MessageConsumer (io.aklivity.zilla.runtime.engine.binding.function.MessageConsumer)4 HttpBindingConfig (io.aklivity.zilla.runtime.binding.http.internal.config.HttpBindingConfig)2 HttpRouteConfig (io.aklivity.zilla.runtime.binding.http.internal.config.HttpRouteConfig)1 HttpVersion (io.aklivity.zilla.runtime.binding.http.internal.config.HttpVersion)1 ProxyInfoFW (io.aklivity.zilla.runtime.binding.http.internal.types.ProxyInfoFW)1 String16FW (io.aklivity.zilla.runtime.binding.http.internal.types.String16FW)1 String8FW (io.aklivity.zilla.runtime.binding.http.internal.types.String8FW)1 HttpBeginExFW (io.aklivity.zilla.runtime.binding.http.internal.types.stream.HttpBeginExFW)1 ProxyBeginExFW (io.aklivity.zilla.runtime.binding.http.internal.types.stream.ProxyBeginExFW)1