Source:
<code>protected void getResponse(String url, HttpResponse response, HttpRequestBase method, Map<String, Object> headers) { try { if (headers != null) { for (String key : headers.keySet()) { Object value = headers.get(key); if (value != null) { method.setHeader(key, value.toString()); } } } org.apache.http.HttpResponse resp; CookieStore store = response.getCookieStore(); if (store == null) { store = new BasicCookieStore(); } resp = getHttpResponse(store, url, method); int returnCode = resp.getStatusLine().getStatusCode(); response.setStatusCode(returnCode); HttpEntity entity = resp.getEntity(); Map<String, String> responseHeaders = response.getResponseHeaders(); for (Header h : resp.getAllHeaders()) { <START> if(h.getName().equalsIgnoreCase("Set-Cookie")) <END> { StringBuilder cookieHeader = new StringBuilder(); List<Cookie> cookies = store.getCookies(); for(Cookie cookie : cookies) { cookieHeader.append(cookie.getName() + "=" + cookie.getValue()); cookieHeader.append(";"); } responseHeaders.put(h.getName(), cookieHeader.toString()); } else { responseHeaders.put(h.getName(), h.getValue()); } } if (entity == null) { response.setResponse(null); } else { if (response instanceof BinaryHttpResponse) { BinaryHttpResponse binaryHttpResponse = (BinaryHttpResponse) response; byte[] content = EntityUtils.toByteArray(entity); binaryHttpResponse.setResponseContent(content); String fileName = getAttachmentFileName(resp); binaryHttpResponse.setFileName(fileName); } else { String result = EntityUtils.toString(entity); response.setResponse(result); } } } catch (Exception e) { throw new RuntimeException("Unable to get response from: " + url, e); } finally { method.reset(); } }</code><technical_language>this values for 'Set-Cookie' in responseHeader response's cookieStore filled request? I as-if cookies present in response's cookieStore server (even if added programmatically request sent). is good. responseHeaders Set-Cookies server. **If is problem** : nicer to: - process headers before. - (if responseHeaders contains 'Set-Cookie') put cookies in store in responseHeaders for key 'Set-Cookie'. Basically do now, for loop instead of nested it</technical_language>

Target:
protected void getResponse(String url, HttpResponse response, HttpRequestBase method, Map<String, Object> headers) { try { if (headers != null) { for (String key : headers.keySet()) { Object value = headers.get(key); if (value != null) { method.setHeader(key, value.toString()); } } } org.apache.http.HttpResponse resp; CookieStore store = response.getCookieStore(); if (store == null) { resp = getHttpResponse(url, method); } else { resp = getHttpResponse(store, url, method); } int returnCode = resp.getStatusLine().getStatusCode(); response.setStatusCode(returnCode); HttpEntity entity = resp.getEntity(); Map<String, String> responseHeaders = response.getResponseHeaders(); for (Header h : resp.getAllHeaders()) { responseHeaders.put(h.getName(), h.getValue()); } if (entity == null) { response.setResponse(null); } else { if (response instanceof BinaryHttpResponse) { BinaryHttpResponse binaryHttpResponse = (BinaryHttpResponse) response; byte[] content = EntityUtils.toByteArray(entity); binaryHttpResponse.setResponseContent(content); String fileName = getAttachmentFileName(resp); binaryHttpResponse.setFileName(fileName); } else { String result = EntityUtils.toString(entity); response.setResponse(result); } } } catch (Exception e) { throw new RuntimeException("Unable to get response from: " + url, e); } finally { method.reset(); } }