1
1
/*
2
- * Copyright 2002-2019 the original author or authors.
2
+ * Copyright 2002-2020 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.
@@ -668,11 +668,14 @@ public void setServerName(String serverName) {
668
668
669
669
@ Override
670
670
public String getServerName () {
671
- String host = getHeader (HttpHeaders .HOST );
671
+ String rawHostHeader = getHeader (HttpHeaders .HOST );
672
+ String host = rawHostHeader ;
672
673
if (host != null ) {
673
674
host = host .trim ();
674
675
if (host .startsWith ("[" )) {
675
- host = host .substring (1 , host .indexOf (']' ));
676
+ int indexOfClosingBracket = host .indexOf (']' );
677
+ Assert .state (indexOfClosingBracket > -1 , () -> "Invalid Host header: " + rawHostHeader );
678
+ host = host .substring (0 , indexOfClosingBracket + 1 );
676
679
}
677
680
else if (host .contains (":" )) {
678
681
host = host .substring (0 , host .indexOf (':' ));
@@ -690,12 +693,15 @@ public void setServerPort(int serverPort) {
690
693
691
694
@ Override
692
695
public int getServerPort () {
693
- String host = getHeader (HttpHeaders .HOST );
696
+ String rawHostHeader = getHeader (HttpHeaders .HOST );
697
+ String host = rawHostHeader ;
694
698
if (host != null ) {
695
699
host = host .trim ();
696
700
int idx ;
697
701
if (host .startsWith ("[" )) {
698
- idx = host .indexOf (':' , host .indexOf (']' ));
702
+ int indexOfClosingBracket = host .indexOf (']' );
703
+ Assert .state (indexOfClosingBracket > -1 , () -> "Invalid Host header: " + rawHostHeader );
704
+ idx = host .indexOf (':' , indexOfClosingBracket );
699
705
}
700
706
else {
701
707
idx = host .indexOf (':' );
0 commit comments