Skip to content

Commit 3b2b51d

Browse files
authored
Add TRACE, CONNECT, and PATCH http methods (#31079)
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.
1 parent 3bc5248 commit 3b2b51d

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

modules/transport-netty4/src/main/java/org/elasticsearch/http/netty4/Netty4HttpRequest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,19 @@ public Method method() {
119119
return Method.OPTIONS;
120120
}
121121

122-
return Method.GET;
122+
if (httpMethod == HttpMethod.PATCH) {
123+
return Method.PATCH;
124+
}
125+
126+
if (httpMethod == HttpMethod.TRACE) {
127+
return Method.TRACE;
128+
}
129+
130+
if (httpMethod == HttpMethod.CONNECT) {
131+
return Method.CONNECT;
132+
}
133+
134+
throw new IllegalArgumentException("Unexpected http method: " + httpMethod);
123135
}
124136

125137
@Override

server/src/main/java/org/elasticsearch/rest/RestRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public RestRequest(
130130
}
131131

132132
public enum Method {
133-
GET, POST, PUT, DELETE, OPTIONS, HEAD
133+
GET, POST, PUT, DELETE, OPTIONS, HEAD, PATCH, TRACE, CONNECT
134134
}
135135

136136
public abstract Method method();

0 commit comments

Comments
 (0)