Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug:The path of the cookie is changed. More sessions will be created … #226

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/main/java/org/mitre/dsmiley/httpproxy/ProxyServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ public class ProxyServlet extends HttpServlet {
protected static final String ATTR_TARGET_HOST =
ProxyServlet.class.getSimpleName() + ".targetHost";

/**default root path of cookie**/
private static String COOKIE_ROOT_PATH = "/";

/* MISC */

protected boolean doLog = false;
Expand Down Expand Up @@ -590,7 +593,8 @@ protected void copyProxyCookie(HttpServletRequest servletRequest,
protected Cookie createProxyCookie(HttpServletRequest servletRequest, HttpCookie cookie) {
String proxyCookieName = getProxyCookieName(cookie);
Cookie servletCookie = new Cookie(proxyCookieName, cookie.getValue());
servletCookie.setPath(buildProxyCookiePath(servletRequest)); //set to the path of the proxy servlet
//set to the path of the proxy servlet
servletCookie.setPath(COOKIE_ROOT_PATH.equals(cookie.getPath()) ? COOKIE_ROOT_PATH : buildProxyCookiePath(servletRequest));
servletCookie.setComment(cookie.getComment());
servletCookie.setMaxAge((int) cookie.getMaxAge());
// don't set cookie domain
Expand Down Expand Up @@ -621,7 +625,7 @@ protected String buildProxyCookiePath(HttpServletRequest servletRequest) {
String path = servletRequest.getContextPath(); // path starts with / or is empty string
path += servletRequest.getServletPath(); // servlet path starts with / or is empty string
if (path.isEmpty()) {
path = "/";
path = COOKIE_ROOT_PATH;
}
return path;
}
Expand Down Expand Up @@ -680,7 +684,7 @@ protected void copyResponseEntity(HttpResponse proxyResponse, HttpServletRespons
* but may read or skip fewer bytes.
*
* To work around this, a flush is issued always if compression
* is handled by apache http client
* is handled by apache http client
*/
if (doHandleCompression || is.available() == 0 /* next is.read will block */) {
os.flush();
Expand Down