2016-04-07 15:59:27 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* 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/.
|
|
|
|
*/
|
2016-04-08 03:08:41 -05:00
|
|
|
#ifndef INCLUDED_UNITHTTP_HPP
|
|
|
|
#define INCLUDED_UNITHTTP_HPP
|
2016-04-07 15:59:27 -05:00
|
|
|
|
2016-04-09 14:39:20 -05:00
|
|
|
#include <Poco/Version.h>
|
2016-04-07 15:59:27 -05:00
|
|
|
#include <Poco/Net/HTTPRequest.h>
|
|
|
|
#include <Poco/Net/HTTPServerParams.h>
|
|
|
|
#include <Poco/Net/HTTPServerRequest.h>
|
|
|
|
#include <Poco/Net/HTTPServerResponse.h>
|
|
|
|
#include <Poco/Net/SocketAddress.h>
|
|
|
|
|
|
|
|
#include "Common.hpp"
|
|
|
|
|
|
|
|
using Poco::Net::SocketAddress;
|
|
|
|
using Poco::Net::HTTPServerParams;
|
|
|
|
|
|
|
|
/// Unit test stub for a server response
|
|
|
|
class UnitHTTPServerResponse : public Poco::Net::HTTPServerResponse
|
|
|
|
{
|
|
|
|
bool _sent;
|
|
|
|
public:
|
|
|
|
UnitHTTPServerResponse() : _sent (false) {}
|
|
|
|
virtual void sendContinue() override {}
|
|
|
|
virtual std::ostream& send() override
|
|
|
|
{ _sent = true; return *(static_cast<std::ostream *>(nullptr)); }
|
|
|
|
virtual void sendFile(const std::string& /* path */,
|
|
|
|
const std::string& /* mediaType */) override {}
|
|
|
|
virtual void sendBuffer(const void* /* pBuffer */,
|
|
|
|
std::size_t /* length */) override {}
|
|
|
|
virtual void redirect(const std::string& /* uri */,
|
|
|
|
HTTPStatus /* status = HTTP_FOUND */) override {}
|
|
|
|
virtual void requireAuthentication(const std::string& /* realm */) override {}
|
|
|
|
virtual bool sent() const override { return _sent; }
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Unit test stub for a server request
|
|
|
|
class UnitHTTPServerRequest : public Poco::Net::HTTPServerRequest
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
UnitHTTPServerResponse &_response;
|
|
|
|
Poco::Net::SocketAddress _clientAddress;
|
|
|
|
Poco::Net::SocketAddress _serverAddress;
|
|
|
|
public:
|
|
|
|
UnitHTTPServerRequest(UnitHTTPServerResponse &inResponse,
|
|
|
|
const std::string &uri)
|
|
|
|
: _response(inResponse),
|
|
|
|
_clientAddress(),
|
2016-05-04 06:06:34 -05:00
|
|
|
_serverAddress(MasterPortNumber)
|
2016-04-07 15:59:27 -05:00
|
|
|
{ setURI(uri); }
|
|
|
|
virtual std::istream& stream() override
|
|
|
|
{ return *(static_cast<std::istream *>(nullptr)); }
|
2016-04-08 01:29:45 -05:00
|
|
|
#if POCO_VERSION < 0x02000000
|
|
|
|
virtual bool expectContinue() const override
|
2016-04-07 15:59:27 -05:00
|
|
|
{ return false; }
|
2016-04-08 01:29:45 -05:00
|
|
|
#endif
|
2016-04-07 19:29:27 -05:00
|
|
|
virtual bool secure() const { return true; }
|
2016-04-07 15:59:27 -05:00
|
|
|
virtual const SocketAddress& clientAddress() const override
|
|
|
|
{ return _clientAddress; }
|
|
|
|
virtual const SocketAddress& serverAddress() const override
|
|
|
|
{ return _serverAddress; }
|
|
|
|
virtual const HTTPServerParams& serverParams() const override
|
|
|
|
{ return *(static_cast<HTTPServerParams *>(nullptr)); }
|
|
|
|
virtual Poco::Net::HTTPServerResponse& response() const override
|
|
|
|
{ return _response; }
|
|
|
|
};
|
|
|
|
|
2016-04-08 03:08:41 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|