1
1
/*
2
- * Copyright 2002-2022 the original author or authors.
2
+ * Copyright 2002-2023 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -80,6 +80,12 @@ private static URI initUri(HttpServerRequest request) throws URISyntaxException
80
80
81
81
private static URI resolveBaseUrl (HttpServerRequest request ) throws URISyntaxException {
82
82
String scheme = getScheme (request );
83
+
84
+ InetSocketAddress hostAddress = request .hostAddress ();
85
+ if (hostAddress != null ) {
86
+ return new URI (scheme , null , hostAddress .getHostString (), hostAddress .getPort (), null , null , null );
87
+ }
88
+
83
89
CharSequence charSequence = request .requestHeaders ().get (HttpHeaderNames .HOST );
84
90
if (charSequence != null ) {
85
91
String header = charSequence .toString ();
@@ -103,12 +109,8 @@ private static URI resolveBaseUrl(HttpServerRequest request) throws URISyntaxExc
103
109
return new URI (scheme , header , null , null );
104
110
}
105
111
}
106
- else {
107
- InetSocketAddress localAddress = request .hostAddress ();
108
- Assert .state (localAddress != null , "No host address available" );
109
- return new URI (scheme , null , localAddress .getHostString (),
110
- localAddress .getPort (), null , null , null );
111
- }
112
+
113
+ throw new IllegalStateException ("Neither local hostAddress nor HOST header available" );
112
114
}
113
115
114
116
private static String getScheme (HttpServerRequest request ) {
0 commit comments