You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2018/10/09 13:56:31 UTC

[GitHub] azagrebin commented on a change in pull request #6796: [FLINK-10075] Redirect non-ssl requests to https url if ssl is enabled

azagrebin commented on a change in pull request #6796: [FLINK-10075] Redirect non-ssl requests to https url if ssl is enabled
URL: https://github.com/apache/flink/pull/6796#discussion_r223711070
 
 

 ##########
 File path: flink-runtime/src/main/java/org/apache/flink/runtime/net/RedirectingSslHandler.java
 ##########
 @@ -0,0 +1,115 @@
+/*
+ * 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.flink.runtime.net;
+
+import org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf;
+import org.apache.flink.shaded.netty4.io.netty.buffer.Unpooled;
+import org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandler;
+import org.apache.flink.shaded.netty4.io.netty.channel.ChannelHandlerContext;
+import org.apache.flink.shaded.netty4.io.netty.channel.ChannelInboundHandlerAdapter;
+import org.apache.flink.shaded.netty4.io.netty.handler.codec.ByteToMessageDecoder;
+import org.apache.flink.shaded.netty4.io.netty.handler.codec.http.DefaultFullHttpResponse;
+import org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpResponse;
+import org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpRequest;
+import org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpRequestDecoder;
+import org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseEncoder;
+import org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus;
+import org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpVersion;
+import org.apache.flink.shaded.netty4.io.netty.handler.ssl.SslHandler;
+import org.apache.flink.shaded.netty4.io.netty.util.ReferenceCountUtil;
+
+import org.jboss.netty.handler.codec.http.HttpHeaders;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.net.InetSocketAddress;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+
+/** SSL handler which automatically redirects Non-SSL requests to SSL address. */
+public class RedirectingSslHandler extends ByteToMessageDecoder {
+	protected final Logger log = LoggerFactory.getLogger(getClass());
+
+	/** the length of the ssl record header (in bytes). */
+	private static final int SSL_RECORD_HEADER_LENGTH = 5;
+
+	private final String confRedirectBaseUrl;
+	private final CompletableFuture<String> redirectBaseUrl;
+	private final SSLEngineFactory sslEngineFactory;
+
+	public RedirectingSslHandler(
+		String confRedirectHost,
+		CompletableFuture<String> redirectBaseUrl,
+		SSLEngineFactory sslEngineFactory) {
+		this.confRedirectBaseUrl = "https://" + confRedirectHost + ":";
+		this.redirectBaseUrl = redirectBaseUrl;
+		this.sslEngineFactory = sslEngineFactory;
+	}
+
+	@Override
+	protected void decode(ChannelHandlerContext context, ByteBuf in, List<Object> out) {
+		if (in.readableBytes() < SSL_RECORD_HEADER_LENGTH) {
 
 Review comment:
   we can treat it as non ssl case instead as it would be if ssl is disabled

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services