diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 12:15:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 12:15:43 +0000 |
commit | f5f56e1a1c4d9e9496fcb9d81131066a964ccd23 (patch) | |
tree | 49e44c6f87febed37efb953ab5485aa49f6481a7 /src/lib/http/tests/response_test.h | |
parent | Initial commit. (diff) | |
download | isc-kea-f5f56e1a1c4d9e9496fcb9d81131066a964ccd23.tar.xz isc-kea-f5f56e1a1c4d9e9496fcb9d81131066a964ccd23.zip |
Adding upstream version 2.4.1.upstream/2.4.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/lib/http/tests/response_test.h')
-rw-r--r-- | src/lib/http/tests/response_test.h | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/lib/http/tests/response_test.h b/src/lib/http/tests/response_test.h new file mode 100644 index 0000000..d342a64 --- /dev/null +++ b/src/lib/http/tests/response_test.h @@ -0,0 +1,62 @@ +// Copyright (C) 2016-2018 Internet Systems Consortium, Inc. ("ISC") +// +// 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/. + +#ifndef HTTP_RESPONSE_TEST_H +#define HTTP_RESPONSE_TEST_H + +#include <http/http_types.h> +#include <http/response.h> +#include <boost/lexical_cast.hpp> +#include <cstdint> + +namespace isc { +namespace http { +namespace test { + +/// @brief Base class for test HTTP response. +template<typename HttpResponseType> +class TestHttpResponseBase : public HttpResponseType { +public: + + /// @brief Constructor. + /// + /// @param version HTTP version for the response. + /// @param status_code HTTP status code. + TestHttpResponseBase(const HttpVersion& version, + const HttpStatusCode& status_code) + : HttpResponseType(version, status_code) { + } + + /// @brief Returns fixed header value. + /// + /// Including fixed header value in the response makes the + /// response deterministic, which is critical for the unit + /// tests. + virtual std::string getDateHeaderValue() const { + return ("Tue, 19 Dec 2016 18:53:35 GMT"); + } + + /// @brief Returns date header value. + std::string generateDateHeaderValue() const { + return (HttpResponseType::getDateHeaderValue()); + } + + /// @brief Sets custom content length. + /// + /// @param content_length Content length value. + void setContentLength(const uint64_t content_length) { + HttpHeaderPtr length_header(new HttpHeader("Content-Length", + boost::lexical_cast<std::string> + (content_length))); + HttpResponseType::headers_["content-length"] = length_header; + } +}; + +} // namespace test +} // namespace http +} // namespace isc + +#endif |