Skip to content

Commit

Permalink
Add RequestContext method to get cookie value (#2033)
Browse files Browse the repository at this point in the history
  • Loading branch information
pkoenig10 authored Apr 27, 2023
1 parent cc833ff commit af82796
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-2033.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: feature
feature:
description: Add `RequestContext` method to get cookie values.
links:
- https://github.com/palantir/conjure-java/pull/2033
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.palantir.logsafe.logger.SafeLogger;
import com.palantir.logsafe.logger.SafeLoggerFactory;
import io.undertow.server.HttpServerExchange;
import io.undertow.server.handlers.Cookie;
import io.undertow.util.HeaderValues;
import java.security.cert.Certificate;
import java.util.Collections;
Expand Down Expand Up @@ -71,6 +72,11 @@ public Optional<String> firstHeader(String headerName) {
return Optional.ofNullable(exchange.getRequestHeaders().getFirst(headerName));
}

@Override
public Optional<String> cookie(String cookieName) {
return Optional.ofNullable(exchange.getRequestCookie(cookieName)).map(Cookie::getValue);
}

@Override
public ImmutableListMultimap<String, String> queryParameters() {
ImmutableListMultimap<String, String> cachedQueryParamsSnapshot = cachedQueryParams;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ public interface RequestContext {
*/
Optional<String> firstHeader(String headerName);

/**
* Returns the value of the cookie named {@code cookieName}.
* An {@link Optional#empty()} is returned if no such cookie exists.
*/
Optional<String> cookie(String cookieName);

/**
* Returns all query parameters associated with the current request.
*/
Expand Down

0 comments on commit af82796

Please sign in to comment.