diff --git a/src/main/java/org/springframework/hateoas/mvc/ControllerLinkBuilder.java b/src/main/java/org/springframework/hateoas/mvc/ControllerLinkBuilder.java index 3d55f406..5148a1db 100755 --- a/src/main/java/org/springframework/hateoas/mvc/ControllerLinkBuilder.java +++ b/src/main/java/org/springframework/hateoas/mvc/ControllerLinkBuilder.java @@ -15,8 +15,6 @@ */ package org.springframework.hateoas.mvc; -import static org.springframework.hateoas.mvc.ForwardedHeader.*; - import lombok.RequiredArgsConstructor; import lombok.experimental.Delegate; @@ -27,7 +25,6 @@ import java.util.Map; import javax.servlet.http.HttpServletRequest; -import org.springframework.context.ApplicationContext; import org.springframework.hateoas.Affordance; import org.springframework.hateoas.Link; import org.springframework.hateoas.TemplateVariables; @@ -296,31 +293,7 @@ public class ControllerLinkBuilder extends LinkBuilderSupport= 5 && minorVersion >= 1 || majorVersion > 5; + return ServletUriComponentsBuilder.fromServletMapping(getCurrentRequest()); } /** diff --git a/src/main/java/org/springframework/hateoas/mvc/ForwardedHeader.java b/src/main/java/org/springframework/hateoas/mvc/ForwardedHeader.java deleted file mode 100644 index 761e0b1e..00000000 --- a/src/main/java/org/springframework/hateoas/mvc/ForwardedHeader.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.hateoas.mvc; - -import static org.springframework.util.StringUtils.*; - -import java.util.Arrays; -import java.util.Collections; -import java.util.Map; -import java.util.stream.Collectors; - -import javax.servlet.http.HttpServletRequest; - -import org.springframework.util.Assert; -import org.springframework.util.StringUtils; -import org.springframework.web.util.UriComponentsBuilder; - -/** - * Value object to partially implement the {@literal Forwarded} header defined in RFC 7239. - * - * @author Oliver Gierke - * @see http://tools.ietf.org/html/rfc7239 - * @deprecated In Spring 5.1, all Forwarded headers will by handled by Spring MVC. - */ -@Deprecated -class ForwardedHeader { - - private static final ForwardedHeader NO_HEADER = new ForwardedHeader(Collections.emptyMap()); - private final Map elements; - - private ForwardedHeader(Map elements) { - this.elements = elements; - } - - /** - * 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 - * @return - * @deprecated No longer needed with Spring 5.1 - */ - @Deprecated - 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. - - String forwardedSsl = request.getHeader("X-Forwarded-Ssl"); - ForwardedHeader forwarded = ForwardedHeader.of(request.getHeader("Forwarded")); - String proto = hasText(forwarded.getProto()) ? forwarded.getProto() : request.getHeader("X-Forwarded-Proto"); - - if (!hasText(proto) && hasText(forwardedSsl) && forwardedSsl.equalsIgnoreCase("on")) { - builder.scheme("https"); - } - - return builder; - - } - - /** - * Creates a new {@link ForwardedHeader} from the given source. - * - * @param source can be {@literal null}. - * @return - */ - static ForwardedHeader of(String source) { - - if (!StringUtils.hasText(source)) { - return NO_HEADER; - } - - Map elements = Arrays.stream(source.split(";")) // - .map(part -> part.split("=")) // - .filter(keyValue -> keyValue.length == 2) // - .collect(Collectors.toMap(it -> it[0].trim(), it -> it[1].trim())); - - Assert.isTrue(!elements.isEmpty(), "At least one forwarded element needs to be present!"); - - return new ForwardedHeader(elements); - } - - /** - * Returns the value defined for the {@code proto} parameter of the header. - * - * @return - */ - String getProto() { - return elements.get("proto"); - } - - /** - * Returns the value defined for the {@code host} parameter of the header. - * - * @return - */ - String getHost() { - return elements.get("host"); - } -} diff --git a/src/test/java/org/springframework/hateoas/mvc/ForwardedHeaderUnitTest.java b/src/test/java/org/springframework/hateoas/mvc/ForwardedHeaderUnitTest.java deleted file mode 100755 index b3f5923a..00000000 --- a/src/test/java/org/springframework/hateoas/mvc/ForwardedHeaderUnitTest.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2014-2019 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.hateoas.mvc; - -import static org.assertj.core.api.Assertions.*; - -import org.junit.Test; - -/** - * Unit tests for {@link ForwardedHeader}. - * - * @author Oliver Gierke - */ -@SuppressWarnings("deprecation") -public class ForwardedHeaderUnitTest { - - /** - * @see #257 - */ - @Test - public void detectsProtoValue() { - assertThat(ForwardedHeader.of("for=192.0.2.60;proto=http").getProto()).isEqualTo("http"); - } - - /** - * @see #257 - */ - @Test - public void detectsHostValue() { - assertThat(ForwardedHeader.of("host=localhost;proto=http").getHost()).isEqualTo("localhost"); - } - - /** - * @see #257 - */ - @Test - public void returnsNullObjectForNullSource() { - - ForwardedHeader header = ForwardedHeader.of(null); - - assertThat(header).isNotNull(); - assertThat(header.getHost()).isNull(); - assertThat(header.getProto()).isNull(); - } -}