blob: 0ba5eb7a913755f81cb09c7d84ddd7159abd3102 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc.http;
import com.yahoo.jdisc.HeaderFields;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
/**
* Helper for encoding/decoding cookies on request/response.
*
* @author bjorncs
*/
public class CookieHelper {
private CookieHelper() {}
public static List<Cookie> decodeSetCookieHeader(HeaderFields headers) {
List<String> cookies = headers.get(HttpHeaders.Names.SET_COOKIE);
if (cookies == null) {
return Collections.emptyList();
}
List<Cookie> ret = new LinkedList<>();
for (String cookie : cookies) {
ret.add(Cookie.fromSetCookieHeader(cookie));
}
return ret;
}
public static void encodeSetCookieHeader(HeaderFields headers, List<Cookie> cookies) {
headers.remove(HttpHeaders.Names.SET_COOKIE);
for (Cookie cookie : cookies) {
headers.add(HttpHeaders.Names.SET_COOKIE, Cookie.toSetCookieHeaders(Arrays.asList(cookie)));
}
}
}
|