}
protected boolean prepareForwardingCookies(HttpRequestBase method, HttpServletRequest request, DefaultHttpClient httpClient) throws ServletException {
Object timedObject = ProxyProfiler.getTimedObject();
Cookie[] cookies = request.getCookies();
BasicCookieStore cs = new BasicCookieStore();
httpClient.setCookieStore(cs);
if (cookies != null) {
for (Cookie cookie : cookies) {
if (cookie != null) {
String cookiename = cookie.getName();
if(StringUtil.isNotEmpty(cookiename)) {
String cookieval = cookie.getValue();
if (cookiename.startsWith(PASSTHRUID)) {
cookiename = cookiename.substring(PASSTHRUID.length());
if(isCookieAllowed(cookiename)) {
String[] parts = decodeCookieNameAndPath(cookiename);
if (parts!=null && parts.length==3) {
cookiename = parts[0];
String path = parts[1];
String domain = parts[2];
// Got stored domain now see if it matches destination
BasicClientCookie methodcookie = new BasicClientCookie(cookiename,cookieval);
methodcookie.setDomain(domain);
methodcookie.setPath(path);
cs.addCookie(methodcookie);
if(getDebugHook()!=null) {
getDebugHook().getDumpRequest().addCookie(methodcookie.getName(), methodcookie.toString());
}
}
}
} else if(isCookieAllowed(cookiename)) {
BasicClientCookie methodcookie = new BasicClientCookie(cookiename,cookieval);
String domain = cookie.getDomain();
if (domain == null) {
try {
domain = method.getURI().getHost();
domain = domain.substring(domain.indexOf('.'));
} catch (Exception e) {
domain = "";
}
}
methodcookie.setDomain(domain);
String path = cookie.getPath();
if (path == null) {
path = "/";
}
methodcookie.setPath(path);
cs.addCookie(methodcookie);
if(getDebugHook()!=null) {
getDebugHook().getDumpRequest().addCookie(methodcookie.getName(), methodcookie.toString());
}
}
}