@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
/ *
* Copyright 2002 - 2014 the original author or authors .
* Copyright 2002 - 2015 the original author or authors .
*
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
@ -18,11 +18,14 @@ package org.springframework.web.servlet.support;
@@ -18,11 +18,14 @@ package org.springframework.web.servlet.support;
import javax.servlet.http.HttpServletRequest ;
import org.springframework.http.HttpRequest ;
import org.springframework.http.server.ServletServerHttpRequest ;
import org.springframework.util.Assert ;
import org.springframework.util.StringUtils ;
import org.springframework.web.context.request.RequestAttributes ;
import org.springframework.web.context.request.RequestContextHolder ;
import org.springframework.web.context.request.ServletRequestAttributes ;
import org.springframework.web.util.UriComponents ;
import org.springframework.web.util.UriComponentsBuilder ;
import org.springframework.web.util.UrlPathHelper ;
import org.springframework.web.util.WebUtils ;
@ -112,34 +115,11 @@ public class ServletUriComponentsBuilder extends UriComponentsBuilder {
@@ -112,34 +115,11 @@ public class ServletUriComponentsBuilder extends UriComponentsBuilder {
* Initialize a builder with a scheme , host , and port ( but not path and query ) .
* /
private static ServletUriComponentsBuilder initFromRequest ( HttpServletRequest request ) {
String scheme = request . getScheme ( ) ;
String host = request . getServerName ( ) ;
int port = request . getServerPort ( ) ;
String hostHeader = request . getHeader ( "X-Forwarded-Host" ) ;
if ( StringUtils . hasText ( hostHeader ) ) {
String [ ] hosts = StringUtils . commaDelimitedListToStringArray ( hostHeader ) ;
String hostToUse = hosts [ 0 ] ;
if ( hostToUse . contains ( ":" ) ) {
String [ ] hostAndPort = StringUtils . split ( hostToUse , ":" ) ;
host = hostAndPort [ 0 ] ;
port = Integer . parseInt ( hostAndPort [ 1 ] ) ;
}
else {
host = hostToUse ;
port = - 1 ;
}
}
String portHeader = request . getHeader ( "X-Forwarded-Port" ) ;
if ( StringUtils . hasText ( portHeader ) ) {
port = Integer . parseInt ( portHeader ) ;
}
String protocolHeader = request . getHeader ( "X-Forwarded-Proto" ) ;
if ( StringUtils . hasText ( protocolHeader ) ) {
scheme = protocolHeader ;
}
HttpRequest httpRequest = new ServletServerHttpRequest ( request ) ;
UriComponents uriComponents = UriComponentsBuilder . fromHttpRequest ( httpRequest ) . build ( ) ;
String scheme = uriComponents . getScheme ( ) ;
String host = uriComponents . getHost ( ) ;
int port = uriComponents . getPort ( ) ;
ServletUriComponentsBuilder builder = new ServletUriComponentsBuilder ( ) ;
builder . scheme ( scheme ) ;