7070
7171/**
7272 * Creates instances of {@link org.springframework.web.util.UriComponentsBuilder}
73- * by pointing to Spring MVC controllers and {@code @RequestMapping} methods.
73+ * by pointing to {@code @RequestMapping} methods on Spring MVC controllers .
7474 *
75- * <p>The static {@code fromXxx(...)} methods prepare links relative to the
76- * current request as determined by a call to
75+ * <p>There are several groups of methods:
76+ * <ul>
77+ * <li>Static {@code fromXxx(...)} methods to prepare links using information
78+ * from the current request as determined by a call to
7779 * {@link org.springframework.web.servlet.support.ServletUriComponentsBuilder#fromCurrentServletMapping()}.
80+ * <li>Static {@code fromXxx(UriComponentsBuilder,...)} methods can be given
81+ * a baseUrl when operating outside the context of a request.
82+ * <li>Instance-based {@code withXxx(...)} methods where an instance of
83+ * MvcUriComponentsBuilder is created with a baseUrl via
84+ * {@link #relativeTo(org.springframework.web.util.UriComponentsBuilder)}.
85+ * </ul>
7886 *
79- * <p>The static {@code fromXxx(UriComponentsBuilder,...)} methods can be given
80- * the baseUrl when operating outside the context of a request.
81- *
82- * <p>You can also create an MvcUriComponentsBuilder instance with a baseUrl
83- * via {@link #relativeTo(org.springframework.web.util.UriComponentsBuilder)}
84- * and then use the non-static {@code withXxx(...)} method variants.
87+ * <p><strong>Note:</strong> This class extracts and uses values from the headers
88+ * "Forwarded" (<a href="http://tools.ietf.org/html/rfc7239">RFC 7239</a>),
89+ * or "X-Forwarded-Host", "X-Forwarded-Port", and "X-Forwarded-Proto" if
90+ * "Forwarded" is not found, in order to reflect the client-originated protocol
91+ * and address. As an alternative consider using the
92+ * {@link org.springframework.web.filter.ForwardedHeaderFilter} to have such
93+ * headers extracted once and removed, or removed only (without being used).
94+ * See the reference for further information including security considerations.
8595 *
8696 * @author Oliver Gierke
8797 * @author Rossen Stoyanchev
@@ -142,6 +152,8 @@ public static MvcUriComponentsBuilder relativeTo(UriComponentsBuilder baseUrl) {
142152 * Create a {@link UriComponentsBuilder} from the mapping of a controller class
143153 * and current request information including Servlet mapping. If the controller
144154 * contains multiple mappings, only the first one is used.
155+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
156+ * and "X-Forwarded-*" headers if found. See class-level docs.
145157 * @param controllerType the controller to build a URI for
146158 * @return a UriComponentsBuilder instance (never {@code null})
147159 */
@@ -154,6 +166,8 @@ public static UriComponentsBuilder fromController(Class<?> controllerType) {
154166 * {@code UriComponentsBuilder} representing the base URL. This is useful
155167 * when using MvcUriComponentsBuilder outside the context of processing a
156168 * request or to apply a custom baseUrl not matching the current request.
169+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
170+ * and "X-Forwarded-*" headers if found. See class-level docs.
157171 * @param builder the builder for the base URL; the builder will be cloned
158172 * and therefore not modified and may be re-used for further calls.
159173 * @param controllerType the controller to build a URI for
@@ -171,6 +185,8 @@ public static UriComponentsBuilder fromController(@Nullable UriComponentsBuilder
171185 * Create a {@link UriComponentsBuilder} from the mapping of a controller
172186 * method and an array of method argument values. This method delegates
173187 * to {@link #fromMethod(Class, Method, Object...)}.
188+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
189+ * and "X-Forwarded-*" headers if found. See class-level docs.
174190 * @param controllerType the controller
175191 * @param methodName the method name
176192 * @param args the argument values
@@ -190,6 +206,8 @@ public static UriComponentsBuilder fromMethodName(Class<?> controllerType,
190206 * accepts a {@code UriComponentsBuilder} representing the base URL. This is
191207 * useful when using MvcUriComponentsBuilder outside the context of processing
192208 * a request or to apply a custom baseUrl not matching the current request.
209+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
210+ * and "X-Forwarded-*" headers if found. See class-level docs.
193211 * @param builder the builder for the base URL; the builder will be cloned
194212 * and therefore not modified and may be re-used for further calls.
195213 * @param controllerType the controller
@@ -237,6 +255,10 @@ public static UriComponentsBuilder fromMethodName(UriComponentsBuilder builder,
237255 * controller.getAddressesForCountry("US")
238256 * builder = MvcUriComponentsBuilder.fromMethodCall(controller);
239257 * </pre>
258+ *
259+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
260+ * and "X-Forwarded-*" headers if found. See class-level docs.
261+ *
240262 * @param info either the value returned from a "mock" controller
241263 * invocation or the "mock" controller itself after an invocation
242264 * @return a UriComponents instance
@@ -255,6 +277,8 @@ public static UriComponentsBuilder fromMethodCall(Object info) {
255277 * {@code UriComponentsBuilder} representing the base URL. This is useful
256278 * when using MvcUriComponentsBuilder outside the context of processing a
257279 * request or to apply a custom baseUrl not matching the current request.
280+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
281+ * and "X-Forwarded-*" headers if found. See class-level docs.
258282 * @param builder the builder for the base URL; the builder will be cloned
259283 * and therefore not modified and may be re-used for further calls.
260284 * @param info either the value returned from a "mock" controller
@@ -305,6 +329,10 @@ public static UriComponentsBuilder fromMethodCall(UriComponentsBuilder builder,
305329 * </pre>
306330 * <p>Note that it's not necessary to specify all arguments. Only the ones
307331 * required to prepare the URL, mainly {@code @RequestParam} and {@code @PathVariable}).
332+ *
333+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
334+ * and "X-Forwarded-*" headers if found. See class-level docs.
335+ *
308336 * @param mappingName the mapping name
309337 * @return a builder to prepare the URI String
310338 * @throws IllegalArgumentException if the mapping name is not found or
@@ -320,6 +348,8 @@ public static MethodArgumentBuilder fromMappingName(String mappingName) {
320348 * {@code UriComponentsBuilder} representing the base URL. This is useful
321349 * when using MvcUriComponentsBuilder outside the context of processing a
322350 * request or to apply a custom baseUrl not matching the current request.
351+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
352+ * and "X-Forwarded-*" headers if found. See class-level docs.
323353 * @param builder the builder for the base URL; the builder will be cloned
324354 * and therefore not modified and may be re-used for further calls.
325355 * @param name the mapping name
@@ -352,6 +382,8 @@ public static MethodArgumentBuilder fromMappingName(@Nullable UriComponentsBuild
352382 * {@link org.springframework.web.method.support.UriComponentsContributor
353383 * UriComponentsContributor}) while remaining argument values are ignored and
354384 * can be {@code null}.
385+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
386+ * and "X-Forwarded-*" headers if found. See class-level docs.
355387 * @param controllerType the controller type
356388 * @param method the controller method
357389 * @param args argument values for the controller method
@@ -368,6 +400,8 @@ public static UriComponentsBuilder fromMethod(Class<?> controllerType, Method me
368400 * This is useful when using MvcUriComponentsBuilder outside the context of
369401 * processing a request or to apply a custom baseUrl not matching the
370402 * current request.
403+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
404+ * and "X-Forwarded-*" headers if found. See class-level docs.
371405 * @param baseUrl the builder for the base URL; the builder will be cloned
372406 * and therefore not modified and may be re-used for further calls.
373407 * @param controllerType the controller type
@@ -549,6 +583,9 @@ private static WebApplicationContext getWebApplicationContext() {
549583 * <pre class="code">
550584 * MvcUriComponentsBuilder.fromMethodCall(on(FooController.class).getFoo(1)).build();
551585 * </pre>
586+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
587+ * and "X-Forwarded-*" headers if found. See class-level docs.
588+ *
552589 * @param controllerType the target controller
553590 */
554591 public static <T > T on (Class <T > controllerType ) {
@@ -571,6 +608,8 @@ public static <T> T on(Class<T> controllerType) {
571608 * fooController.saveFoo(2, null);
572609 * builder = MvcUriComponentsBuilder.fromMethodCall(fooController);
573610 * </pre>
611+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
612+ * and "X-Forwarded-*" headers if found. See class-level docs.
574613 * @param controllerType the target controller
575614 */
576615 public static <T > T controller (Class <T > controllerType ) {
@@ -626,6 +665,8 @@ private static <T> T initProxy(Class<?> type, ControllerMethodInvocationIntercep
626665 /**
627666 * An alternative to {@link #fromController(Class)} for use with an instance
628667 * of this class created via a call to {@link #relativeTo}.
668+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
669+ * and "X-Forwarded-*" headers if found. See class-level docs.
629670 * @since 4.2
630671 */
631672 public UriComponentsBuilder withController (Class <?> controllerType ) {
@@ -635,6 +676,8 @@ public UriComponentsBuilder withController(Class<?> controllerType) {
635676 /**
636677 * An alternative to {@link #fromMethodName(Class, String, Object...)}} for
637678 * use with an instance of this class created via {@link #relativeTo}.
679+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
680+ * and "X-Forwarded-*" headers if found. See class-level docs.
638681 * @since 4.2
639682 */
640683 public UriComponentsBuilder withMethodName (Class <?> controllerType , String methodName , Object ... args ) {
@@ -644,6 +687,8 @@ public UriComponentsBuilder withMethodName(Class<?> controllerType, String metho
644687 /**
645688 * An alternative to {@link #fromMethodCall(Object)} for use with an instance
646689 * of this class created via {@link #relativeTo}.
690+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
691+ * and "X-Forwarded-*" headers if found. See class-level docs.
647692 * @since 4.2
648693 */
649694 public UriComponentsBuilder withMethodCall (Object invocationInfo ) {
@@ -653,6 +698,8 @@ public UriComponentsBuilder withMethodCall(Object invocationInfo) {
653698 /**
654699 * An alternative to {@link #fromMappingName(String)} for use with an instance
655700 * of this class created via {@link #relativeTo}.
701+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
702+ * and "X-Forwarded-*" headers if found. See class-level docs.
656703 * @since 4.2
657704 */
658705 public MethodArgumentBuilder withMappingName (String mappingName ) {
@@ -662,6 +709,8 @@ public MethodArgumentBuilder withMappingName(String mappingName) {
662709 /**
663710 * An alternative to {@link #fromMethod(Class, Method, Object...)}
664711 * for use with an instance of this class created via {@link #relativeTo}.
712+ * <p><strong>Note:</strong> This method extracts values from "Forwarded"
713+ * and "X-Forwarded-*" headers if found. See class-level docs.
665714 * @since 4.2
666715 */
667716 public UriComponentsBuilder withMethod (Class <?> controllerType , Method method , Object ... args ) {
0 commit comments