Switch to Reactor Netty 2 snapshots
Update to Reactor BOM 2022.0.0-SNAPSHOT. Process package changes. Adapt to new `HttpHeaders` API. Adapt to new cookies API. See gh-29247
This commit is contained in:
committed by
rstoyanchev
parent
1b1682eacd
commit
b5adae2086
@@ -17,13 +17,17 @@
|
||||
package org.springframework.http.client.reactive;
|
||||
|
||||
import java.util.AbstractSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Spliterator;
|
||||
import java.util.Spliterators;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
import io.netty5.handler.codec.http.HttpHeaders;
|
||||
import io.netty5.handler.codec.http.headers.HttpHeaders;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -52,7 +56,8 @@ class Netty5HeadersAdapter implements MultiValueMap<String, String> {
|
||||
@Override
|
||||
@Nullable
|
||||
public String getFirst(String key) {
|
||||
return this.headers.get(key);
|
||||
CharSequence value = this.headers.get(key);
|
||||
return value != null ? value.toString() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -87,12 +92,11 @@ class Netty5HeadersAdapter implements MultiValueMap<String, String> {
|
||||
@Override
|
||||
public Map<String, String> toSingleValueMap() {
|
||||
Map<String, String> singleValueMap = CollectionUtils.newLinkedHashMap(this.headers.size());
|
||||
this.headers.entries()
|
||||
.forEach(entry -> {
|
||||
if (!singleValueMap.containsKey(entry.getKey())) {
|
||||
singleValueMap.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
});
|
||||
this.headers.forEach(entry -> {
|
||||
if (!singleValueMap.containsKey(entry.getKey())) {
|
||||
singleValueMap.put(entry.getKey().toString(), entry.getValue().toString());
|
||||
}
|
||||
});
|
||||
return singleValueMap;
|
||||
}
|
||||
|
||||
@@ -114,7 +118,8 @@ class Netty5HeadersAdapter implements MultiValueMap<String, String> {
|
||||
@Override
|
||||
public boolean containsValue(Object value) {
|
||||
return (value instanceof String &&
|
||||
this.headers.entries().stream()
|
||||
StreamSupport.stream(
|
||||
Spliterators.spliteratorUnknownSize(this.headers.iterator(), Spliterator.ORDERED), false)
|
||||
.anyMatch(entry -> value.equals(entry.getValue())));
|
||||
}
|
||||
|
||||
@@ -122,7 +127,7 @@ class Netty5HeadersAdapter implements MultiValueMap<String, String> {
|
||||
@Nullable
|
||||
public List<String> get(Object key) {
|
||||
if (containsKey(key)) {
|
||||
return this.headers.getAll((String) key);
|
||||
return getAll(this.headers.valuesIterator((CharSequence) key));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -130,7 +135,7 @@ class Netty5HeadersAdapter implements MultiValueMap<String, String> {
|
||||
@Nullable
|
||||
@Override
|
||||
public List<String> put(String key, @Nullable List<String> value) {
|
||||
List<String> previousValues = this.headers.getAll(key);
|
||||
List<String> previousValues = getAll(this.headers.valuesIterator(key));
|
||||
this.headers.set(key, value);
|
||||
return previousValues;
|
||||
}
|
||||
@@ -139,7 +144,7 @@ class Netty5HeadersAdapter implements MultiValueMap<String, String> {
|
||||
@Override
|
||||
public List<String> remove(Object key) {
|
||||
if (key instanceof String headerName) {
|
||||
List<String> previousValues = this.headers.getAll(headerName);
|
||||
List<String> previousValues = getAll(this.headers.valuesIterator(headerName));
|
||||
this.headers.remove(headerName);
|
||||
return previousValues;
|
||||
}
|
||||
@@ -164,7 +169,7 @@ class Netty5HeadersAdapter implements MultiValueMap<String, String> {
|
||||
@Override
|
||||
public Collection<List<String>> values() {
|
||||
return this.headers.names().stream()
|
||||
.map(this.headers::getAll).toList();
|
||||
.map(key -> getAll(this.headers.valuesIterator(key))).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -189,9 +194,22 @@ class Netty5HeadersAdapter implements MultiValueMap<String, String> {
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
private static List<String> getAll(Iterator<CharSequence> valuesIterator) {
|
||||
if (!valuesIterator.hasNext()) {
|
||||
return null;
|
||||
}
|
||||
List<String> result = new ArrayList<>();
|
||||
while (valuesIterator.hasNext()) {
|
||||
result.add(valuesIterator.next().toString());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private class EntryIterator implements Iterator<Entry<String, List<String>>> {
|
||||
|
||||
private final Iterator<String> names = headers.names().iterator();
|
||||
private final Iterator<CharSequence> names = headers.names().iterator();
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
@@ -207,25 +225,30 @@ class Netty5HeadersAdapter implements MultiValueMap<String, String> {
|
||||
|
||||
private class HeaderEntry implements Entry<String, List<String>> {
|
||||
|
||||
private final String key;
|
||||
private final CharSequence key;
|
||||
|
||||
HeaderEntry(String key) {
|
||||
HeaderEntry(CharSequence key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return this.key;
|
||||
return this.key.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getValue() {
|
||||
return headers.getAll(this.key);
|
||||
List<String> result = new ArrayList<>();
|
||||
Iterator<CharSequence> valuesIterator = headers.valuesIterator(this.key);
|
||||
while (valuesIterator.hasNext()) {
|
||||
result.add(valuesIterator.next().toString());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> setValue(List<String> value) {
|
||||
List<String> previousValues = headers.getAll(this.key);
|
||||
List<String> previousValues = getValue();
|
||||
headers.set(this.key, value);
|
||||
return previousValues;
|
||||
}
|
||||
@@ -247,12 +270,12 @@ class Netty5HeadersAdapter implements MultiValueMap<String, String> {
|
||||
|
||||
private final class HeaderNamesIterator implements Iterator<String> {
|
||||
|
||||
private final Iterator<String> iterator;
|
||||
private final Iterator<CharSequence> iterator;
|
||||
|
||||
@Nullable
|
||||
private String currentName;
|
||||
private CharSequence currentName;
|
||||
|
||||
private HeaderNamesIterator(Iterator<String> iterator) {
|
||||
private HeaderNamesIterator(Iterator<CharSequence> iterator) {
|
||||
this.iterator = iterator;
|
||||
}
|
||||
|
||||
@@ -264,7 +287,7 @@ class Netty5HeadersAdapter implements MultiValueMap<String, String> {
|
||||
@Override
|
||||
public String next() {
|
||||
this.currentName = this.iterator.next();
|
||||
return this.currentName;
|
||||
return this.currentName.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,8 +20,8 @@ import java.net.URI;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collection;
|
||||
|
||||
import io.netty5.buffer.api.Buffer;
|
||||
import io.netty5.handler.codec.http.cookie.DefaultCookie;
|
||||
import io.netty5.buffer.Buffer;
|
||||
import io.netty5.handler.codec.http.headers.DefaultHttpCookiePair;
|
||||
import org.reactivestreams.Publisher;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
@@ -131,7 +131,7 @@ class ReactorNetty2ClientHttpRequest extends AbstractClientHttpRequest implement
|
||||
@Override
|
||||
protected void applyCookies() {
|
||||
getCookies().values().stream().flatMap(Collection::stream)
|
||||
.map(cookie -> new DefaultCookie(cookie.getName(), cookie.getValue()))
|
||||
.map(cookie -> new DefaultHttpCookiePair(cookie.getName(), cookie.getValue()))
|
||||
.forEach(this.request::addCookie);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ import java.util.Collection;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import io.netty5.handler.codec.http.cookie.Cookie;
|
||||
import io.netty5.handler.codec.http.cookie.DefaultCookie;
|
||||
import io.netty5.handler.codec.http.headers.DefaultHttpSetCookie;
|
||||
import io.netty5.handler.codec.http.headers.HttpSetCookie;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import reactor.core.publisher.Flux;
|
||||
@@ -129,11 +129,11 @@ class ReactorNetty2ClientHttpResponse implements ClientHttpResponse {
|
||||
MultiValueMap<String, ResponseCookie> result = new LinkedMultiValueMap<>();
|
||||
this.response.cookies().values().stream()
|
||||
.flatMap(Collection::stream)
|
||||
.forEach(cookie -> result.add(cookie.name(),
|
||||
ResponseCookie.fromClientResponse(cookie.name(), cookie.value())
|
||||
.domain(cookie.domain())
|
||||
.path(cookie.path())
|
||||
.maxAge(cookie.maxAge())
|
||||
.forEach(cookie -> result.add(cookie.name().toString(),
|
||||
ResponseCookie.fromClientResponse(cookie.name().toString(), cookie.value().toString())
|
||||
.domain(cookie.domain() != null ? cookie.domain().toString() : null)
|
||||
.path(cookie.path() != null ? cookie.path().toString() : null)
|
||||
.maxAge(cookie.maxAge() != null ? cookie.maxAge() : -1L)
|
||||
.secure(cookie.isSecure())
|
||||
.httpOnly(cookie.isHttpOnly())
|
||||
.sameSite(getSameSite(cookie))
|
||||
@@ -142,8 +142,8 @@ class ReactorNetty2ClientHttpResponse implements ClientHttpResponse {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String getSameSite(Cookie cookie) {
|
||||
if (cookie instanceof DefaultCookie defaultCookie) {
|
||||
private static String getSameSite(HttpSetCookie cookie) {
|
||||
if (cookie instanceof DefaultHttpSetCookie defaultCookie) {
|
||||
if (defaultCookie.sameSite() != null) {
|
||||
return defaultCookie.sameSite().name();
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ class BaseDefaultCodecs implements CodecConfigurer.DefaultCodecs, CodecConfigure
|
||||
protobufPresent = ClassUtils.isPresent("com.google.protobuf.Message", classLoader);
|
||||
synchronossMultipartPresent = ClassUtils.isPresent("org.synchronoss.cloud.nio.multipart.NioMultipartParser", classLoader);
|
||||
nettyByteBufPresent = ClassUtils.isPresent("io.netty.buffer.ByteBuf", classLoader);
|
||||
netty5BufferPresent = ClassUtils.isPresent("io.netty5.buffer.api.Buffer", classLoader);
|
||||
netty5BufferPresent = ClassUtils.isPresent("io.netty5.buffer.Buffer", classLoader);
|
||||
kotlinSerializationJsonPresent = ClassUtils.isPresent("kotlinx.serialization.json.Json", classLoader);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,13 +17,17 @@
|
||||
package org.springframework.http.server.reactive;
|
||||
|
||||
import java.util.AbstractSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Spliterator;
|
||||
import java.util.Spliterators;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
import io.netty5.handler.codec.http.HttpHeaders;
|
||||
import io.netty5.handler.codec.http.headers.HttpHeaders;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -50,7 +54,8 @@ final class Netty5HeadersAdapter implements MultiValueMap<String, String> {
|
||||
@Override
|
||||
@Nullable
|
||||
public String getFirst(String key) {
|
||||
return this.headers.get(key);
|
||||
CharSequence value = this.headers.get(key);
|
||||
return value != null ? value.toString() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -85,10 +90,9 @@ final class Netty5HeadersAdapter implements MultiValueMap<String, String> {
|
||||
@Override
|
||||
public Map<String, String> toSingleValueMap() {
|
||||
Map<String, String> singleValueMap = CollectionUtils.newLinkedHashMap(this.headers.size());
|
||||
this.headers.entries()
|
||||
.forEach(entry -> {
|
||||
this.headers.forEach(entry -> {
|
||||
if (!singleValueMap.containsKey(entry.getKey())) {
|
||||
singleValueMap.put(entry.getKey(), entry.getValue());
|
||||
singleValueMap.put(entry.getKey().toString(), entry.getValue().toString());
|
||||
}
|
||||
});
|
||||
return singleValueMap;
|
||||
@@ -112,7 +116,8 @@ final class Netty5HeadersAdapter implements MultiValueMap<String, String> {
|
||||
@Override
|
||||
public boolean containsValue(Object value) {
|
||||
return (value instanceof String &&
|
||||
this.headers.entries().stream()
|
||||
StreamSupport.stream(
|
||||
Spliterators.spliteratorUnknownSize(this.headers.iterator(), Spliterator.ORDERED), false)
|
||||
.anyMatch(entry -> value.equals(entry.getValue())));
|
||||
}
|
||||
|
||||
@@ -120,7 +125,7 @@ final class Netty5HeadersAdapter implements MultiValueMap<String, String> {
|
||||
@Nullable
|
||||
public List<String> get(Object key) {
|
||||
if (containsKey(key)) {
|
||||
return this.headers.getAll((String) key);
|
||||
return getAll(this.headers.valuesIterator((CharSequence) key));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -128,7 +133,7 @@ final class Netty5HeadersAdapter implements MultiValueMap<String, String> {
|
||||
@Nullable
|
||||
@Override
|
||||
public List<String> put(String key, @Nullable List<String> value) {
|
||||
List<String> previousValues = this.headers.getAll(key);
|
||||
List<String> previousValues = getAll(this.headers.valuesIterator(key));
|
||||
this.headers.set(key, value);
|
||||
return previousValues;
|
||||
}
|
||||
@@ -137,7 +142,7 @@ final class Netty5HeadersAdapter implements MultiValueMap<String, String> {
|
||||
@Override
|
||||
public List<String> remove(Object key) {
|
||||
if (key instanceof String headerName) {
|
||||
List<String> previousValues = this.headers.getAll(headerName);
|
||||
List<String> previousValues = getAll(this.headers.valuesIterator(headerName));
|
||||
this.headers.remove(headerName);
|
||||
return previousValues;
|
||||
}
|
||||
@@ -162,7 +167,7 @@ final class Netty5HeadersAdapter implements MultiValueMap<String, String> {
|
||||
@Override
|
||||
public Collection<List<String>> values() {
|
||||
return this.headers.names().stream()
|
||||
.map(this.headers::getAll).toList();
|
||||
.map(key -> getAll(this.headers.valuesIterator(key))).toList();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -187,9 +192,22 @@ final class Netty5HeadersAdapter implements MultiValueMap<String, String> {
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
private static List<String> getAll(Iterator<CharSequence> valuesIterator) {
|
||||
if (!valuesIterator.hasNext()) {
|
||||
return null;
|
||||
}
|
||||
List<String> result = new ArrayList<>();
|
||||
while (valuesIterator.hasNext()) {
|
||||
result.add(valuesIterator.next().toString());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private class EntryIterator implements Iterator<Entry<String, List<String>>> {
|
||||
|
||||
private final Iterator<String> names = headers.names().iterator();
|
||||
private final Iterator<CharSequence> names = headers.names().iterator();
|
||||
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
@@ -205,25 +223,30 @@ final class Netty5HeadersAdapter implements MultiValueMap<String, String> {
|
||||
|
||||
private class HeaderEntry implements Entry<String, List<String>> {
|
||||
|
||||
private final String key;
|
||||
private final CharSequence key;
|
||||
|
||||
HeaderEntry(String key) {
|
||||
HeaderEntry(CharSequence key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return this.key;
|
||||
return this.key.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getValue() {
|
||||
return headers.getAll(this.key);
|
||||
List<String> result = new ArrayList<>();
|
||||
Iterator<CharSequence> valuesIterator = headers.valuesIterator(this.key);
|
||||
while (valuesIterator.hasNext()) {
|
||||
result.add(valuesIterator.next().toString());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> setValue(List<String> value) {
|
||||
List<String> previousValues = headers.getAll(this.key);
|
||||
List<String> previousValues = getValue();
|
||||
headers.set(this.key, value);
|
||||
return previousValues;
|
||||
}
|
||||
@@ -244,12 +267,12 @@ final class Netty5HeadersAdapter implements MultiValueMap<String, String> {
|
||||
|
||||
private final class HeaderNamesIterator implements Iterator<String> {
|
||||
|
||||
private final Iterator<String> iterator;
|
||||
private final Iterator<CharSequence> iterator;
|
||||
|
||||
@Nullable
|
||||
private String currentName;
|
||||
private CharSequence currentName;
|
||||
|
||||
private HeaderNamesIterator(Iterator<String> iterator) {
|
||||
private HeaderNamesIterator(Iterator<CharSequence> iterator) {
|
||||
this.iterator = iterator;
|
||||
}
|
||||
|
||||
@@ -261,7 +284,7 @@ final class Netty5HeadersAdapter implements MultiValueMap<String, String> {
|
||||
@Override
|
||||
public String next() {
|
||||
this.currentName = this.iterator.next();
|
||||
return this.currentName;
|
||||
return this.currentName.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -25,7 +25,7 @@ import javax.net.ssl.SSLSession;
|
||||
|
||||
import io.netty5.channel.Channel;
|
||||
import io.netty5.handler.codec.http.HttpHeaderNames;
|
||||
import io.netty5.handler.codec.http.cookie.Cookie;
|
||||
import io.netty5.handler.codec.http.headers.HttpCookiePair;
|
||||
import io.netty5.handler.ssl.SslHandler;
|
||||
import org.apache.commons.logging.Log;
|
||||
import reactor.core.publisher.Flux;
|
||||
@@ -80,8 +80,9 @@ class ReactorNetty2ServerHttpRequest extends AbstractServerHttpRequest {
|
||||
|
||||
private static URI resolveBaseUrl(HttpServerRequest request) throws URISyntaxException {
|
||||
String scheme = getScheme(request);
|
||||
String header = request.requestHeaders().get(HttpHeaderNames.HOST);
|
||||
if (header != null) {
|
||||
CharSequence headerCS = request.requestHeaders().get(HttpHeaderNames.HOST);
|
||||
if (headerCS != null) {
|
||||
String header = headerCS.toString();
|
||||
final int portIndex;
|
||||
if (header.startsWith("[")) {
|
||||
portIndex = header.indexOf(':', header.indexOf(']'));
|
||||
@@ -151,8 +152,9 @@ class ReactorNetty2ServerHttpRequest extends AbstractServerHttpRequest {
|
||||
protected MultiValueMap<String, HttpCookie> initCookies() {
|
||||
MultiValueMap<String, HttpCookie> cookies = new LinkedMultiValueMap<>();
|
||||
for (CharSequence name : this.request.cookies().keySet()) {
|
||||
for (Cookie cookie : this.request.cookies().get(name)) {
|
||||
HttpCookie httpCookie = new HttpCookie(name.toString(), cookie.value());
|
||||
for (HttpCookiePair cookie : this.request.cookies().get(name)) {
|
||||
CharSequence cookieValue = cookie.value();
|
||||
HttpCookie httpCookie = new HttpCookie(name.toString(), cookieValue != null ? cookieValue.toString() : null);
|
||||
cookies.add(name.toString(), httpCookie);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ package org.springframework.http.server.reactive;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import io.netty5.buffer.api.Buffer;
|
||||
import io.netty5.buffer.Buffer;
|
||||
import io.netty5.channel.ChannelId;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
Reference in New Issue
Block a user