Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Wilkins2015-04-29 04:01:20 +0000
committerGreg Wilkins2015-04-29 04:01:20 +0000
commitd5c95a1302230ba8e20d1fd56dc99b7a3302a256 (patch)
treeaa932f5ff438bd6de74dbb5926764c9d76d5a601
parent6ebfd8832389a85d926b6fb60b86fe343204e657 (diff)
downloadorg.eclipse.jetty.project-d5c95a1302230ba8e20d1fd56dc99b7a3302a256.tar.gz
org.eclipse.jetty.project-d5c95a1302230ba8e20d1fd56dc99b7a3302a256.tar.xz
org.eclipse.jetty.project-d5c95a1302230ba8e20d1fd56dc99b7a3302a256.zip
465747 - Jetty is failing to process all HTTP OPTIONS requests.
The Server handleOptions method was handling all OPTIONS * requests with a blank 200 response. This has been fixed so that this method only checks that * URI is only applied to OPTIONS method.
-rw-r--r--jetty-http/src/main/java/org/eclipse/jetty/http/HttpMethod.java2
-rw-r--r--jetty-server/src/main/java/org/eclipse/jetty/server/Server.java10
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java39
-rw-r--r--jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestFixture.java15
-rw-r--r--tests/test-integration/src/test/java/org/eclipse/jetty/test/support/TestableJettyServer.java2
-rw-r--r--tests/test-integration/src/test/resources/BIOHttp.xml22
-rw-r--r--tests/test-integration/src/test/resources/BIOHttps.xml29
-rw-r--r--tests/test-integration/src/test/resources/NIOHttp.xml2
-rw-r--r--tests/test-integration/src/test/resources/NIOHttps.xml2
9 files changed, 61 insertions, 62 deletions
diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpMethod.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpMethod.java
index 0dd075328f..7904932637 100644
--- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpMethod.java
+++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpMethod.java
@@ -76,7 +76,7 @@ public enum HttpMethod
return HEAD;
break;
case 'O':
- if (bytes[position+1]=='O' && bytes[position+2]=='T' && bytes[position+3]=='I' && length>=8 &&
+ if (bytes[position+1]=='P' && bytes[position+2]=='T' && bytes[position+3]=='I' && length>=8 &&
bytes[position+4]=='O' && bytes[position+5]=='N' && bytes[position+6]=='S' && bytes[position+7]==' ' )
return OPTIONS;
break;
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java
index fe6f847410..96d10b64b6 100644
--- a/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java
+++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java
@@ -487,8 +487,10 @@ public class Server extends HandlerWrapper implements Attributes
if (LOG.isDebugEnabled())
LOG.debug(request.getDispatcherType()+" "+request.getMethod()+" "+target+" on "+connection);
- if ("*".equals(target))
+ if (HttpMethod.OPTIONS.is(request.getMethod()) || "*".equals(target))
{
+ if (!HttpMethod.OPTIONS.is(request.getMethod()))
+ response.sendError(HttpStatus.BAD_REQUEST_400);
handleOptions(request,response);
if (!request.isHandled())
handle(target, request, request, response);
@@ -505,12 +507,6 @@ public class Server extends HandlerWrapper implements Attributes
*/
protected void handleOptions(Request request,Response response) throws IOException
{
- if (!HttpMethod.OPTIONS.is(request.getMethod()))
- response.sendError(HttpStatus.BAD_REQUEST_400);
- request.setHandled(true);
- response.setStatus(200);
- response.setContentLength(0);
- response.closeOutput();
}
/* ------------------------------------------------------------ */
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java
index 5875c526a8..9d0dad20be 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java
@@ -131,6 +131,45 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
}
}
+ @Test
+ public void testOPTIONS() throws Exception
+ {
+ configureServer(new OptionsHandler());
+
+ try (Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort()))
+ {
+ OutputStream os = client.getOutputStream();
+
+ os.write(("OPTIONS * HTTP/1.1\r\n"
+ + "Host: "+_serverURI.getHost()+"\r\n"
+ + "Connection: close\r\n"
+ + "\r\n").getBytes(StandardCharsets.ISO_8859_1));
+ os.flush();
+
+ // Read the response.
+ String response = readResponse(client);
+
+ Assert.assertThat(response, Matchers.containsString("HTTP/1.1 200 OK"));
+ Assert.assertThat(response, Matchers.containsString("Allow: GET"));
+ }
+
+ try (Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort()))
+ {
+ OutputStream os = client.getOutputStream();
+
+ os.write(("GET * HTTP/1.1\r\n"
+ + "Host: "+_serverURI.getHost()+"\r\n"
+ + "Connection: close\r\n"
+ + "\r\n").getBytes(StandardCharsets.ISO_8859_1));
+ os.flush();
+
+ // Read the response.
+ String response = readResponse(client);
+
+ Assert.assertThat(response, Matchers.containsString("HTTP/1.1 400 "));
+ Assert.assertThat(response, Matchers.not(Matchers.containsString("Allow: ")));
+ }
+ }
/*
* Feed a full header method
diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestFixture.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestFixture.java
index 82fff8f4a9..c06034279c 100644
--- a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestFixture.java
+++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestFixture.java
@@ -150,6 +150,21 @@ public class HttpServerTestFixture
}
}
+ protected static class OptionsHandler extends AbstractHandler
+ {
+ @Override
+ public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
+ {
+ baseRequest.setHandled(true);
+ if (request.getMethod().equals("OPTIONS"))
+ response.setStatus(200);
+ else
+ response.setStatus(500);
+
+ response.setHeader("Allow", "GET");
+ }
+ }
+
protected static class HelloWorldHandler extends AbstractHandler
{
@Override
diff --git a/tests/test-integration/src/test/java/org/eclipse/jetty/test/support/TestableJettyServer.java b/tests/test-integration/src/test/java/org/eclipse/jetty/test/support/TestableJettyServer.java
index 5c589d1dd6..43876e8f4b 100644
--- a/tests/test-integration/src/test/java/org/eclipse/jetty/test/support/TestableJettyServer.java
+++ b/tests/test-integration/src/test/java/org/eclipse/jetty/test/support/TestableJettyServer.java
@@ -177,7 +177,7 @@ public class TestableJettyServer
_server.start();
// Find the active server port.
- this._serverPort = ((NetworkConnector)_server.getConnectors()[0]).getPort();
+ this._serverPort = ((NetworkConnector)_server.getConnectors()[0]).getLocalPort();
System.err.println("Server Port="+_serverPort);
Assert.assertTrue("Server Port is between 1 and 65535. Actually <" + _serverPort + ">",(1 <= this._serverPort) && (this._serverPort <= 65535));
}
diff --git a/tests/test-integration/src/test/resources/BIOHttp.xml b/tests/test-integration/src/test/resources/BIOHttp.xml
deleted file mode 100644
index 751a3c2cd0..0000000000
--- a/tests/test-integration/src/test/resources/BIOHttp.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0"?>
-<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
-
-<Configure id="Server" class="org.eclipse.jetty.server.Server">
-
- <!-- =========================================================== -->
- <!-- Set connectors -->
- <!-- =========================================================== -->
-
- <Call name="addConnector">
- <Arg>
- <New class="org.eclipse.jetty.server.bio.SocketConnector">
- <Set name="host"><SystemProperty name="jetty.host" /></Set>
- <Set name="port"><SystemProperty name="jetty.port" default="0"/></Set>
- <Set name="idleTimeout">300000</Set>
- <Set name="Acceptors">2</Set>
- <Set name="statsOn">false</Set>
- </New>
- </Arg>
- </Call>
-
-</Configure>
diff --git a/tests/test-integration/src/test/resources/BIOHttps.xml b/tests/test-integration/src/test/resources/BIOHttps.xml
deleted file mode 100644
index d845957d14..0000000000
--- a/tests/test-integration/src/test/resources/BIOHttps.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-<?xml version="1.0"?>
-<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
-
-<Configure id="Server" class="org.eclipse.jetty.server.Server">
-
- <!-- =========================================================== -->
- <!-- Set connectors -->
- <!-- =========================================================== -->
-
- <Call name="addConnector">
- <Arg>
- <New class="org.eclipse.jetty.server.ssl.SslSocketConnector">
- <Set name="host"><SystemProperty name="jetty.host" /></Set>
- <Set name="port"><SystemProperty name="jetty.port" default="0"/></Set>
- <Set name="idleTimeout">300000</Set>
- <Set name="Acceptors">2</Set>
- <Set name="statsOn">false</Set>
- <Set name="keystore"><Property name="test.resourcesdir" default="src/test/resources" />/keystore</Set>
- <Set name="password">OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4</Set>
- <Set name="keyPassword">OBF:1u2u1wml1z7s1z7a1wnl1u2g</Set>
- <!--
- <Set name="truststore"><Property name="test.resourcesdir" default="src/test/resources" />/keystore</Set>
- <Set name="trustPassword">OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4</Set>
- -->
- </New>
- </Arg>
- </Call>
-
-</Configure>
diff --git a/tests/test-integration/src/test/resources/NIOHttp.xml b/tests/test-integration/src/test/resources/NIOHttp.xml
index 793da7a94d..c766d10596 100644
--- a/tests/test-integration/src/test/resources/NIOHttp.xml
+++ b/tests/test-integration/src/test/resources/NIOHttp.xml
@@ -21,7 +21,7 @@
</Array>
</Arg>
<Set name="host"><Property name="jetty.host" /></Set>
- <Set name="port"><Property name="jetty.port" default="8080" /></Set>
+ <Set name="port">0</Set>
<Set name="idleTimeout"><Property name="http.timeout" default="30000"/></Set>
</New>
</Arg>
diff --git a/tests/test-integration/src/test/resources/NIOHttps.xml b/tests/test-integration/src/test/resources/NIOHttps.xml
index ff42c725fa..5e90fdbd0d 100644
--- a/tests/test-integration/src/test/resources/NIOHttps.xml
+++ b/tests/test-integration/src/test/resources/NIOHttps.xml
@@ -26,7 +26,7 @@
</Array>
</Arg>
<Set name="host"><Property name="jetty.host" /></Set>
- <Set name="port"><Property name="jetty.https.port" default="8443" /></Set>
+ <Set name="port">0</Set>
<Set name="idleTimeout">30000</Set>
</New>
</Arg>

Back to the top