diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 71fcc86d..29c0367a 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -3,7 +3,7 @@ All notable changes to this project will be documented in this file. ## [6.2.8] - 2019-09-26 -- Http server: add options to ws https to redirect all requests to a given url. +- Http server: add options to ws https to redirect all requests to a given url. POST requests will get a 200 and an empty response. ``` ws httpd -L --redirect_url https://www.google.com diff --git a/ws/ws_httpd.cpp b/ws/ws_httpd.cpp index aad3cbba..52714116 100644 --- a/ws/ws_httpd.cpp +++ b/ws/ws_httpd.cpp @@ -31,7 +31,21 @@ namespace ix [redirectUrl]( HttpRequestPtr request, std::shared_ptr /*connectionState*/) -> HttpResponsePtr { + WebSocketHttpHeaders headers; + + // Log request + std::stringstream ss; + ss << request->method << " " << request->headers["User-Agent"] << " " + << request->uri; + spdlog::info(ss.str()); + + if (request->method == "POST") + { + return std::make_shared( + 200, "OK", HttpErrorCode::Ok, headers, std::string()); + } + headers["Location"] = redirectUrl; return std::make_shared(