From e565c972f05445eca6f990c4de9efe0a2f7a2f10 Mon Sep 17 00:00:00 2001 From: Dan Cunningham Date: Wed, 28 Apr 2021 00:12:01 -0700 Subject: [PATCH] [openhabcloud] Accept all Jetty supported http method types (#10600) * Accept all Jetty supported http method types This fixes a number of open issues due to the fact that we were only accepting a limited number of http method types. The effect of this was some functionality like DELETE or HEAD requests would just not work when using the cloud service, which madee our UI look broken in different ways, also it poluted the users log with a lot of messages. Fixes https://github.com/openhab/openhab-core/issues/2312 Fixes https://github.com/openhab/openhab-cloud/issues/328 Signed-off-by: Dan Cunningham Signed-off-by: John Marshall --- .../io/openhabcloud/internal/CloudClient.java | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/bundles/org.openhab.io.openhabcloud/src/main/java/org/openhab/io/openhabcloud/internal/CloudClient.java b/bundles/org.openhab.io.openhabcloud/src/main/java/org/openhab/io/openhabcloud/internal/CloudClient.java index 47ce5cb548034..54b6e1ae93b25 100644 --- a/bundles/org.openhab.io.openhabcloud/src/main/java/org/openhab/io/openhabcloud/internal/CloudClient.java +++ b/bundles/org.openhab.io.openhabcloud/src/main/java/org/openhab/io/openhabcloud/internal/CloudClient.java @@ -315,20 +315,15 @@ private void handleRequestEvent(JSONObject data) { proto = data.getString("protocol"); } request.header("X-Forwarded-Proto", proto); - - if (requestMethod.equals("GET")) { - request.method(HttpMethod.GET); - } else if (requestMethod.equals("POST")) { - request.method(HttpMethod.POST); - request.content(new BytesContentProvider(requestBody.getBytes())); - } else if (requestMethod.equals("PUT")) { - request.method(HttpMethod.PUT); - request.content(new BytesContentProvider(requestBody.getBytes())); - } else { - // TODO: Reject unsupported methods - logger.warn("Unsupported request method {}", requestMethod); + HttpMethod method = HttpMethod.fromString(requestMethod); + if (method == null) { + logger.debug("Unsupported request method {}", requestMethod); return; } + request.method(method); + if (!requestBody.isEmpty()) { + request.content(new BytesContentProvider(requestBody.getBytes())); + } request.onResponseHeaders(response -> { logger.debug("onHeaders {}", requestId);