From c9b353dba030c0d952459be45c421eabc97b14c4 Mon Sep 17 00:00:00 2001 From: Tim Brooks Date: Mon, 4 Jun 2018 09:31:33 -0600 Subject: [PATCH] Add TRACE, CONNECT, and PATCH http methods This is related to #31017. That issue identified that these three http methods were treated like GET requests. This commit adds them to RestRequest. This means that these methods will be handled properly and generate 405s. --- .../http/netty4/Netty4HttpRequest.java | 14 +++++++++++++- .../java/org/elasticsearch/rest/RestRequest.java | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpRequest.java b/modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpRequest.java index 5194c762b7e43..2ce6ffada67f0 100644 --- a/modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpRequest.java +++ b/modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpRequest.java @@ -119,7 +119,19 @@ public Method method() { return Method.OPTIONS; } - return Method.GET; + if (httpMethod == HttpMethod.PATCH) { + return Method.PATCH; + } + + if (httpMethod == HttpMethod.TRACE) { + return Method.TRACE; + } + + if (httpMethod == HttpMethod.CONNECT) { + return Method.CONNECT; + } + + throw new IllegalArgumentException("Unexpected http method: " + httpMethod); } @Override diff --git a/server/src/main/java/org/elasticsearch/rest/RestRequest.java b/server/src/main/java/org/elasticsearch/rest/RestRequest.java index bd46a20f31231..65b4f9d1d3614 100644 --- a/server/src/main/java/org/elasticsearch/rest/RestRequest.java +++ b/server/src/main/java/org/elasticsearch/rest/RestRequest.java @@ -130,7 +130,7 @@ public RestRequest( } public enum Method { - GET, POST, PUT, DELETE, OPTIONS, HEAD + GET, POST, PUT, DELETE, OPTIONS, HEAD, PATCH, TRACE, CONNECT } public abstract Method method();