Skip to content

Commit

Permalink
Prefer servicetalk HttpScheme
Browse files Browse the repository at this point in the history
  • Loading branch information
0x1306e6d committed May 23, 2024
1 parent 620f8e6 commit 6d3d576
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
import io.servicetalk.http.api.HttpRequestMetaData;
import io.servicetalk.http.api.HttpRequestMethod;
import io.servicetalk.http.api.HttpResponseStatus;
import io.servicetalk.http.api.HttpScheme;
import io.servicetalk.transport.api.ConnectionObserver.StreamObserver;
import io.servicetalk.transport.netty.internal.CloseHandler;
import io.servicetalk.transport.netty.internal.DefaultNettyConnection.CancelWriteUserEvent;
import io.servicetalk.transport.netty.internal.DefaultNettyConnection.ContinueUserEvent;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
import io.netty.handler.codec.http.HttpScheme;
import io.netty.handler.codec.http2.Http2DataFrame;
import io.netty.handler.codec.http2.Http2Headers;
import io.netty.handler.codec.http2.Http2HeadersFrame;
Expand Down Expand Up @@ -63,7 +63,7 @@ final class H2ToStH1ClientDuplexHandler extends AbstractH2DuplexHandler {
H2ToStH1ClientDuplexHandler(boolean sslEnabled, BufferAllocator allocator, HttpHeadersFactory headersFactory,
CloseHandler closeHandler, StreamObserver observer) {
super(allocator, headersFactory, closeHandler, observer);
this.scheme = sslEnabled ? HttpScheme.HTTPS : HttpScheme.HTTP;
this.scheme = sslEnabled ? HttpScheme.https() : HttpScheme.http();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.servicetalk.http.netty;

import io.servicetalk.http.api.BlockingHttpClient;
import io.servicetalk.http.api.HttpScheme;
import io.servicetalk.http.api.SingleAddressHttpClientBuilder;
import io.servicetalk.http.netty.H2PriorKnowledgeFeatureParityTest.EchoHttp2Handler;
import io.servicetalk.tcp.netty.internal.TcpServerConfig;
Expand All @@ -32,7 +33,6 @@
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup;
import io.netty.handler.codec.http.HttpScheme;
import io.netty.handler.codec.http2.Http2FrameCodecBuilder;
import io.netty.handler.codec.http2.Http2Headers;
import io.netty.handler.codec.http2.Http2HeadersFrame;
Expand All @@ -47,8 +47,6 @@
import java.net.InetSocketAddress;
import javax.annotation.Nullable;

import static io.netty.handler.codec.http.HttpScheme.HTTP;
import static io.netty.handler.codec.http.HttpScheme.HTTPS;
import static io.servicetalk.http.api.HttpResponseStatus.OK;
import static io.servicetalk.http.netty.BuilderUtils.newClientBuilder;
import static io.servicetalk.http.netty.HttpProtocol.HTTP_1;
Expand Down Expand Up @@ -111,7 +109,8 @@ protected void initChannel(final Channel parentChannel) {
@Override
protected void initChannel(final Http2StreamChannel streamChannel) {
streamChannel.pipeline()
.addLast(new SchemeValidatorHandler(sslContext != null ? HTTPS : HTTP));
.addLast(new SchemeValidatorHandler(
sslContext != null ? HttpScheme.https() : HttpScheme.http()));
streamChannel.pipeline().addLast(new EchoHttp2Handler());
}
}));
Expand Down Expand Up @@ -158,7 +157,7 @@ private SchemeValidatorHandler(final HttpScheme expectedScheme) {
public void channelRead(final ChannelHandlerContext ctx, final Object msg) {
if (msg instanceof Http2HeadersFrame) {
Http2Headers headers = ((Http2HeadersFrame) msg).headers();
if (!expectedScheme.name().equals(headers.scheme())) {
if (!expectedScheme.name().contentEquals(headers.scheme())) {
throw new IllegalArgumentException("Unexpected :scheme received: " + headers.scheme() +
", expected: " + expectedScheme);
}
Expand Down

0 comments on commit 6d3d576

Please sign in to comment.