Removed attributes() from Request
Removes attributes() method from Request, as it exposes a mutable map.
This commit is contained in:
@@ -86,11 +86,6 @@ class DefaultRequest implements Request {
|
||||
return this.exchange.getAttribute(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> attributes() {
|
||||
return this.exchange.getAttributes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> queryParams(String name) {
|
||||
List<String> queryParams = request().getQueryParams().get(name);
|
||||
@@ -107,6 +102,10 @@ class DefaultRequest implements Request {
|
||||
return this.exchange.getRequest();
|
||||
}
|
||||
|
||||
ServerWebExchange exchange() {
|
||||
return this.exchange;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private class DefaultHeaders implements Headers {
|
||||
|
||||
@@ -77,11 +77,6 @@ public interface Request {
|
||||
*/
|
||||
<T> Optional<T> attribute(String name);
|
||||
|
||||
/**
|
||||
* Return a mutable map of attributes for this request.
|
||||
*/
|
||||
Map<String, Object> attributes();
|
||||
|
||||
/**
|
||||
* Return the first query parameter with the given name, if present.
|
||||
* @param name the parameter name
|
||||
@@ -168,7 +163,7 @@ public interface Request {
|
||||
List<String> header(String headerName);
|
||||
|
||||
/**
|
||||
* Return the headers as a "live" {@link HttpHeaders} instance.
|
||||
* Return the headers as a {@link HttpHeaders} instance.
|
||||
*/
|
||||
HttpHeaders asHttpHeaders();
|
||||
|
||||
|
||||
@@ -246,8 +246,11 @@ public abstract class RequestPredicates {
|
||||
public boolean test(Request request) {
|
||||
String path = request.path();
|
||||
if (this.pathMatcher.match(this.pattern, path)) {
|
||||
Map<String, String> uriTemplateVariables = this.pathMatcher.extractUriTemplateVariables(this.pattern, path);
|
||||
request.attributes().put(Router.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVariables);
|
||||
if (request instanceof DefaultRequest) {
|
||||
DefaultRequest defaultRequest = (DefaultRequest) request;
|
||||
Map<String, String> uriTemplateVariables = this.pathMatcher.extractUriTemplateVariables(this.pattern, path);
|
||||
defaultRequest.exchange().getAttributes().put(Router.URI_TEMPLATE_VARIABLES_ATTRIBUTE, uriTemplateVariables);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -95,11 +95,6 @@ public class RequestWrapper implements Request {
|
||||
return this.request.attribute(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> attributes() {
|
||||
return this.request.attributes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> queryParam(String name) {
|
||||
return this.request.queryParam(name);
|
||||
|
||||
@@ -22,7 +22,6 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
@@ -94,11 +93,10 @@ public class DefaultRequestTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void attributes() throws Exception {
|
||||
Map<String, Object> attributes = new LinkedHashMap<>();
|
||||
when(mockExchange.getAttributes()).thenReturn(attributes);
|
||||
public void attribute() throws Exception {
|
||||
when(mockExchange.getAttribute("foo")).thenReturn(Optional.of("bar"));
|
||||
|
||||
assertEquals(attributes, defaultRequest.attributes());
|
||||
assertEquals(Optional.of("bar"), defaultRequest.attribute("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -103,11 +103,6 @@ public class MockRequest implements Request {
|
||||
return Optional.ofNullable((T) this.attributes.get(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> attributes() {
|
||||
return this.attributes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> queryParams(String name) {
|
||||
return Collections.unmodifiableList(this.queryParams.get(name));
|
||||
|
||||
@@ -102,14 +102,6 @@ public class RequestWrapperTests {
|
||||
assertEquals(Optional.of(value), wrapper.attribute(name));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void attributes() throws Exception {
|
||||
Map<String, Object> attributes = Collections.singletonMap("foo", "bar");
|
||||
when(mockRequest.attributes()).thenReturn(attributes);
|
||||
|
||||
assertSame(attributes, wrapper.attributes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryParam() throws Exception {
|
||||
String name = "foo";
|
||||
|
||||
Reference in New Issue
Block a user