Fail with correct status code on invalid method
@@ -13,6 +13,7 @@ import java.security.cert.X509Certificate;
import java.util.Enumeration;
import static com.yahoo.jdisc.Response.Status.BAD_REQUEST;
+import static com.yahoo.jdisc.Response.Status.METHOD_NOT_ALLOWED;
import static com.yahoo.jdisc.http.server.jetty.RequestUtils.getConnection;
import static com.yahoo.jdisc.http.server.jetty.RequestUtils.getConnectorLocalPort;
@@ -27,7 +28,7 @@ class HttpRequestFactory {
HttpRequest httpRequest = HttpRequest.newServerRequest(
container,
getUri(servletRequest),
- HttpRequest.Method.valueOf(servletRequest.getMethod()),
+ getMethod(servletRequest),
HttpRequest.Version.fromString(servletRequest.getProtocol()),
new InetSocketAddress(servletRequest.getRemoteAddr(), servletRequest.getRemotePort()),
getConnection((Request) servletRequest).getCreatedTimeStamp());
@@ -39,6 +40,15 @@ class HttpRequestFactory {
}
}
+ private static HttpRequest.Method getMethod(HttpServletRequest servletRequest) {
+ String method = servletRequest.getMethod();
+ try {
+ return HttpRequest.Method.valueOf(method);
+ } catch (IllegalArgumentException e) {
+ throw new RequestException(METHOD_NOT_ALLOWED, "Invalid method '" + method + "'");
+ }
+ }
+
// Implementation based on org.eclipse.jetty.server.Request.getRequestURL(), but with the connector's local port instead
public static URI getUri(HttpServletRequest servletRequest) {
try {
