Skip to content

Commit

Permalink
Generalise cookie-setting
Browse files Browse the repository at this point in the history
  • Loading branch information
RayDNoper committed Dec 22, 2023
1 parent 0ba30c0 commit f87e3fb
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/main/java/ee/buerokratt/ruuter/domain/steps/ReturnStep.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,18 @@ private Map<String, String> formatHeaders(DslInstance di) {
.collect(toMap(Entry::getKey, this::entryValueToHeaderString));
}

private void addToCookie(LinkedHashMap<String, Object> cookie, String key, Object value) {
if (!cookie.containsKey(key))
cookie.put(key, value);
}
private Map.Entry<String, Object> addDefaultCookies(Map.Entry<String, Object> entry, DslInstance di) {
if ("Set-Cookie".equals(entry.getKey())) {
LinkedHashMap<String, Object> cookie = new LinkedHashMap<>((HashMap<String, Object>) entry.getValue());
if (!cookie.containsKey("Path"))
cookie.put("Path", "/" );

if (!cookie.containsKey("HttpOnly"))
cookie.put("HttpOnly", true);

if (!cookie.containsKey("SetSecure"))
cookie.put("Secure", true);
addToCookie(cookie, "Path", "/");
addToCookie(cookie, "HttpOnly", true);
addToCookie(cookie, "Secure", true);
addToCookie(cookie, "Max-Age", 28800);

entry.setValue(cookie);
}
Expand Down

0 comments on commit f87e3fb

Please sign in to comment.