44f4e59b6b
This avoids depending on LOOLWSD's statics, which makes adding unit-tests much more difficult due to the high number of dependencies LOOLWSD pulls. Adds a number of unit-tests for RequestDetails. Change-Id: I9f1d56f80a633505c7ff548ec0e33ffe61f59f53 Reviewed-on: https://gerrit.libreoffice.org/c/online/+/95290 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Tested-by: Jenkins Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
101 lines
2.6 KiB
C++
101 lines
2.6 KiB
C++
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
|
/*
|
|
* This file is part of the LibreOffice project.
|
|
*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <Poco/Net/HTTPRequest.h>
|
|
|
|
#include <common/StringVector.hpp>
|
|
#include <common/Util.hpp>
|
|
|
|
/**
|
|
* A class to encapsulate various useful pieces from the request.
|
|
* as well as path parsing goodness.
|
|
*/
|
|
class RequestDetails
|
|
{
|
|
bool _isGet : 1;
|
|
bool _isHead : 1;
|
|
bool _isProxy : 1;
|
|
bool _isWebSocket : 1;
|
|
bool _isMobile : 1;
|
|
std::string _uriString;
|
|
std::string _proxyPrefix;
|
|
std::string _hostUntrusted;
|
|
std::string _documentURI;
|
|
StringVector _pathSegs;
|
|
public:
|
|
RequestDetails(Poco::Net::HTTPRequest &request, const std::string& serviceRoot);
|
|
RequestDetails(const std::string &mobileURI);
|
|
// matches the WOPISrc if used. For load balancing
|
|
// must be 2nd element in the path after /lool/<here>
|
|
std::string getDocumentURI() const;
|
|
std::string getURI() const
|
|
{
|
|
return _uriString;
|
|
}
|
|
bool isProxy() const
|
|
{
|
|
return _isProxy;
|
|
}
|
|
const std::string getProxyPrefix() const
|
|
{
|
|
return _proxyPrefix;
|
|
}
|
|
const std::string getHostUntrusted() const
|
|
{
|
|
return _hostUntrusted;
|
|
}
|
|
bool isWebSocket() const
|
|
{
|
|
return _isWebSocket;
|
|
}
|
|
bool isGet() const
|
|
{
|
|
return _isGet;
|
|
}
|
|
bool isGet(const char *path) const
|
|
{
|
|
return _isGet && _uriString == path;
|
|
}
|
|
bool isGetOrHead(const char *path) const
|
|
{
|
|
return (_isGet || _isHead) && _uriString == path;
|
|
}
|
|
bool startsWith(const char *path)
|
|
{
|
|
return Util::startsWith(_uriString, path);
|
|
}
|
|
bool equals(size_t index, const char *string) const
|
|
{
|
|
return _pathSegs.equals(index, string);
|
|
}
|
|
std::string operator[](size_t index) const
|
|
{
|
|
return _pathSegs[index];
|
|
}
|
|
size_t size() const
|
|
{
|
|
return _pathSegs.size();
|
|
}
|
|
std::string toString() const
|
|
{
|
|
std::ostringstream oss;
|
|
oss << _uriString << ' ' << (_isGet?"G":"")
|
|
<< (_isHead?"H":"") << (_isProxy?"Proxy":"")
|
|
<< (_isWebSocket?"WebSocket":"");
|
|
oss << " host: " << _hostUntrusted;
|
|
oss << " path: " << _pathSegs.size();
|
|
for (size_t i = 0; i < _pathSegs.size(); ++i)
|
|
oss << " '" << _pathSegs[i] << "'";
|
|
return oss.str();
|
|
}
|
|
};
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|