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