Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[UNDERTOW-1489] Keep track of duplicate cookie entries at HttpServlet…
…ResponseImpl, and add them to header via Connectors.addCookie This solution is an alternative to keeping track of those entries inside the Exchange. The response cookies map in that class is part of public spi and would break compatibility.
- Loading branch information
Showing
7 changed files
with
426 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
servlet/src/test/java/io/undertow/servlet/test/response/cookies/AddCookiesServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,48 @@ | |||
/* | |||
* JBoss, Home of Professional Open Source. | |||
* Copyright 2019 Red Hat, Inc., and individual contributors | |||
* as indicated by the @author tags. | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
|
|||
package io.undertow.servlet.test.response.cookies; | |||
|
|||
import java.io.IOException; | |||
|
|||
import javax.servlet.ServletException; | |||
import javax.servlet.http.Cookie; | |||
import javax.servlet.http.HttpServlet; | |||
import javax.servlet.http.HttpServletRequest; | |||
import javax.servlet.http.HttpServletResponse; | |||
|
|||
/** | |||
* Simple servlet that adds cookies to response. | |||
* | |||
* @author Flavia Rainone | |||
*/ | |||
public class AddCookiesServlet extends HttpServlet { | |||
|
|||
@Override | |||
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { | |||
Cookie cookie1 = new Cookie("test1", "test1"); | |||
cookie1.setPath("/test"); | |||
|
|||
Cookie cookie2 = new Cookie("test2", "test2"); | |||
|
|||
resp.addCookie(cookie1); | |||
resp.addCookie(cookie2); | |||
|
|||
resp.getWriter().append("Served at: ").append(req.getContextPath()); | |||
} | |||
} |
49 changes: 49 additions & 0 deletions
49
servlet/src/test/java/io/undertow/servlet/test/response/cookies/DuplicateCookiesServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,49 @@ | |||
/* | |||
* JBoss, Home of Professional Open Source. | |||
* Copyright 2019 Red Hat, Inc., and individual contributors | |||
* as indicated by the @author tags. | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
|
|||
package io.undertow.servlet.test.response.cookies; | |||
|
|||
import java.io.IOException; | |||
|
|||
import javax.servlet.ServletException; | |||
import javax.servlet.http.Cookie; | |||
import javax.servlet.http.HttpServlet; | |||
import javax.servlet.http.HttpServletRequest; | |||
import javax.servlet.http.HttpServletResponse; | |||
|
|||
/** | |||
* Servlet that adds duplicate cookies (i.e., with the same name) to response. | |||
* | |||
* @author Flavia Rainone | |||
*/ | |||
public class DuplicateCookiesServlet extends HttpServlet { | |||
|
|||
@Override | |||
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { | |||
Cookie cookie1 = new Cookie("test", "test"); | |||
cookie1.setPath("/test"); | |||
|
|||
Cookie cookie2 = new Cookie("test", "test"); | |||
cookie2.setPath("/test2"); | |||
|
|||
resp.addCookie(cookie1); | |||
resp.addCookie(cookie2); | |||
|
|||
resp.getWriter().append("Served at: ").append(req.getContextPath()); | |||
} | |||
} |
64 changes: 64 additions & 0 deletions
64
...let/src/test/java/io/undertow/servlet/test/response/cookies/JSessionIDCookiesServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,64 @@ | |||
/* | |||
* JBoss, Home of Professional Open Source. | |||
* Copyright 2019 Red Hat, Inc., and individual contributors | |||
* as indicated by the @author tags. | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
|
|||
package io.undertow.servlet.test.response.cookies; | |||
|
|||
import java.io.IOException; | |||
|
|||
import javax.servlet.ServletException; | |||
import javax.servlet.http.HttpServlet; | |||
import javax.servlet.http.HttpServletRequest; | |||
import javax.servlet.http.HttpServletResponse; | |||
|
|||
/** | |||
* Servlet that emulates a buggy behavior where JSessionID cookie is added several times with | |||
* wrong path, and a few of them with max age limits for cookie expiration. | |||
* | |||
* @author Flavia Rainone | |||
*/ | |||
public class JSessionIDCookiesServlet extends HttpServlet { | |||
|
|||
@Override | |||
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { | |||
javax.servlet.http.Cookie cookie1 = new javax.servlet.http.Cookie("JSESSIONID", "_bug_fix"); | |||
cookie1.setPath("/path1"); | |||
cookie1.setMaxAge(0); | |||
|
|||
javax.servlet.http.Cookie cookie2 = new javax.servlet.http.Cookie("JSESSIONID", "_bug_fix"); | |||
cookie2.setPath("/path2"); | |||
cookie2.setMaxAge(0); | |||
|
|||
javax.servlet.http.Cookie cookie3 = new javax.servlet.http.Cookie("JSESSIONID", "_bug_fix"); | |||
cookie1.setPath("/path3"); | |||
cookie1.setMaxAge(500); | |||
|
|||
javax.servlet.http.Cookie cookie4 = new javax.servlet.http.Cookie("JSESSIONID", "_bug_fix"); | |||
cookie2.setPath("/path4"); | |||
cookie2.setMaxAge(1000); | |||
|
|||
resp.addCookie(cookie1); | |||
resp.addCookie(cookie2); | |||
resp.addCookie(cookie3); | |||
resp.addCookie(cookie4); | |||
|
|||
// creating session -> additional set-cookie | |||
req.getSession().setAttribute("CleanSessions", true); | |||
|
|||
resp.getWriter().append("Served at: ").append(req.getContextPath()); | |||
} | |||
} |
61 changes: 61 additions & 0 deletions
61
servlet/src/test/java/io/undertow/servlet/test/response/cookies/OverwriteCookiesServlet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,61 @@ | |||
/* | |||
* JBoss, Home of Professional Open Source. | |||
* Copyright 2019 Red Hat, Inc., and individual contributors | |||
* as indicated by the @author tags. | |||
* | |||
* Licensed under the Apache License, Version 2.0 (the "License"); | |||
* you may not use this file except in compliance with the License. | |||
* You may obtain a copy of the License at | |||
* | |||
* http://www.apache.org/licenses/LICENSE-2.0 | |||
* | |||
* Unless required by applicable law or agreed to in writing, software | |||
* distributed under the License is distributed on an "AS IS" BASIS, | |||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||
* See the License for the specific language governing permissions and | |||
* limitations under the License. | |||
*/ | |||
|
|||
package io.undertow.servlet.test.response.cookies; | |||
|
|||
import java.io.IOException; | |||
|
|||
import javax.servlet.ServletException; | |||
import javax.servlet.http.Cookie; | |||
import javax.servlet.http.HttpServlet; | |||
import javax.servlet.http.HttpServletRequest; | |||
import javax.servlet.http.HttpServletResponse; | |||
|
|||
/** | |||
* Servlet that adds multiple cookies with same name and a few of which sharing | |||
* the same path, to test cookies with same path and name being correctly | |||
* overriden. | |||
* | |||
* @author Flavia Rainone | |||
*/ | |||
public class OverwriteCookiesServlet extends HttpServlet { | |||
|
|||
@Override | |||
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { | |||
Cookie cookie1 = new javax.servlet.http.Cookie("test", "test1"); | |||
cookie1.setPath("/test"); | |||
|
|||
Cookie cookie2 = new javax.servlet.http.Cookie("test", "test2"); | |||
cookie2.setPath("/test"); | |||
|
|||
Cookie cookie3 = new javax.servlet.http.Cookie("test", "test3"); | |||
Cookie cookie4 = new javax.servlet.http.Cookie("test", "test4"); | |||
Cookie cookie5 = new javax.servlet.http.Cookie("test", "test5"); | |||
|
|||
resp.addCookie(cookie1); | |||
resp.addCookie(cookie2); | |||
resp.addCookie(cookie3); | |||
resp.addCookie(cookie4); | |||
resp.addCookie(cookie5); | |||
|
|||
// creating session -> additional jsessionid set-cookie | |||
req.getSession().setAttribute("CleanSessions", true); | |||
|
|||
resp.getWriter().append("Served at: ").append(req.getContextPath()); | |||
} | |||
} |
Oops, something went wrong.