Use existing context path in DefaultServerRequestBuilder

Closes gh-28820
This commit is contained in:
Arjen Poutsma
2022-07-14 14:54:37 +02:00
parent bf63309d05
commit f145b53fc8
3 changed files with 31 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2022 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.
@@ -16,6 +16,7 @@
package org.springframework.web.reactive.function.server;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import org.junit.jupiter.api.Test;
@@ -56,8 +57,11 @@ public class DefaultServerRequestBuilderTests {
.map(s -> s.getBytes(StandardCharsets.UTF_8))
.map(DefaultDataBufferFactory.sharedInstance::wrap);
URI uri = URI.create("https://example2.com/foo/bar");
ServerRequest result = ServerRequest.from(other)
.method(HttpMethod.HEAD)
.uri(uri)
.contextPath("/foo")
.headers(httpHeaders -> httpHeaders.set("foo", "baar"))
.cookies(cookies -> cookies.set("baz", ResponseCookie.from("baz", "quux").build()))
.attribute("attr2", "value2")
@@ -66,6 +70,9 @@ public class DefaultServerRequestBuilderTests {
.build();
assertThat(result.method()).isEqualTo(HttpMethod.HEAD);
assertThat(result.uri()).isEqualTo(uri);
assertThat(result.requestPath().pathWithinApplication().value()).isEqualTo("/bar");
assertThat(result.requestPath().contextPath().value()).isEqualTo("/foo");
assertThat(result.headers().asHttpHeaders()).hasSize(1);
assertThat(result.headers().asHttpHeaders().getFirst("foo")).isEqualTo("baar");
assertThat(result.cookies()).hasSize(1);