@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 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.
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.hateoas.mvc;
|
||||
|
||||
import static org.springframework.hateoas.mvc.ForwardedHeader.handleXForwardedSslHeader;
|
||||
import static org.springframework.hateoas.mvc.ForwardedHeader.*;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.experimental.Delegate;
|
||||
@@ -330,7 +330,7 @@ public class ControllerLinkBuilder extends LinkBuilderSupport<ControllerLinkBuil
|
||||
* @return
|
||||
*/
|
||||
private static boolean isSpringAtLeast5_1() {
|
||||
|
||||
|
||||
String versionOfSpringFramework = ApplicationContext.class.getPackage().getImplementationVersion();
|
||||
|
||||
String[] parts = versionOfSpringFramework.split("\\.");
|
||||
@@ -377,7 +377,7 @@ public class ControllerLinkBuilder extends LinkBuilderSupport<ControllerLinkBuil
|
||||
public UriTemplate getMappingAsUriTemplate(Class<?> type, Method method) {
|
||||
|
||||
String mapping = delegate.getMapping(type, method);
|
||||
|
||||
|
||||
return templates.computeIfAbsent(mapping, UriTemplate::new);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
* Copyright 2017-2018 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.
|
||||
@@ -46,8 +46,8 @@ class ForwardedHeader {
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method to pull handling of {@literal X-Forwarded-Ssl} into a class that will be removed when
|
||||
* rebaselined against Spring 5.1
|
||||
* Utility method to pull handling of {@literal X-Forwarded-Ssl} into a class that will be removed when rebaselined
|
||||
* against Spring 5.1
|
||||
*
|
||||
* @param request
|
||||
* @param builder
|
||||
@@ -55,7 +55,8 @@ class ForwardedHeader {
|
||||
* @deprecated No longer needed with Spring 5.1
|
||||
*/
|
||||
@Deprecated
|
||||
public static UriComponentsBuilder handleXForwardedSslHeader(HttpServletRequest request, UriComponentsBuilder builder) {
|
||||
public static UriComponentsBuilder handleXForwardedSslHeader(HttpServletRequest request,
|
||||
UriComponentsBuilder builder) {
|
||||
|
||||
// special case handling for X-Forwarded-Ssl:
|
||||
// apply it, but only if X-Forwarded-Proto is unset.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2013 the original author or authors.
|
||||
* Copyright 2012-2018 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.
|
||||
@@ -34,6 +34,7 @@ import org.springframework.web.filter.ForwardedHeaderFilter;
|
||||
* Utility class to ease testing.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Greg Turnquist
|
||||
*/
|
||||
public class TestUtils {
|
||||
|
||||
@@ -52,13 +53,13 @@ public class TestUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a mechanism to simulate inserting a {@link ForwardedHeaderFilter} into the servlet
|
||||
* filter chain, so {@literal Forwarded} headers are properly inserted into the test web request.
|
||||
* Provide a mechanism to simulate inserting a {@link ForwardedHeaderFilter} into the servlet filter chain, so
|
||||
* {@literal Forwarded} headers are properly inserted into the test web request.
|
||||
*
|
||||
* @see https://jira.spring.io/browse/SPR-16668
|
||||
*/
|
||||
protected void adaptRequestFromForwardedHeaders() {
|
||||
|
||||
|
||||
MockFilterChain chain = new MockFilterChain();
|
||||
try {
|
||||
new ForwardedHeaderFilter().doFilter(this.request, new MockHttpServletResponse(), chain);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2018 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.
|
||||
@@ -435,7 +435,7 @@ public class ControllerLinkBuilderUnitTest extends TestUtils {
|
||||
|
||||
setUp();
|
||||
request.addHeader("X-Forwarded-Proto", proto);
|
||||
|
||||
|
||||
adaptRequestFromForwardedHeaders();
|
||||
|
||||
Link link = linkTo(PersonControllerImpl.class).withSelfRel();
|
||||
@@ -469,7 +469,7 @@ public class ControllerLinkBuilderUnitTest extends TestUtils {
|
||||
|
||||
request.addHeader("X-Forwarded-Proto", "foo");
|
||||
request.addHeader("Forwarded", "proto=bar");
|
||||
|
||||
|
||||
adaptRequestFromForwardedHeaders();
|
||||
|
||||
Link link = linkTo(PersonControllerImpl.class).withSelfRel();
|
||||
@@ -588,8 +588,7 @@ public class ControllerLinkBuilderUnitTest extends TestUtils {
|
||||
@Test
|
||||
public void considersEmptyOptionalMethodParameterOptional() {
|
||||
|
||||
Link link = linkTo(methodOn(ControllerWithMethods.class).methodWithJdk8Optional(Optional.empty()))
|
||||
.withSelfRel();
|
||||
Link link = linkTo(methodOn(ControllerWithMethods.class).methodWithJdk8Optional(Optional.empty())).withSelfRel();
|
||||
|
||||
assertThat(link.isTemplated()).isTrue();
|
||||
assertThat(link.getVariableNames(), contains("value"));
|
||||
|
||||
Reference in New Issue
Block a user