use reactor cookie support
This commit is contained in:
parent
da90f03f4c
commit
0f432f735a
|
@ -18,12 +18,14 @@ package org.springframework.http.server.reactive;
|
|||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import reactor.Flux;
|
||||
import reactor.io.buffer.Buffer;
|
||||
import reactor.io.net.http.HttpChannel;
|
||||
import reactor.io.net.http.model.Cookie;
|
||||
|
||||
import org.springframework.http.HttpCookie;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
|
@ -69,7 +71,16 @@ public class ReactorServerHttpRequest extends AbstractServerHttpRequest {
|
|||
|
||||
@Override
|
||||
protected void initCookies(Map<String, List<HttpCookie>> cookies) {
|
||||
// https://github.com/reactor/reactor/issues/614
|
||||
for (String name : this.channel.cookies().keySet()) {
|
||||
List<HttpCookie> list = cookies.get(name);
|
||||
if (list == null) {
|
||||
list = new ArrayList<>();
|
||||
cookies.put(name, list);
|
||||
}
|
||||
for (Cookie cookie : this.channel.cookies().get(name)) {
|
||||
list.add(HttpCookie.clientCookie(name, cookie.value()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -22,8 +22,10 @@ import reactor.Flux;
|
|||
import reactor.Mono;
|
||||
import reactor.io.buffer.Buffer;
|
||||
import reactor.io.net.http.HttpChannel;
|
||||
import reactor.io.net.http.model.Cookie;
|
||||
import reactor.io.net.http.model.Status;
|
||||
|
||||
import org.springframework.http.HttpCookie;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
|
@ -69,7 +71,57 @@ public class ReactorServerHttpResponse extends AbstractServerHttpResponse {
|
|||
|
||||
@Override
|
||||
protected void writeCookies() {
|
||||
// https://github.com/reactor/reactor/issues/614
|
||||
for (String name : getHeaders().getCookies().keySet()) {
|
||||
for (HttpCookie httpCookie : getHeaders().getCookies().get(name)) {
|
||||
Cookie cookie = new ReactorCookie(name, httpCookie);
|
||||
this.channel.addResponseCookie(name, cookie);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final static class ReactorCookie extends Cookie {
|
||||
|
||||
final HttpCookie httpCookie;
|
||||
final String name;
|
||||
|
||||
public ReactorCookie(String name, HttpCookie httpCookie) {
|
||||
this.name = name;
|
||||
this.httpCookie = httpCookie;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String value() {
|
||||
return httpCookie.getValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean httpOnly() {
|
||||
return httpCookie.isHttpOnly();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long maxAge() {
|
||||
return httpCookie.getMaxAge() > -1 ? httpCookie.getMaxAge() : -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String domain() {
|
||||
return httpCookie.getDomain();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String path() {
|
||||
return httpCookie.getPath();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean secure() {
|
||||
return httpCookie.isSecure();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ import org.springframework.http.RequestEntity;
|
|||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.server.reactive.boot.HttpServer;
|
||||
import org.springframework.http.server.reactive.boot.JettyHttpServer;
|
||||
import org.springframework.http.server.reactive.boot.ReactorHttpServer;
|
||||
import org.springframework.http.server.reactive.boot.RxNettyHttpServer;
|
||||
import org.springframework.http.server.reactive.boot.TomcatHttpServer;
|
||||
import org.springframework.http.server.reactive.boot.UndertowHttpServer;
|
||||
|
@ -66,7 +67,7 @@ public class CookieIntegrationTests {
|
|||
return new Object[][] {
|
||||
{new JettyHttpServer()},
|
||||
{new RxNettyHttpServer()},
|
||||
// {new ReactorHttpServer()},
|
||||
{new ReactorHttpServer()},
|
||||
{new TomcatHttpServer()},
|
||||
{new UndertowHttpServer()}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue