]> git.basschouten.com Git - openhab-addons.git/commitdiff
[openhabcloud] Accept all Jetty supported http method types (#10600)
authorDan Cunningham <dan@digitaldan.com>
Wed, 28 Apr 2021 07:12:01 +0000 (00:12 -0700)
committerGitHub <noreply@github.com>
Wed, 28 Apr 2021 07:12:01 +0000 (09:12 +0200)
* 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 <dan@digitaldan.com>
bundles/org.openhab.io.openhabcloud/src/main/java/org/openhab/io/openhabcloud/internal/CloudClient.java

index 47ce5cb5480343ab6926a912e7ea03f35548a523..54b6e1ae93b251234f2d0e1ec21954181cb5893e 100644 (file)
@@ -315,20 +315,15 @@ public class CloudClient {
                 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);