summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Brooks <tim@uncontended.net>2018-06-01 17:07:54 -0600
committerGitHub <noreply@github.com>2018-06-01 17:07:54 -0600
commitf8785dda9df4a79fb0ff4cd23fb5f4fe98acff16 (patch)
tree80b8ae49a08854e9c27ab276b37aeefece30a022
parent2401150be75c1af06c5bcddca4a8d2ea7a4f084a (diff)
Add TRACE, CONNECT, and PATCH http methods (#31035)
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.
-rw-r--r--modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpRequest.java14
-rw-r--r--plugins/transport-nio/src/main/java/org/elasticsearch/http/nio/NioHttpRequest.java14
-rw-r--r--server/src/main/java/org/elasticsearch/rest/RestRequest.java2
3 files changed, 27 insertions, 3 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 5194c762b7..2ce6ffada6 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 class Netty4HttpRequest extends RestRequest {
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/plugins/transport-nio/src/main/java/org/elasticsearch/http/nio/NioHttpRequest.java b/plugins/transport-nio/src/main/java/org/elasticsearch/http/nio/NioHttpRequest.java
index b5bfcc6b0c..4dcd6ba19e 100644
--- a/plugins/transport-nio/src/main/java/org/elasticsearch/http/nio/NioHttpRequest.java
+++ b/plugins/transport-nio/src/main/java/org/elasticsearch/http/nio/NioHttpRequest.java
@@ -84,7 +84,19 @@ public class NioHttpRequest extends RestRequest {
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 bd46a20f31..65b4f9d1d3 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 abstract class RestRequest implements ToXContent.Params {
}
public enum Method {
- GET, POST, PUT, DELETE, OPTIONS, HEAD
+ GET, POST, PUT, DELETE, OPTIONS, HEAD, PATCH, TRACE, CONNECT
}
public abstract Method method();