55 */
66package io .jooby ;
77
8- import io .jooby .exception .RegistryException ;
9- import io .jooby .exception .TypeMismatchException ;
10- import io .jooby .internal .HashValue ;
11- import io .jooby .internal .MissingValue ;
12- import io .jooby .internal .SingleValue ;
13- import io .jooby .internal .UrlParser ;
14- import io .jooby .internal .ValueConverters ;
15- import org .slf4j .Logger ;
8+ import static java .util .Optional .ofNullable ;
169
17- import javax .annotation .Nonnull ;
18- import javax .annotation .Nullable ;
1910import java .io .FileInputStream ;
2011import java .io .IOException ;
2112import java .io .InputStream ;
3324import java .util .Map ;
3425import java .util .Optional ;
3526
27+ import javax .annotation .Nonnull ;
28+ import javax .annotation .Nullable ;
29+
30+ import org .slf4j .Logger ;
31+
32+ import io .jooby .exception .RegistryException ;
33+ import io .jooby .exception .TypeMismatchException ;
34+ import io .jooby .internal .HashValue ;
35+ import io .jooby .internal .MissingValue ;
36+ import io .jooby .internal .SingleValue ;
37+ import io .jooby .internal .UrlParser ;
38+ import io .jooby .internal .ValueConverters ;
39+
3640/***
3741 * Like {@link Context} but with couple of default methods.
3842 *
@@ -270,7 +274,10 @@ public interface DefaultContext extends Context {
270274 ? header ("X-Forwarded-Host" ).toOptional ()
271275 : Optional .empty ();
272276 String value = header
273- .orElseGet (() -> header ("Host" ).value (getServerHost () + ":" + getServerPort ()));
277+ .orElseGet (() ->
278+ ofNullable (header ("Host" ).valueOrNull ())
279+ .orElseGet (() -> getServerHost () + ":" + getServerPort ())
280+ );
274281 int i = value .indexOf (',' );
275282 String host = i > 0 ? value .substring (0 , i ).trim () : value ;
276283 if (host .startsWith ("[" ) && host .endsWith ("]" )) {
@@ -286,7 +293,10 @@ public interface DefaultContext extends Context {
286293
287294 @ Override default int getServerPort () {
288295 ServerOptions options = getRouter ().getServerOptions ();
289- return isSecure () ? options .getSecurePort () : options .getPort ();
296+ return isSecure ()
297+ // Buggy proxy where it report a https scheme but there is no HTTPS configured option
298+ ? ofNullable (options .getSecurePort ()).orElse (options .getPort ())
299+ : options .getPort ();
290300 }
291301
292302 @ Override default int getPort () {
0 commit comments