funky-eyes commented on code in PR #7451: URL: https://github.com/apache/incubator-seata/pull/7451#discussion_r2159148164
########## core/src/main/java/org/apache/seata/core/rpc/netty/http/Http2HttpHandler.java: ########## @@ -0,0 +1,174 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.seata.core.rpc.netty.http; + +import com.fasterxml.jackson.databind.node.ObjectNode; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.Unpooled; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.http.HttpHeaderNames; +import io.netty.handler.codec.http.HttpMethod; +import io.netty.handler.codec.http.HttpResponseStatus; +import io.netty.handler.codec.http.QueryStringDecoder; +import io.netty.handler.codec.http2.DefaultHttp2DataFrame; +import io.netty.handler.codec.http2.DefaultHttp2Headers; +import io.netty.handler.codec.http2.DefaultHttp2HeadersFrame; +import io.netty.handler.codec.http2.Http2DataFrame; +import io.netty.handler.codec.http2.Http2Headers; +import io.netty.handler.codec.http2.Http2HeadersFrame; +import io.netty.handler.codec.http2.Http2StreamFrame; +import org.apache.seata.common.rpc.http.HttpContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.lang.reflect.Method; +import java.nio.charset.StandardCharsets; + +/** + * The http2 http handler. + */ +public class Http2HttpHandler extends BaseHttpChannelHandler<Http2StreamFrame> { + private static final Logger LOGGER = LoggerFactory.getLogger(Http2HttpHandler.class); + private Http2Headers http2Headers; + private ByteBuf bodyBuffer; + private boolean headersEndStream = false; + + @Override + protected void channelRead0(ChannelHandlerContext ctx, Http2StreamFrame msg) throws Exception { + if (bodyBuffer == null) { + bodyBuffer = ctx.alloc().buffer(); + } + try { + if (msg instanceof Http2HeadersFrame) { + Http2HeadersFrame headersFrame = (Http2HeadersFrame) msg; + this.http2Headers = headersFrame.headers(); + headersEndStream = headersFrame.isEndStream(); + if (headersEndStream) { + handleRequest(ctx); + } + } else if (msg instanceof Http2DataFrame) { + Http2DataFrame dataFrame = (Http2DataFrame) msg; + bodyBuffer.writeBytes(dataFrame.content()); + if (dataFrame.isEndStream()) { + handleRequest(ctx); + } + } Review Comment: > Oh, pattern matching is only available starting from JDK 17. With JDK 8, using if-else is probably the best option. 😅 ok -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@seata.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@seata.apache.org For additional commands, e-mail: notifications-h...@seata.apache.org