@@ -717,16 +717,7 @@ UriComponentsBuilder adaptFromForwardedHeaders(HttpHeaders headers) {
717
717
String forwardedToUse = StringUtils .tokenizeToStringArray (forwardedHeader , "," )[0 ];
718
718
Matcher matcher = FORWARDED_HOST_PATTERN .matcher (forwardedToUse );
719
719
if (matcher .find ()) {
720
- String hostToUse = matcher .group (1 ).trim ();
721
- int portSeparatorIdx = hostToUse .lastIndexOf (":" );
722
- if (portSeparatorIdx > hostToUse .lastIndexOf ("]" )) {
723
- host (hostToUse .substring (0 , portSeparatorIdx ));
724
- port (Integer .parseInt (hostToUse .substring (portSeparatorIdx + 1 )));
725
- }
726
- else {
727
- host (hostToUse );
728
- port (null );
729
- }
720
+ adaptForwardedHost (matcher .group (1 ).trim ());
730
721
}
731
722
matcher = FORWARDED_PROTO_PATTERN .matcher (forwardedToUse );
732
723
if (matcher .find ()) {
@@ -736,16 +727,7 @@ UriComponentsBuilder adaptFromForwardedHeaders(HttpHeaders headers) {
736
727
else {
737
728
String hostHeader = headers .getFirst ("X-Forwarded-Host" );
738
729
if (StringUtils .hasText (hostHeader )) {
739
- String hostToUse = StringUtils .tokenizeToStringArray (hostHeader , "," )[0 ];
740
- int portSeparatorIdx = hostToUse .lastIndexOf (":" );
741
- if (portSeparatorIdx > hostToUse .lastIndexOf ("]" )) {
742
- host (hostToUse .substring (0 , portSeparatorIdx ));
743
- port (Integer .parseInt (hostToUse .substring (portSeparatorIdx + 1 )));
744
- }
745
- else {
746
- host (hostToUse );
747
- port (null );
748
- }
730
+ adaptForwardedHost (StringUtils .tokenizeToStringArray (hostHeader , "," )[0 ]);
749
731
}
750
732
751
733
String portHeader = headers .getFirst ("X-Forwarded-Port" );
@@ -767,6 +749,18 @@ UriComponentsBuilder adaptFromForwardedHeaders(HttpHeaders headers) {
767
749
return this ;
768
750
}
769
751
752
+ private void adaptForwardedHost (String hostToUse ) {
753
+ int portSeparatorIdx = hostToUse .lastIndexOf (":" );
754
+ if (portSeparatorIdx > hostToUse .lastIndexOf ("]" )) {
755
+ host (hostToUse .substring (0 , portSeparatorIdx ));
756
+ port (Integer .parseInt (hostToUse .substring (portSeparatorIdx + 1 )));
757
+ }
758
+ else {
759
+ host (hostToUse );
760
+ port (null );
761
+ }
762
+ }
763
+
770
764
private void resetHierarchicalComponents () {
771
765
this .userInfo = null ;
772
766
this .host = null ;
0 commit comments