Skip to content

Commit

Permalink
refactor: 쿠키 파싱 구분자 상수화
Browse files Browse the repository at this point in the history
  • Loading branch information
youngh0 committed Sep 4, 2023
1 parent fdd145d commit 7ef6666
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
public class Cookie {

private static final String COOKIE_DELIMITER = ";";
public static final String COOKIE_VALUE_DELIMITER = "=";
public static final int COOKIE_KEY_INDEX = 0;
public static final int COOKIE_VALUE_INDEX = 1;

private final Map<String, String> cookies;

Expand All @@ -20,8 +23,8 @@ public static Cookie from(String cookieValue) {
}

Map<String, String> cookies = Arrays.stream(cookieValue.split(COOKIE_DELIMITER))
.map(cookieElement -> cookieElement.trim().split("="))
.collect(Collectors.toMap(cookie -> cookie[0], cookie -> cookie[1]));
.map(cookieElement -> cookieElement.trim().split(COOKIE_VALUE_DELIMITER))
.collect(Collectors.toMap(cookie -> cookie[COOKIE_KEY_INDEX], cookie -> cookie[COOKIE_VALUE_INDEX]));
return new Cookie(cookies);
}

Expand Down

0 comments on commit 7ef6666

Please sign in to comment.