Skip to content

Commit

Permalink
Merge pull request #5422 from eclipse-vertx/deprecations-for-removal
Browse files Browse the repository at this point in the history
Deprecations for removal
  • Loading branch information
vietj authored Dec 17, 2024
2 parents e85c42c + 1f649bc commit b4433e7
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 104 deletions.
2 changes: 1 addition & 1 deletion vertx-core/src/main/asciidoc/http.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ to arbitrary places on your filesystem. See <<Security notes, security notes>> f
==== Handling cookies

You use {@link io.vertx.core.http.HttpServerRequest#getCookie(String)} to retrieve
a cookie by name, or use {@link io.vertx.core.http.HttpServerRequest#cookieMap()} to retrieve all the cookies.
a cookie by name, or use {@link io.vertx.core.http.HttpServerRequest#cookies()} to retrieve all the cookies.

To remove a cookie, use {@link io.vertx.core.http.HttpServerResponse#removeCookie(String)}.

Expand Down
9 changes: 0 additions & 9 deletions vertx-core/src/main/java/io/vertx/core/http/HttpHeaders.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import io.vertx.codegen.annotations.VertxGen;
import io.vertx.core.MultiMap;
import io.vertx.core.http.impl.headers.HeadersMultiMap;
import io.vertx.core.impl.SysProps;

/**
* Contains a bunch of useful HTTP headers stuff:
Expand All @@ -35,14 +34,6 @@
@VertxGen
public interface HttpHeaders {

/** JVM system property that disables HTTP headers validation, don't use this in production. */
@Deprecated
String DISABLE_HTTP_HEADERS_VALIDATION_PROP_NAME = SysProps.DISABLE_HTTP_HEADERS_VALIDATION.name;

/** Constant that disables HTTP headers validation, this is a constant so the JIT can eliminate validation code. */
@Deprecated
boolean DISABLE_HTTP_HEADERS_VALIDATION = SysProps.DISABLE_HTTP_HEADERS_VALIDATION.getBoolean();

/**
* Accept header name
*/
Expand Down
17 changes: 0 additions & 17 deletions vertx-core/src/main/java/io/vertx/core/http/HttpServerRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

import javax.net.ssl.SSLSession;
import java.util.*;
import java.util.stream.Collectors;

/**
* Represents a server-side HTTP request.
Expand Down Expand Up @@ -476,22 +475,6 @@ default int cookieCount() {
return cookies().size();
}

/**
* @deprecated the implementation made a wrong assumption that cookies could be identified only by their name. The RFC
* states that the tuple of {@code <name, domain, path>} is the unique identifier.
*
* When more than one cookie has the same name, the map will hold that lost one to be parsed and any previously parsed
* value will be silently overwritten.
*
* @return a map of all the cookies.
*/
@Deprecated
default Map<String, Cookie> cookieMap() {
return cookies()
.stream()
.collect(Collectors.toMap(Cookie::getName, cookie -> cookie));
}

/**
* Returns a read only set of parsed cookies that match the given name, or an empty set. Several cookies may share the
* same name but have different keys. A cookie is unique by its {@code <name, domain, path>} tuple.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,21 +405,21 @@ default Future<Void> sendFile(String filename, long offset) {
int streamId();

/**
* Like {@link #push(HttpMethod, String, String, MultiMap)} with no headers.
* Like {@link #push(HttpMethod, HostAndPort, String, MultiMap)} with no headers.
*/
default Future<HttpServerResponse> push(HttpMethod method, String host, String path) {
return push(method, host, path, (MultiMap) null);
default Future<HttpServerResponse> push(HttpMethod method, HostAndPort authority, String path) {
return push(method, authority, path, null);
}

/**
* Like {@link #push(HttpMethod, String, String, MultiMap)} with the host copied from the current request.
* Like {@link #push(HttpMethod, HostAndPort, String, MultiMap)} with the host copied from the current request.
*/
default Future<HttpServerResponse> push(HttpMethod method, String path, MultiMap headers) {
return push(method, (HostAndPort) null, path, headers);
return push(method, null, path, headers);
}

/**
* Like {@link #push(HttpMethod, String, String, MultiMap)} with the host copied from the current request.
* Like {@link #push(HttpMethod, HostAndPort, String, MultiMap)} with the host copied from the current request.
*/
default Future<HttpServerResponse> push(HttpMethod method, String path) {
return push(method, null, path);
Expand All @@ -444,27 +444,6 @@ default Future<HttpServerResponse> push(HttpMethod method, String path) {
*/
Future<HttpServerResponse> push(HttpMethod method, HostAndPort authority, String path, MultiMap headers);

/**
* Push a response to the client.<p/>
*
* The {@code handler} will be notified with a <i>success</i> when the push can be sent and with
* a <i>failure</i> when the client has disabled push or reset the push before it has been sent.<p/>
*
* The {@code handler} may be queued if the client has reduced the maximum number of streams the server can push
* concurrently.<p/>
*
* Push can be sent only for peer initiated streams and if the response is not ended.
*
* @param method the method of the promised request
* @param host the host of the promised request
* @param path the path of the promised request
* @param headers the headers of the promised request
* @return a future notified when the response can be written
* @deprecated instead use {@link #push(HttpMethod, HostAndPort, String, MultiMap)}
*/
@Deprecated
Future<HttpServerResponse> push(HttpMethod method, String host, String path, MultiMap headers);

/**
* Reset this HTTP/2 stream with the error code {@code 0}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -708,11 +708,6 @@ public Future<HttpServerResponse> push(HttpMethod method, HostAndPort authority,
return context.failedFuture("HTTP/1 does not support response push");
}

@Override
public Future<HttpServerResponse> push(HttpMethod method, String host, String path, MultiMap headers) {
return context.failedFuture("HTTP/1 does not support response push");
}

@Override
public Future<Void> writeCustomFrame(int type, int flags, Buffer payload) {
return context.failedFuture("HTTP/1 does not support custom frames");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -628,26 +628,6 @@ public Future<HttpServerResponse> push(HttpMethod method, HostAndPort authority,
return promise.future();
}

@Override
public Future<HttpServerResponse> push(HttpMethod method, String authority, String path, MultiMap headers) {
if (push) {
throw new IllegalStateException("A push response cannot promise another push");
}
HostAndPort hostAndPort = null;
if (authority != null) {
hostAndPort = HostAndPort.parseAuthority(authority, -1);
}
if (hostAndPort == null) {
hostAndPort = stream.authority;
}
synchronized (conn) {
checkValid();
}
Promise<HttpServerResponse> promise = stream.context.promise();
conn.sendPush(stream.id(), hostAndPort, method, headers, path, stream.priority(), promise);
return promise.future();
}

@Override
public HttpServerResponse setStreamPriority(StreamPriority priority) {
stream.updatePriority(priority);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.vertx.core.http.HttpVersion;
import io.vertx.core.internal.ContextInternal;
import io.vertx.core.internal.PromiseInternal;
import io.vertx.core.internal.http.HttpHeadersInternal;
import io.vertx.core.net.*;
import io.vertx.core.internal.net.NetClientInternal;
import io.vertx.core.net.impl.NetSocketImpl;
Expand Down Expand Up @@ -195,7 +196,7 @@ private void applyHttp1xConnectionOptions(ChannelPipeline pipeline) {
options.getMaxHeaderSize(),
options.getMaxChunkSize(),
false,
!HttpHeaders.DISABLE_HTTP_HEADERS_VALIDATION,
!HttpHeadersInternal.DISABLE_HTTP_HEADERS_VALIDATION,
options.getDecoderInitialBufferSize()));
if (options.isDecompressionSupported()) {
pipeline.addLast("inflater", new HttpContentDecompressor(false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
package io.vertx.core.http.impl;

import io.netty.handler.codec.http.*;
import io.vertx.core.http.HttpHeaders;
import io.vertx.core.http.HttpServerOptions;
import io.vertx.core.http.impl.headers.HeadersMultiMap;
import io.vertx.core.internal.http.HttpHeadersInternal;

/**
* A request decoder using {@link HeadersMultiMap} which is faster than {@code DefaultHttpHeaders} used by the super class.
Expand All @@ -25,7 +25,7 @@ public VertxHttpRequestDecoder(HttpServerOptions options) {
options.getMaxInitialLineLength(),
options.getMaxHeaderSize(),
options.getMaxChunkSize(),
!HttpHeaders.DISABLE_HTTP_HEADERS_VALIDATION,
!HttpHeadersInternal.DISABLE_HTTP_HEADERS_VALIDATION,
options.getDecoderInitialBufferSize());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import io.netty.util.CharsetUtil;
import io.vertx.core.MultiMap;
import io.vertx.core.http.impl.HttpUtils;
import io.vertx.core.internal.http.HttpHeadersInternal;

import java.util.AbstractMap;
import java.util.Arrays;
Expand Down Expand Up @@ -60,7 +61,7 @@ private static CharSequence toValidCharSequence(Object value) {
static final BiConsumer<CharSequence, CharSequence> HTTP_VALIDATOR;

static {
if (!io.vertx.core.http.HttpHeaders.DISABLE_HTTP_HEADERS_VALIDATION) {
if (!HttpHeadersInternal.DISABLE_HTTP_HEADERS_VALIDATION) {
HTTP_VALIDATOR = HttpUtils::validateHeader;
} else {
HTTP_VALIDATOR = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import io.netty.handler.codec.http2.Http2Headers;
import io.vertx.core.MultiMap;
import io.vertx.core.http.impl.HttpUtils;
import io.vertx.core.internal.http.HttpHeadersInternal;

import java.util.AbstractList;
import java.util.Iterator;
Expand Down Expand Up @@ -93,7 +94,7 @@ public Set<String> names() {

@Override
public MultiMap add(String name, String value) {
if (!io.vertx.core.http.HttpHeaders.DISABLE_HTTP_HEADERS_VALIDATION) {
if (!HttpHeadersInternal.DISABLE_HTTP_HEADERS_VALIDATION) {
HttpUtils.validateHeader(name, value);
}
headers.add(HttpUtils.toLowerCase(name), value);
Expand All @@ -102,7 +103,7 @@ public MultiMap add(String name, String value) {

@Override
public MultiMap add(String name, Iterable<String> values) {
if (!io.vertx.core.http.HttpHeaders.DISABLE_HTTP_HEADERS_VALIDATION) {
if (!HttpHeadersInternal.DISABLE_HTTP_HEADERS_VALIDATION) {
HttpUtils.validateHeader(name, values);
}
headers.add(HttpUtils.toLowerCase(name), values);
Expand All @@ -127,7 +128,7 @@ public MultiMap addAll(Map<String, String> map) {

@Override
public MultiMap set(String name, String value) {
if (!io.vertx.core.http.HttpHeaders.DISABLE_HTTP_HEADERS_VALIDATION) {
if (!HttpHeadersInternal.DISABLE_HTTP_HEADERS_VALIDATION) {
HttpUtils.validateHeader(name, value);
}
name = (String) HttpUtils.toLowerCase(name);
Expand All @@ -141,7 +142,7 @@ public MultiMap set(String name, String value) {

@Override
public MultiMap set(String name, Iterable<String> values) {
if (!io.vertx.core.http.HttpHeaders.DISABLE_HTTP_HEADERS_VALIDATION) {
if (!HttpHeadersInternal.DISABLE_HTTP_HEADERS_VALIDATION) {
HttpUtils.validateHeader(name, values);
}
headers.set(HttpUtils.toLowerCase(name), values);
Expand Down Expand Up @@ -242,7 +243,7 @@ public boolean contains(CharSequence name, CharSequence value, boolean caseInsen

@Override
public MultiMap add(CharSequence name, CharSequence value) {
if (!io.vertx.core.http.HttpHeaders.DISABLE_HTTP_HEADERS_VALIDATION) {
if (!HttpHeadersInternal.DISABLE_HTTP_HEADERS_VALIDATION) {
HttpUtils.validateHeader(name, value);
}
headers.add(HttpUtils.toLowerCase(name), value);
Expand All @@ -251,7 +252,7 @@ public MultiMap add(CharSequence name, CharSequence value) {

@Override
public MultiMap add(CharSequence name, Iterable<CharSequence> values) {
if (!io.vertx.core.http.HttpHeaders.DISABLE_HTTP_HEADERS_VALIDATION) {
if (!HttpHeadersInternal.DISABLE_HTTP_HEADERS_VALIDATION) {
HttpUtils.validateHeader(name, values);
}
headers.add(HttpUtils.toLowerCase(name), values);
Expand All @@ -260,7 +261,7 @@ public MultiMap add(CharSequence name, Iterable<CharSequence> values) {

@Override
public MultiMap set(CharSequence name, CharSequence value) {
if (!io.vertx.core.http.HttpHeaders.DISABLE_HTTP_HEADERS_VALIDATION) {
if (!HttpHeadersInternal.DISABLE_HTTP_HEADERS_VALIDATION) {
HttpUtils.validateHeader(name, value);
}
name = HttpUtils.toLowerCase(name);
Expand All @@ -274,7 +275,7 @@ public MultiMap set(CharSequence name, CharSequence value) {

@Override
public MultiMap set(CharSequence name, Iterable<CharSequence> values) {
if (!io.vertx.core.http.HttpHeaders.DISABLE_HTTP_HEADERS_VALIDATION) {
if (!HttpHeadersInternal.DISABLE_HTTP_HEADERS_VALIDATION) {
HttpUtils.validateHeader(name, values);
}
headers.set(HttpUtils.toLowerCase(name), values);
Expand Down
4 changes: 3 additions & 1 deletion vertx-core/src/main/java/io/vertx/core/impl/SysProps.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*/
package io.vertx.core.impl;

import io.vertx.core.internal.http.HttpHeadersInternal;

import java.io.File;

/**
Expand All @@ -20,7 +22,7 @@
public enum SysProps {

/**
* Duplicate of {@link io.vertx.core.http.HttpHeaders#DISABLE_HTTP_HEADERS_VALIDATION}
* Duplicate of {@link HttpHeadersInternal#DISABLE_HTTP_HEADERS_VALIDATION}
*/
DISABLE_HTTP_HEADERS_VALIDATION("vertx.disableHttpHeadersValidation"),

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,21 @@
import io.vertx.core.http.HttpHeaders;
import io.vertx.core.http.impl.headers.HeadersAdaptor;
import io.vertx.core.http.impl.headers.Http2HeadersAdaptor;
import io.vertx.core.impl.SysProps;

/**
* HTTP multimap implementations.
*/
public interface HttpHeadersInternal extends HttpHeaders {

/** JVM system property that disables HTTP headers validation, don't use this in production. */
@Deprecated
String DISABLE_HTTP_HEADERS_VALIDATION_PROP_NAME = SysProps.DISABLE_HTTP_HEADERS_VALIDATION.name;

/** Constant that disables HTTP headers validation, this is a constant so the JIT can eliminate validation code. */
@Deprecated
boolean DISABLE_HTTP_HEADERS_VALIDATION = SysProps.DISABLE_HTTP_HEADERS_VALIDATION.getBoolean();

/**
* @return a multimap wrapping Netty HTTP {code header} instance
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import io.vertx.core.http.impl.Http1xOrH2CHandler;
import io.vertx.core.http.impl.HttpUtils;
import io.vertx.core.impl.Utils;
import io.vertx.core.net.HostAndPort;
import io.vertx.core.streams.ReadStream;
import io.vertx.core.streams.WriteStream;
import io.vertx.test.core.DetectFileDescriptorLeaks;
Expand Down Expand Up @@ -1099,7 +1100,7 @@ public void testPushPromiseNoAuthority() throws Exception {
@Test
public void testPushPromiseOverrideAuthority() throws Exception {
testPushPromise(GET("/").authority("whatever.com"), (resp, handler ) -> {
resp.push(HttpMethod.GET, "override.com", "/wibble").onComplete(handler);
resp.push(HttpMethod.GET, HostAndPort.authority("override.com"), "/wibble").onComplete(handler);
}, headers -> {
assertEquals("GET", headers.method().toString());
assertEquals("https", headers.scheme().toString());
Expand Down
20 changes: 9 additions & 11 deletions vertx-core/src/test/java/io/vertx/tests/http/HttpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5893,16 +5893,15 @@ public void testSimpleCookie() throws Exception {
public void testGetCookies() throws Exception {
testCookies("foo=bar; wibble=blibble; plop=flop", req -> {
assertEquals(3, req.cookieCount());
Map<String, Cookie> cookies = req.cookieMap();
assertTrue(cookies.containsKey("foo"));
assertTrue(cookies.containsKey("wibble"));
assertTrue(cookies.containsKey("plop"));
Set<Cookie> cookies = req.cookies();
assertNotNull(req.getCookie("foo"));
assertNotNull(req.getCookie("wibble"));
assertNotNull(req.getCookie("plop"));
Cookie removed = req.response().removeCookie("foo");
cookies = req.cookieMap();
// removed cookies, need to be sent back with an expiration date
assertTrue(cookies.containsKey("foo"));
assertTrue(cookies.containsKey("wibble"));
assertTrue(cookies.containsKey("plop"));
assertNotNull(req.getCookie("foo"));
assertNotNull(req.getCookie("wibble"));
assertNotNull(req.getCookie("plop"));
req.response().end();
}, resp -> {
List<String> cookies = resp.headers().getAll("set-cookie");
Expand Down Expand Up @@ -6154,9 +6153,8 @@ public void testReplaceCookie() throws Exception {
testCookies("XSRF-TOKEN=c359b44aef83415", req -> {
assertEquals(1, req.cookieCount());
req.response().addCookie(Cookie.cookie("XSRF-TOKEN", "88533580000c314").setPath("/"));
Map<String, Cookie> deprecatedMap = req.cookieMap();
assertFalse(((ServerCookie) deprecatedMap.get("XSRF-TOKEN")).isFromUserAgent());
assertEquals("/", deprecatedMap.get("XSRF-TOKEN").getPath());
assertFalse(((ServerCookie) req.getCookie("XSRF-TOKEN")).isFromUserAgent());
assertEquals("/", req.getCookie("XSRF-TOKEN").getPath());
req.response().end();
}, resp -> {
List<String> cookies = resp.headers().getAll("set-cookie");
Expand Down

0 comments on commit b4433e7

Please sign in to comment.