@@ -84,6 +84,9 @@ public class ProxyServlet extends HttpServlet {
84
84
/** A boolean parameter name to keep COOKIES as-is */
85
85
public static final String P_PRESERVECOOKIES = "preserveCookies" ;
86
86
87
+ /** A boolean parameter name to keep COOKIE path as-is */
88
+ public static final String P_PRESERVECOOKIEPATH = "preserveCookiePath" ;
89
+
87
90
/** A boolean parameter name to have auto-handle redirects */
88
91
public static final String P_HANDLEREDIRECTS = "http.protocol.handle-redirects" ; // ClientPNames.HANDLE_REDIRECTS
89
92
@@ -121,6 +124,7 @@ public class ProxyServlet extends HttpServlet {
121
124
protected boolean doSendUrlFragment = true ;
122
125
protected boolean doPreserveHost = false ;
123
126
protected boolean doPreserveCookies = false ;
127
+ protected boolean doPreserveCookiePath = false ;
124
128
protected boolean doHandleRedirects = false ;
125
129
protected boolean useSystemProperties = true ;
126
130
protected boolean doHandleCompression = false ;
@@ -182,6 +186,11 @@ public void init() throws ServletException {
182
186
this .doPreserveCookies = Boolean .parseBoolean (preserveCookiesString );
183
187
}
184
188
189
+ String preserveCookiePathString = getConfigParam (P_PRESERVECOOKIEPATH );
190
+ if (preserveCookiePathString != null ) {
191
+ this .doPreserveCookiePath = Boolean .parseBoolean (preserveCookiePathString );
192
+ }
193
+
185
194
String handleRedirectsString = getConfigParam (P_HANDLEREDIRECTS );
186
195
if (handleRedirectsString != null ) {
187
196
this .doHandleRedirects = Boolean .parseBoolean (handleRedirectsString );
@@ -590,7 +599,10 @@ protected void copyProxyCookie(HttpServletRequest servletRequest,
590
599
protected Cookie createProxyCookie (HttpServletRequest servletRequest , HttpCookie cookie ) {
591
600
String proxyCookieName = getProxyCookieName (cookie );
592
601
Cookie servletCookie = new Cookie (proxyCookieName , cookie .getValue ());
593
- servletCookie .setPath (buildProxyCookiePath (servletRequest )); //set to the path of the proxy servlet
602
+ servletCookie .setPath (this .doPreserveCookiePath ?
603
+ cookie .getPath () : // preserve original cookie path
604
+ buildProxyCookiePath (servletRequest ) //set to the path of the proxy servlet
605
+ );
594
606
servletCookie .setComment (cookie .getComment ());
595
607
servletCookie .setMaxAge ((int ) cookie .getMaxAge ());
596
608
// don't set cookie domain
0 commit comments