This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/master by this push:
     new 445251f  Test case for OPTIONS request on a sub-class
445251f is described below

commit 445251f4d46d6718a991ec21e0ea545b63dcc2b7
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Mon Feb 17 09:32:46 2020 +0000

    Test case for OPTIONS request on a sub-class
---
 test/jakarta/servlet/http/TestHttpServlet.java | 61 ++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)

diff --git a/test/jakarta/servlet/http/TestHttpServlet.java 
b/test/jakarta/servlet/http/TestHttpServlet.java
index de2ae94..2473799 100644
--- a/test/jakarta/servlet/http/TestHttpServlet.java
+++ b/test/jakarta/servlet/http/TestHttpServlet.java
@@ -22,6 +22,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import jakarta.servlet.Servlet;
 import jakarta.servlet.ServletException;
 
 import org.junit.Assert;
@@ -157,6 +158,39 @@ public class TestHttpServlet extends TomcatBaseTest {
     }
 
 
+    @Test
+    public void testDoOptions() throws Exception {
+        doTestDoOptions(new OptionsServlet(), "GET, HEAD, OPTIONS");
+    }
+
+
+    @Test
+    public void testDoOptionsSub() throws Exception {
+        doTestDoOptions(new OptionsServletSub(), "GET, HEAD, POST, OPTIONS");
+    }
+
+
+    private void doTestDoOptions(Servlet servlet, String expectedAllow) throws 
Exception{
+        Tomcat tomcat = getTomcatInstance();
+
+        // No file system docBase required
+        StandardContext ctx = (StandardContext) tomcat.addContext("", null);
+
+        // Map the test Servlet
+        Tomcat.addServlet(ctx, "servlet", servlet);
+        ctx.addServletMappingDecoded("/", "servlet");
+
+        tomcat.start();
+
+        Map<String,List<String>> resHeaders= new HashMap<>();
+        int rc = methodUrl("http://localhost:"; + getPort() + "/", new 
ByteChunk(),
+               DEFAULT_CLIENT_TIMEOUT_MS, null, resHeaders, "OPTIONS");
+
+        Assert.assertEquals(HttpServletResponse.SC_OK, rc);
+        Assert.assertEquals(expectedAllow, resHeaders.get("Allow").get(0));
+    }
+
+
     private static class Bug57602ServletOuter extends HttpServlet {
 
         private static final long serialVersionUID = 1L;
@@ -204,4 +238,31 @@ public class TestHttpServlet extends TomcatBaseTest {
             pw.println("Data");
         }
     }
+
+
+    private static class OptionsServlet extends HttpServlet {
+
+        private static final long serialVersionUID = 1L;
+
+        @Override
+        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+                throws ServletException, IOException {
+            resp.setContentType("text/plain");
+            resp.setCharacterEncoding("UTF-8");
+            PrintWriter pw = resp.getWriter();
+            pw.print("OK");
+        }
+    }
+
+
+    private static class OptionsServletSub extends OptionsServlet {
+
+        private static final long serialVersionUID = 1L;
+
+        @Override
+        protected void doPost(HttpServletRequest req, HttpServletResponse resp)
+                throws ServletException, IOException {
+            doGet(req, resp);
+        }
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to