Skip to content

Commit

Permalink
fix: cookie on http response with status code
Browse files Browse the repository at this point in the history
  • Loading branch information
bbortt authored and christophd committed Nov 21, 2023
1 parent 1ff9c14 commit 93e85c2
Show file tree
Hide file tree
Showing 2 changed files with 166 additions and 200 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

import jakarta.servlet.http.Cookie;
Expand Down Expand Up @@ -54,6 +55,10 @@ public HttpMessageConverter(CookieConverter cookieConverter) {
this.cookieConverter = cookieConverter;
}

private static String resolveCookieValue(TestContext context, Cookie cookie) {
return Objects.isNull(context) ? cookie.getValue() : context.replaceDynamicContentInString(cookie.getValue());
}

@Override
public HttpEntity<?> convertOutbound(Message message,
HttpEndpointConfiguration endpointConfiguration,
Expand All @@ -63,15 +68,15 @@ public HttpEntity<?> convertOutbound(Message message,

HttpHeaders httpHeaders = createHttpHeaders(httpMessage, endpointConfiguration);

for (Cookie cookie : httpMessage.getCookies()) {
httpHeaders.add(
HttpHeaders.COOKIE,
cookie.getName() + "=" + resolveCookieValue(context, cookie));
}

Object payload = httpMessage.getPayload();
if (httpMessage.getStatusCode() != null) {
return new ResponseEntity<>(payload, httpHeaders, httpMessage.getStatusCode());
} else {
for (Cookie cookie : httpMessage.getCookies()) {
httpHeaders.add(
HttpHeaders.COOKIE,
cookie.getName() + "=" + context.replaceDynamicContentInString(cookie.getValue()));
}
}

RequestMethod method = determineRequestMethod(endpointConfiguration, httpMessage);
Expand Down
Loading

0 comments on commit 93e85c2

Please sign in to comment.