killpoco: use http::Response in admin file serving
Change-Id: I9ad49002bc85071770aba08c23e0210bb10ff55b Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>pull/8581/head
parent
4dfb7ee312
commit
a48917d052
|
@ -440,8 +440,11 @@ public:
|
|||
/// Return true iff Transfer-Encoding is set to chunked (the last entry).
|
||||
bool getChunkedTransferEncoding() const { return _chunked; }
|
||||
|
||||
/// Adds a new "Cookie" header entry with the given cookies.
|
||||
void addCookies(const Container& pairs)
|
||||
/// Adds a new "Cookie" header entry with the given content.
|
||||
void addCookie(const std::string& cookie) { add(COOKIE, cookie); }
|
||||
|
||||
/// Adds a new "Cookie" header entry with the given pairs.
|
||||
void addCookie(const Container& pairs)
|
||||
{
|
||||
std::string s;
|
||||
s.reserve(256);
|
||||
|
@ -853,6 +856,7 @@ public:
|
|||
|
||||
const StatusLine& statusLine() const { return _statusLine; }
|
||||
|
||||
Header& header() { return _header; }
|
||||
const Header& header() const { return _header; }
|
||||
|
||||
/// Add an HTTP header field.
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
#include <sys/poll.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <Poco/Net/HTTPCookie.h>
|
||||
#include <Poco/Net/HTTPRequest.h>
|
||||
#include <Poco/Net/HTTPResponse.h>
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "COOLWSD.hpp"
|
||||
#include "Exceptions.hpp"
|
||||
#include "FileUtil.hpp"
|
||||
#include "HttpRequest.hpp"
|
||||
#include "RequestDetails.hpp"
|
||||
#include "ServerURL.hpp"
|
||||
#include <Common.hpp>
|
||||
|
@ -265,8 +266,7 @@ bool FileServerRequestHandler::isAdminLoggedIn(const Poco::Net::HTTPRequest& req
|
|||
}
|
||||
|
||||
bool FileServerRequestHandler::authenticateAdmin(const Poco::Net::HTTPBasicCredentials& credentials,
|
||||
Poco::Net::HTTPResponse& response,
|
||||
std::string& jwtToken)
|
||||
http::Response& response, std::string& jwtToken)
|
||||
{
|
||||
assert(COOLWSD::AdminEnabled);
|
||||
|
||||
|
@ -304,37 +304,18 @@ bool FileServerRequestHandler::authenticateAdmin(const Poco::Net::HTTPBasicCrede
|
|||
// bundlify appears to add an extra /dist -> dist/dist/admin
|
||||
cookie.setPath(COOLWSD::ServiceRoot + "/browser/dist/");
|
||||
cookie.setSecure(COOLWSD::isSSLEnabled());
|
||||
response.addCookie(cookie);
|
||||
response.header().addCookie(cookie.toString());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool FileServerRequestHandler::isAdminLoggedIn(const HTTPRequest& request,
|
||||
HTTPResponse &response)
|
||||
bool FileServerRequestHandler::isAdminLoggedIn(const HTTPRequest& request, http::Response& response)
|
||||
{
|
||||
std::string jwtToken;
|
||||
return isAdminLoggedIn(request, jwtToken) ||
|
||||
authenticateAdmin(Poco::Net::HTTPBasicCredentials(request), response, jwtToken);
|
||||
}
|
||||
|
||||
bool FileServerRequestHandler::isAdminLoggedIn(const HTTPRequest& request, http::Response& response)
|
||||
{
|
||||
// For now, we reuse the exiting implementation, which uses Poco HTTPCookie.
|
||||
Poco::Net::HTTPResponse pocoResponse;
|
||||
if (isAdminLoggedIn(request, pocoResponse))
|
||||
{
|
||||
// Copy the headers, including the cookies.
|
||||
for (const auto& pair : pocoResponse)
|
||||
{
|
||||
response.set(pair.first, pair.second);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#if ENABLE_DEBUG
|
||||
// Represents basic file's attributes.
|
||||
// Used for localFile
|
||||
|
@ -1566,7 +1547,7 @@ void FileServerRequestHandler::preprocessAdminFile(const HTTPRequest& request,
|
|||
if (!COOLWSD::AdminEnabled)
|
||||
throw Poco::FileAccessDeniedException("Admin console disabled");
|
||||
|
||||
Poco::Net::HTTPResponse response;
|
||||
http::Response response(http::StatusCode::OK);
|
||||
std::string jwtToken;
|
||||
if (!isAdminLoggedIn(request, jwtToken))
|
||||
{
|
||||
|
@ -1646,13 +1627,8 @@ void FileServerRequestHandler::preprocessAdminFile(const HTTPRequest& request,
|
|||
response.set("Server", http::getServerString());
|
||||
response.set("Date", Util::getHttpTimeNow());
|
||||
|
||||
response.setContentType("text/html");
|
||||
response.setChunkedTransferEncoding(false);
|
||||
|
||||
std::ostringstream oss;
|
||||
response.write(oss);
|
||||
oss << templateFile;
|
||||
socket->send(oss.str());
|
||||
response.setBody(std::move(templateFile));
|
||||
socket->send(response);
|
||||
}
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
|
|
@ -144,12 +144,11 @@ public:
|
|||
static bool isAdminLoggedIn(const Poco::Net::HTTPRequest& request, std::string& jwtToken);
|
||||
|
||||
/// Evaluate if the cookie exists, and if not, ask for the credentials.
|
||||
static bool isAdminLoggedIn(const Poco::Net::HTTPRequest& request, Poco::Net::HTTPResponse& response);
|
||||
static bool isAdminLoggedIn(const Poco::Net::HTTPRequest& request, http::Response& response);
|
||||
|
||||
/// Authenticate the admin.
|
||||
static bool authenticateAdmin(const Poco::Net::HTTPBasicCredentials& credentials,
|
||||
Poco::Net::HTTPResponse& response, std::string& jwtToken);
|
||||
http::Response& response, std::string& jwtToken);
|
||||
|
||||
static void handleRequest(const Poco::Net::HTTPRequest& request,
|
||||
const RequestDetails& requestDetails,
|
||||
|
|
Loading…
Reference in New Issue