Skip to content

Commit

Permalink
Merge pull request #37 from martin-olivier/version/5.0.0
Browse files Browse the repository at this point in the history
Version 5.0.0
  • Loading branch information
dhbrojas authored Mar 1, 2022
2 parents 6de700e + 5c51ecb commit 9dbdbb7
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 28 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![Banner](docs/assets/project_banner.png)

[![ZiAPI](https://img.shields.io/badge/ZiAPI-v4.0.0-blue.svg)](https://github.com/martin-olivier/ZiAPI/releases/tag/v4.0.0)
[![ZiAPI](https://img.shields.io/badge/ZiAPI-v5.0.0-blue.svg)](https://github.com/martin-olivier/ZiAPI/releases/tag/v5.0.0)
[![CPP Version](https://img.shields.io/badge/C++-17_and_above-darkgreen.svg)](https://isocpp.org/)
[![Discord](https://img.shields.io/discord/934852777136513075)](https://discord.gg/CzKv6dGXmf)
[![workflow](https://github.com/martin-olivier/ZiAPI/actions/workflows/CI.yml/badge.svg)](https://github.com/martin-olivier/ZiAPI/actions/workflows/CI.yml)
Expand Down Expand Up @@ -38,7 +38,7 @@ include(ExternalProject)
ExternalProject_Add(
ziapi
GIT_REPOSITORY https://github.com/martin-olivier/ZiAPI.git
GIT_TAG v4.0.0
GIT_TAG v5.0.0
INSTALL_COMMAND ""
TEST_COMMAND ""
)
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/LOGGER.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Then, first thing we want is to store the timestamp when the request is received
void PreProcess(ziapi::http::Context &ctx, ziapi::http::Request &req) override
{
ctx["timestamp"] = std::time(nullptr);
// This example is deprecated. The `PostProcess` method has access to the request since version 5.0.0.
ctx["target"] = req.target;
ctx["method"] = req.method;
}
Expand All @@ -76,7 +77,7 @@ And now in the post-process we can just simply access our variables and use them
```cpp
...
void PostProcess(ziapi::http::Context &ctx, ziapi::http::Response &res) override
void PostProcess(ziapi::http::Context &ctx, const ziapi::http::Request &, ziapi::http::Response &res) override
{
std::stringstream ss;
Expand Down
2 changes: 1 addition & 1 deletion docs/general/MODULES.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ The `ShouldPreProcess()` method returns `true` if this module's PreProcess metho
The `PostProcess()` is the method invoked on a response after the handler is called. You can use post-processors to modify the response after it is generated (serializing the body, logging the response, etc...).
```c++
virtual void PostProcess(http::Context &ctx, http::Response &res) = 0;
virtual void PostProcess(http::Context &ctx, const http::Request &, http::Response &res) = 0;
```

The `GetPostProcessorPriority()` method returns the priority of the module between zero and one. Post-processors with a higher priority are executed first!
Expand Down
2 changes: 1 addition & 1 deletion docs/guides/INSTALL_AND_BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ include(ExternalProject)
ExternalProject_Add(
ziapi
GIT_REPOSITORY https://github.com/martin-olivier/ZiAPI.git
GIT_TAG v4.0.0
GIT_TAG v5.0.0
INSTALL_COMMAND ""
TEST_COMMAND ""
)
Expand Down
2 changes: 1 addition & 1 deletion docs/guides/MODULES_101.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ include(ExternalProject)
ExternalProject_Add(
ziapi
GIT_REPOSITORY https://github.com/martin-olivier/ZiAPI.git
GIT_TAG v4.0.0
GIT_TAG v5.0.0
INSTALL_COMMAND ""
TEST_COMMAND ""
)
Expand Down
5 changes: 4 additions & 1 deletion examples/modules/compressor/CompressorModule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ class CompressorModule : public ziapi::IPostProcessorModule {
return "Compress the response body before sending it back to the network";
}

void PostProcess(ziapi::http::Context &, ziapi::http::Response &res) override { res.body = CompressBody(res.body); }
void PostProcess(ziapi::http::Context &, const ziapi::http::Request &, ziapi::http::Response &res) override
{
res.body = CompressBody(res.body);
}

[[nodiscard]] double GetPostProcessorPriority() const noexcept override
{
Expand Down
4 changes: 3 additions & 1 deletion examples/modules/logger/LoggerModule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class LoggerModule : virtual public ziapi::IPreProcessorModule, public ziapi::IP
return true;
}

void PostProcess(ziapi::http::Context &ctx, ziapi::http::Response &res) override
void PostProcess(ziapi::http::Context &ctx, const ziapi::http::Request &, ziapi::http::Response &res) override
{
std::stringstream ss;

Expand All @@ -54,6 +54,8 @@ class LoggerModule : virtual public ziapi::IPreProcessorModule, public ziapi::IP
void PreProcess(ziapi::http::Context &ctx, ziapi::http::Request &req) override
{
ctx["timestamp"] = std::time(nullptr);
/// This example is deprecrated. Storing the target and method is useless because the `PostProcess` method now
/// has access to the request object.
ctx["target"] = req.target;
ctx["method"] = req.method;
}
Expand Down
8 changes: 6 additions & 2 deletions include/ziapi/Http.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ using Context = std::unordered_map<std::string, std::any>;
*/
class IResponseInputQueue {
public:
using ValueType = std::pair<Response, Context>;

virtual ~IResponseInputQueue() = default;

[[nodiscard]] virtual std::optional<std::pair<Response, Context>> Pop() = 0;
[[nodiscard]] virtual std::optional<ValueType> Pop() = 0;

[[nodiscard]] virtual std::size_t Size() const noexcept = 0;

Expand All @@ -82,9 +84,11 @@ class IResponseInputQueue {
*/
class IRequestOutputQueue {
public:
using ValueType = std::pair<Request, Context>;

virtual ~IRequestOutputQueue() = default;

virtual void Push(std::pair<Request, Context> &&req) = 0;
virtual void Push(ValueType &&req) = 0;

[[nodiscard]] virtual std::size_t Size() const noexcept = 0;
};
Expand Down
2 changes: 1 addition & 1 deletion include/ziapi/Module.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class IPostProcessorModule : virtual public IModule {
/**
* Handler invoked during the post-processing pipeline after the handler.
*/
virtual void PostProcess(http::Context &ctx, http::Response &res) = 0;
virtual void PostProcess(http::Context &ctx, const http::Request &req, http::Response &res) = 0;

/**
* Value between zero and one which states the module's priority of
Expand Down
2 changes: 1 addition & 1 deletion tests/Compressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ TEST(Compressor, compressionRate)
res.headers.insert(std::make_pair<std::string, std::string>("Content-Type", "application/json"));

if (compressor.ShouldPostProcess(ctx, req, res)) {
compressor.PostProcess(ctx, res);
compressor.PostProcess(ctx, req, res);
}
ASSERT_EQ(res.body, "not compressed stuf");
}
6 changes: 3 additions & 3 deletions tests/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ TEST(Config, VectorConstructArray)
ASSERT_EQ(n[2].AsDouble(), 1.f);
}

TEST(Config, VectorConstructDict)
TEST(Config, MapConstructDict)
{
std::unordered_map<std::string, Node> vec{{"ten", 10}, {"string", "value"}, {"float", 1.f}, {"null", nullptr}};
Node n = Node::MakeDict(vec);
std::unordered_map<std::string, Node> map{{"ten", 10}, {"string", "value"}, {"float", 1.f}, {"null", nullptr}};
Node n = Node::MakeDict(map);

ASSERT_EQ(n["ten"].AsInt(), 10);
ASSERT_EQ(n["string"].AsString(), "value");
Expand Down
12 changes: 6 additions & 6 deletions tests/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class OSRedirector {
}
};

TEST(Logger, info)
TEST(Logger, Info)
{
OSRedirector os(std::cout);

Expand All @@ -37,7 +37,7 @@ TEST(Logger, info)
std::string::npos);
}

TEST(Logger, warning)
TEST(Logger, Warning)
{
OSRedirector os(std::cout);

Expand All @@ -47,7 +47,7 @@ TEST(Logger, warning)
std::string::npos);
}

TEST(Logger, error)
TEST(Logger, Error)
{
OSRedirector os(std::cerr);

Expand All @@ -57,7 +57,7 @@ TEST(Logger, error)
std::string::npos);
}

TEST(Logger, debug)
TEST(Logger, Debug)
{
OSRedirector os(std::cout);

Expand All @@ -67,12 +67,12 @@ TEST(Logger, debug)
std::string::npos);
}

TEST(Logger, variadic)
TEST(Logger, Variadic)
{
OSRedirector os(std::cout);

ziapi::Logger::Debug("debug", ' ', 1.1);
auto out = os.getContent();
EXPECT_TRUE(out.find(ziapi::color::GREEN + std::string(" [&] ") + ziapi::color::DEFAULT + "debug 1.1") !=
std::string::npos);
}
}
2 changes: 1 addition & 1 deletion tests/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "dylib/dylib.hpp"
#include "ziapi/Logger.hpp"

TEST(Module, example)
TEST(Module, Example)
{
try {
dylib lib("./module", dylib::extension);
Expand Down
12 changes: 6 additions & 6 deletions tests/Version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <gtest/gtest.h>

TEST(Version, equal)
TEST(Version, Equal)
{
ziapi::Version a{1, 0, 3};
ziapi::Version b{1, 0, 3};
Expand All @@ -20,7 +20,7 @@ TEST(Version, equal)
ASSERT_FALSE(a == b);
}

TEST(Version, not_equal)
TEST(Version, NotEqual)
{
ziapi::Version a{1, 0, 0};
ziapi::Version b{1, 0, 0};
Expand All @@ -38,7 +38,7 @@ TEST(Version, not_equal)
ASSERT_TRUE(a != b);
}

TEST(Version, greater)
TEST(Version, Greater)
{
ziapi::Version a{1, 0, 3};
ziapi::Version b{1, 0, 3};
Expand All @@ -56,7 +56,7 @@ TEST(Version, greater)
ASSERT_FALSE(a > b);
}

TEST(Version, less)
TEST(Version, Less)
{
ziapi::Version a{1, 0, 1};
ziapi::Version b{1, 0, 0};
Expand All @@ -74,7 +74,7 @@ TEST(Version, less)
ASSERT_FALSE(a < b);
}

TEST(Version, greater_or_equal)
TEST(Version, GreaterOrEqual)
{
ziapi::Version a{1, 0, 0};
ziapi::Version b{1, 0, 0};
Expand All @@ -92,7 +92,7 @@ TEST(Version, greater_or_equal)
ASSERT_FALSE(a >= b);
}

TEST(Version, less_or_equal)
TEST(Version, LessOrEqual)
{
ziapi::Version a{1, 0, 0};
ziapi::Version b{1, 0, 0};
Expand Down

0 comments on commit 9dbdbb7

Please sign in to comment.