2020import java .net .URI ;
2121import java .net .URISyntaxException ;
2222
23+ import io .netty .channel .ChannelPipeline ;
2324import io .netty .handler .codec .http .HttpHeaderNames ;
2425import io .netty .handler .codec .http .cookie .Cookie ;
26+ import io .netty .handler .ssl .SslHandler ;
2527import reactor .core .publisher .Flux ;
2628import reactor .ipc .netty .http .server .HttpServerRequest ;
2729
@@ -62,6 +64,7 @@ private static URI initUri(HttpServerRequest request) throws URISyntaxException
6264 }
6365
6466 private static URI resolveBaseUrl (HttpServerRequest request ) throws URISyntaxException {
67+ String scheme = getScheme (request );
6568 String header = request .requestHeaders ().get (HttpHeaderNames .HOST );
6669 if (header != null ) {
6770 final int portIndex ;
@@ -73,24 +76,30 @@ private static URI resolveBaseUrl(HttpServerRequest request) throws URISyntaxExc
7376 }
7477 if (portIndex != -1 ) {
7578 try {
76- return new URI (null , null , header .substring (0 , portIndex ),
79+ return new URI (scheme , null , header .substring (0 , portIndex ),
7780 Integer .parseInt (header .substring (portIndex + 1 )), null , null , null );
7881 }
7982 catch (NumberFormatException ex ) {
8083 throw new URISyntaxException (header , "Unable to parse port" , portIndex );
8184 }
8285 }
8386 else {
84- return new URI (null , header , null , null );
87+ return new URI (scheme , header , null , null );
8588 }
8689 }
8790 else {
8891 InetSocketAddress localAddress = (InetSocketAddress ) request .context ().channel ().localAddress ();
89- return new URI (null , null , localAddress .getHostString (),
92+ return new URI (scheme , null , localAddress .getHostString (),
9093 localAddress .getPort (), null , null , null );
9194 }
9295 }
9396
97+ private static String getScheme (HttpServerRequest request ) {
98+ ChannelPipeline pipeline = request .context ().channel ().pipeline ();
99+ boolean ssl = pipeline .get (SslHandler .class ) != null ;
100+ return ssl ? "https" : "http" ;
101+ }
102+
94103 private static HttpHeaders initHeaders (HttpServerRequest channel ) {
95104 HttpHeaders headers = new HttpHeaders ();
96105 for (String name : channel .requestHeaders ().names ()) {
0 commit comments