Cache ServerHttpRequest::getMethod in AbstractServerHttpRequest

This commit ensures that the HttpMethod, exposed through
ServerHttpRequest::getMethod, is cached in AbstractServerHttpRequest so
that potentially expensive HTTP method lookups are only done once.

Closes gh-30139
This commit is contained in:
Arjen Poutsma
2023-03-21 11:29:32 +01:00
parent c27a5687dc
commit 37a4e84450
8 changed files with 62 additions and 62 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 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.
@@ -54,8 +54,6 @@ import org.springframework.web.util.UriComponentsBuilder;
*/
public final class MockServerHttpRequest extends AbstractServerHttpRequest {
private final HttpMethod httpMethod;
private final MultiValueMap<String, HttpCookie> cookies;
@Nullable
@@ -74,8 +72,7 @@ public final class MockServerHttpRequest extends AbstractServerHttpRequest {
@Nullable InetSocketAddress localAddress, @Nullable InetSocketAddress remoteAddress,
@Nullable SslInfo sslInfo, Publisher<? extends DataBuffer> body) {
super(uri, contextPath, headers);
this.httpMethod = httpMethod;
super(httpMethod, uri, contextPath, headers);
this.cookies = cookies;
this.localAddress = localAddress;
this.remoteAddress = remoteAddress;
@@ -84,11 +81,6 @@ public final class MockServerHttpRequest extends AbstractServerHttpRequest {
}
@Override
public HttpMethod getMethod() {
return this.httpMethod;
}
@Override
@Nullable
public InetSocketAddress getLocalAddress() {