@@ -16,22 +16,39 @@ public class RequestUtils {
1616 * @param headers The Headers
1717 * @return An hashmap with the cookie name as key and the complete cookie as value.
1818 */
19- protected static HashMap <String , Cookie > parseCookies (Headers headers ) {
19+ static HashMap <String , Cookie > parseCookies (Headers headers ) {
2020 HashMap <String , Cookie > cookieList = new HashMap <>();
2121 List <String > headerCookies = headers .get ("Cookie" );
2222
2323 if (headerCookies == null || headerCookies .size () == 0 ) {
2424 return cookieList ;
2525 }
2626
27- String hcookies = headerCookies .get (0 );
27+ char [] chars = headerCookies .get (0 ).toCharArray ();
28+ StringBuilder key = new StringBuilder ();
29+ StringBuilder val = new StringBuilder ();
30+ boolean swap = false ;
31+
32+ for (char c : chars ) {
33+ if (c == '=' ) {
34+ swap = true ;
35+ } else if (c == ';' ) {
36+ String rkey = key .toString ().trim ();
37+ cookieList .put (rkey , new Cookie (rkey , val .toString ()));
38+
39+ key .setLength (0 );
40+ val .setLength (0 );
41+ swap = false ;
42+ } else if (swap ) {
43+ val .append (c );
44+ } else {
45+ key .append (c );
46+ }
47+ }
2848
29- String [] cookies = hcookies .split (";" );
30- for (String cookie : cookies ) {
31- String [] split = cookie .split ("=" );
32- String name = split [0 ].trim ();
33- String value = split [1 ].trim ();
34- cookieList .put (name , new Cookie (name , value ));
49+ if (key .length () > 0 && val .length () > 0 ) {
50+ String rkey = key .toString ().trim ();
51+ cookieList .put (rkey , new Cookie (rkey , val .toString ()));
3552 }
3653
3754 return cookieList ;
@@ -43,7 +60,7 @@ protected static HashMap<String, Cookie> parseCookies(Headers headers) {
4360 * @param rawQuery The raw query
4461 * @return An list with key-values which are encoded in UTF8.
4562 */
46- protected static HashMap <String , String > parseRawQuery (String rawQuery ) {
63+ static HashMap <String , String > parseRawQuery (String rawQuery ) {
4764 HashMap <String , String > querys = new HashMap <>();
4865
4966 if (rawQuery == null )
0 commit comments