From 7ffec5003b998b8870a78d824419d54cab6a0eaa Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Tue, 5 Jan 2016 16:20:37 -0500 Subject: [PATCH] Add PUT REST support, and clean up the bytes calculation for the output JSON data. --- src/server/RestStructs.h | 3 ++- src/server/WebSocket.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/server/RestStructs.h b/src/server/RestStructs.h index 634b1ce..0013eee 100644 --- a/src/server/RestStructs.h +++ b/src/server/RestStructs.h @@ -139,7 +139,8 @@ public: headers << "Date: "+QDateTime::currentDateTime().toString(Qt::ISODate); if(!Header.isEmpty()){ headers << Header; } //Now add the body of the return - if(!Body.isEmpty()){ headers << "Content-Length: "+QString::number(Body.length()); } + qDebug() << "Return JSON:" << Body; + if(!Body.isEmpty()){ headers << "Content-Length: "+QString::number(Body.toUtf8().size()); } //number of bytes for the body headers << Body; return headers.join("\n"); diff --git a/src/server/WebSocket.cpp b/src/server/WebSocket.cpp index b65ae42..1e5987f 100644 --- a/src/server/WebSocket.cpp +++ b/src/server/WebSocket.cpp @@ -117,7 +117,7 @@ void WebSocket::EvaluateREST(QString msg){ void WebSocket::EvaluateRequest(const RestInputStruct &REQ){ RestOutputStruct out; out.in_struct = REQ; - if(!REQ.VERB.isEmpty() && REQ.VERB != "GET" && REQ.VERB!="POST"){ + if(!REQ.VERB.isEmpty() && REQ.VERB != "GET" && REQ.VERB!="POST" && REQ.VERB!="PUT"){ //Non-supported request (at the moment) - return an error message out.CODE = RestOutputStruct::BADREQUEST; }else if(out.in_struct.name.isEmpty() || out.in_struct.namesp.isEmpty() ){