Commit ea418d25b21de97a6bda4139d526d01dcf71ca8e
1 parent
ddf3333a
cleanup and add todo
Showing
2 changed files
with
13 additions
and
13 deletions
hueplusplus/HttpHandler.cpp
| @@ -223,22 +223,22 @@ std::string HttpHandler::sendHTTPRequest(std::string method, std::string uri, st | @@ -223,22 +223,22 @@ std::string HttpHandler::sendHTTPRequest(std::string method, std::string uri, st | ||
| 223 | std::string request; | 223 | std::string request; |
| 224 | // Protocol reference: https://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html | 224 | // Protocol reference: https://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html |
| 225 | // Request-Line | 225 | // Request-Line |
| 226 | - request.append(method); // Method | ||
| 227 | - request.append(" "); // Separation | ||
| 228 | - request.append(uri); // Request-URI | ||
| 229 | - request.append(" "); // Separation | 226 | + request.append(method); // Method |
| 227 | + request.append(" "); // Separation | ||
| 228 | + request.append(uri); // Request-URI | ||
| 229 | + request.append(" "); // Separation | ||
| 230 | request.append("HTTP/1.0"); // HTTP-Version | 230 | request.append("HTTP/1.0"); // HTTP-Version |
| 231 | - request.append("\r\n"); // Ending | 231 | + request.append("\r\n"); // Ending |
| 232 | // Entities | 232 | // Entities |
| 233 | - request.append("Content-Type:"); // entity-header | ||
| 234 | - request.append(" "); // Separation | ||
| 235 | - request.append(content_type); // media-type | ||
| 236 | - request.append("\r\n"); // Entity ending | ||
| 237 | - request.append("Content-Length:"); // entity-header | ||
| 238 | - request.append(" "); // Separation | 233 | + request.append("Content-Type:"); // entity-header |
| 234 | + request.append(" "); // Separation | ||
| 235 | + request.append(content_type); // media-type | ||
| 236 | + request.append("\r\n"); // Entity ending | ||
| 237 | + request.append("Content-Length:"); // entity-header | ||
| 238 | + request.append(" "); // Separation | ||
| 239 | request.append(std::to_string(body.size())); // length | 239 | request.append(std::to_string(body.size())); // length |
| 240 | request.append("\r\n\r\n"); // Entity ending & Request-Line ending | 240 | request.append("\r\n\r\n"); // Entity ending & Request-Line ending |
| 241 | - request.append(body); // message-body | 241 | + request.append(body); // message-body |
| 242 | request.append("\r\n\r\n"); // Ending | 242 | request.append("\r\n\r\n"); // Ending |
| 243 | 243 | ||
| 244 | return sendGetHTTPBody(request.c_str(), adr, port); | 244 | return sendGetHTTPBody(request.c_str(), adr, port); |
| @@ -259,6 +259,7 @@ std::string HttpHandler::PUTString(std::string uri, std::string content_type, st | @@ -259,6 +259,7 @@ std::string HttpHandler::PUTString(std::string uri, std::string content_type, st | ||
| 259 | return sendHTTPRequest("PUT", uri, content_type, body, adr, port); | 259 | return sendHTTPRequest("PUT", uri, content_type, body, adr, port); |
| 260 | } | 260 | } |
| 261 | 261 | ||
| 262 | +//! \todo Get rid of duplicate code in GETJson, POSTJson and PUTJson | ||
| 262 | Json::Value HttpHandler::GETJson(std::string uri, const Json::Value& body, const std::string &adr, int port) | 263 | Json::Value HttpHandler::GETJson(std::string uri, const Json::Value& body, const std::string &adr, int port) |
| 263 | { | 264 | { |
| 264 | std::string response = GETString(uri, "application/json", body.toStyledString(), adr, port); | 265 | std::string response = GETString(uri, "application/json", body.toStyledString(), adr, port); |