Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NettyMutableHttpResponse should support getCookies #10972

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
import io.micronaut.http.MutableHttpResponse;
import io.micronaut.http.body.MessageBodyWriter;
import io.micronaut.http.cookie.Cookie;
import io.micronaut.http.cookie.Cookies;
import io.micronaut.http.cookie.ServerCookieEncoder;
import io.micronaut.http.netty.cookies.NettyCookies;
import io.micronaut.http.netty.stream.DefaultStreamedHttpResponse;
import io.micronaut.http.netty.stream.StreamedHttpResponse;
import io.netty.buffer.ByteBuf;
Expand All @@ -50,6 +52,7 @@
import io.netty.handler.codec.http.HttpResponse;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.HttpVersion;

import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -267,6 +270,16 @@ public MutableHttpResponse<B> cookies(Set<Cookie> cookies) {
return this;
}

@Override
public Cookies getCookies() {
return new NettyCookies(nettyHeaders, conversionService);
}

@Override
public Optional<Cookie> getCookie(String name) {
return getCookies().findCookie(name);
}

@Override
public Optional<B> getBody() {
return (Optional) optionalBody;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ class NettyHttpResponseSpec extends Specification {
expect:
response.status == HttpStatus."$status"
response.headers.get(header) == value
response.getCookies().size() == 1
response.getCookies().get("foo").value == "bar"
response.getCookie("foo").get().value == "bar"

where:
status | header | value
Expand Down
2 changes: 1 addition & 1 deletion http/src/main/java/io/micronaut/http/HttpResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ default Cookies getCookies() {
* @return The Cookie
*/
default Optional<Cookie> getCookie(String name) {
throw new UnsupportedOperationException("Operation not supported on a " + this.getClass() + " response.");
return getCookies().findCookie(name);
}

/**
Expand Down
Loading