private void putAllCookiesInASingleHeader ( String host , CookieSpec matcher , Cookie [ ] cookies ) { LOG . trace ( "enter putAllCookiesInASingleHeader(String host, CookieSpec matcher, Cookie[] cookies)" ) ; //use a map to make sure we only have one cookie per name HashMap < String , Cookie > mergedCookies = new HashMap < String , Cookie > ( ) ; Header [ ] cookieLineHeaders = getRequestHeaderGroup ( ) . getHeaders ( HttpHeader . COOKIE ) ; for ( Header cookieLineHeader : cookieLineHeaders ) { List < Cookie > cookiesHeader = parseCookieHeader ( host , cookieLineHeader . getValue ( ) ) ; for ( Cookie cookieHeader : cookiesHeader ) { mergedCookies . put ( cookieHeader . getName ( ) , cookieHeader ) ; } // clean the header getRequestHeaderGroup ( ) . removeHeader ( cookieLineHeader ) ; } //add the cookies coming from the state for ( Cookie cookie : cookies ) { mergedCookies . put ( cookie . getName ( ) , cookie ) ; } cookies = mergedCookies . values ( ) . toArray ( new Cookie [ mergedCookies . size ( ) ] ) ; String s = matcher . formatCookies ( cookies ) ; getRequestHeaderGroup ( ) . addHeader ( new Header ( HttpHeader . COOKIE , s , true ) ) ; }
Put all the cookies in a single header line .