Skip to content

Commit

Permalink
-wip refactoring 2
Browse files Browse the repository at this point in the history
  • Loading branch information
kamchatka-volcano committed Jul 14, 2024
1 parent fe30c1b commit 1343bf4
Show file tree
Hide file tree
Showing 20 changed files with 64 additions and 27 deletions.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,8 @@ endif()

if (ASYNCGI_USE_BOOST_ASIO)
target_compile_definitions(asyncgi PUBLIC "ASYNCGI_USE_BOOST_ASIO")
endif()
endif()

if (ASYNCGI_DISABLE_GLOBAL_HTTP_NAMESPACE)
target_compile_definitions(asyncgi PUBLIC "ASYNCGI_DISABLE_GLOBAL_HTTP_NAMESPACE")
endif ()
2 changes: 0 additions & 2 deletions examples/example_client.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include <asyncgi/asyncgi.h>
#include <iostream>

using namespace asyncgi;

int main()
{
auto io = asyncgi::IO{};
Expand Down
2 changes: 0 additions & 2 deletions examples/example_client_in_processor.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include <asyncgi/asyncgi.h>

namespace http = asyncgi::http;

struct RequestPage{
void operator()(const http::Request&, asyncgi::Responder& responder)
{
Expand Down
1 change: 0 additions & 1 deletion examples/example_guestbook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <optional>
#include <regex>

namespace http = asyncgi::http;
using namespace std::string_literals;

enum class AccessRole {
Expand Down
2 changes: 0 additions & 2 deletions examples/example_hello_world.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include <asyncgi/asyncgi.h>

namespace http = asyncgi::http;

int main()
{
auto io = asyncgi::IO{};
Expand Down
2 changes: 0 additions & 2 deletions examples/example_request_processor.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include <asyncgi/asyncgi.h>

namespace http = asyncgi::http;

http::Response guestBookPage(const http::Request& request)
{
if (request.path() == "/")
Expand Down
25 changes: 25 additions & 0 deletions examples/example_request_processor_fastcgi_types.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <asyncgi/asyncgi.h>

fastcgi::Response guestBookPage(const fastcgi::Request& request)
{
if (request.param("REQUEST_URI") == "/")
return {"Status: 200 OK \r\n"
"Content-Type: text/html\r\n"
"\r\n"
"<h1>Guest book</h1>\n"
"<p>No messages</p>\n"};
return {"Status: 404 Not found\r\n\r\n"};
}

int main()
{
auto io = asyncgi::IO{};
auto server = asyncgi::Server{io, guestBookPage};
#ifndef _WIN32
server.listen("/tmp/fcgi.sock");
#else
server.listen("127.0.0.1", 9088);
#endif
io.run();
return 0;
}
2 changes: 0 additions & 2 deletions examples/example_response_dispatching_asio_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ namespace asio = boost::asio;
#include <asio/steady_timer.hpp>
#endif

namespace http = asyncgi::http;

struct DelayedPage {
void operator()(const http::Request&, asyncgi::Responder& responder)
{
Expand Down
2 changes: 0 additions & 2 deletions examples/example_response_wait_future.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include <asyncgi/asyncgi.h>
#include <thread>

using namespace asyncgi;

struct DelayedPage{
void operator()(const http::Request&, asyncgi::Responder& responder)
{
Expand Down
1 change: 0 additions & 1 deletion examples/example_route_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <mutex>
#include <optional>

namespace http = asyncgi::http;
using namespace std::string_literals;

enum class AccessRole {
Expand Down
1 change: 0 additions & 1 deletion examples/example_route_matcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#include <mutex>
#include <optional>

namespace http = asyncgi::http;
using namespace std::string_literals;

enum class AccessRole {
Expand Down
1 change: 0 additions & 1 deletion examples/example_route_params.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <asyncgi/asyncgi.h>
#include <mutex>

using namespace asyncgi;
using namespace std::string_literals;

class GuestBookState {
Expand Down
1 change: 0 additions & 1 deletion examples/example_route_params_user_defined_types.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <asyncgi/asyncgi.h>
#include <mutex>

using namespace asyncgi;
using namespace std::string_literals;

struct MessageNumber {
Expand Down
1 change: 0 additions & 1 deletion examples/example_router.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <asyncgi/asyncgi.h>
#include <mutex>

namespace http = asyncgi::http;
using namespace std::string_literals;

class GuestBookState {
Expand Down
2 changes: 0 additions & 2 deletions examples/example_timer.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include <asyncgi/asyncgi.h>

namespace http = asyncgi::http;

struct Greeter{
Greeter(const int& secondsCounter)
: secondsCounter_{&secondsCounter}
Expand Down
9 changes: 9 additions & 0 deletions functional_tests/request_processor_fastcgi_types/test.toast
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-Launch detached: ../../build/examples/example_request_processor_fastcgi_types
-Wait: 1 sec

-Expect response from "/":
<h1>Guest book</h1>
<p>No messages</p>
---

-Expect status from "/foo": 404
8 changes: 8 additions & 0 deletions include/asyncgi/asyncgi.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,12 @@
#include "server.h"
#include "timer.h"

#ifndef ASYNCGI_DISABLE_GLOBAL_HTTP_NAMESPACE
namespace http = asyncgi::http;
#endif

#ifndef ASYNCGI_DISABLE_GLOBAL_FASTCGI_NAMESPACE
namespace fastcgi = asyncgi::fastcgi;
#endif

#endif //ASYNCGI_H
17 changes: 13 additions & 4 deletions include/asyncgi/asyncgi_fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

namespace asyncgi {
class IO;
class Request;
class Responder;
class Server;
class Client;
Expand All @@ -13,13 +12,23 @@ class TaskContext;
class Timer;

namespace http {
class Request;
class Response;
};
}; //namespace http

namespace fastcgi {
struct Request;
struct Response;
class Request;
class Response;
} //namespace fastcgi

} //namespace asyncgi

#ifndef ASYNCGI_DISABLE_GLOBAL_HTTP_NAMESPACE
namespace http = asyncgi::http;
#endif

#ifndef ASYNCGI_DISABLE_GLOBAL_FASTCGI_NAMESPACE
namespace fastcgi = asyncgi::fastcgi;
#endif

#endif //ASYNCGI_FWD_H
2 changes: 1 addition & 1 deletion include/asyncgi/fastcgi/response.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ResponseData moveOutResponseData(Response&);
class Response {
public:
explicit Response(detail::ResponseView);
Response(std::string data, std::string errorMsg);
Response(std::string data, std::string errorMsg = {});
std::string_view data() const;
std::string_view errorMsg() const;

Expand Down
4 changes: 3 additions & 1 deletion include/asyncgi/requestprocessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ constexpr void checkRequestProcessorSignature()
std::is_same_v<TRequestProcessorReturnType, fastcgi::Response>);
constexpr auto args = TRequestProcessorArgs{};
static_assert(args.size() == 1);
static_assert(std::is_same_v<const http::Request&, typename decltype(sfun::get<0>(args))::type>);
static_assert(
std::is_same_v<const http::Request&, typename decltype(sfun::get<0>(args))::type> ||
std::is_same_v<const fastcgi::Request&, typename decltype(sfun::get<0>(args))::type>);
}
}
} // namespace detail
Expand Down

0 comments on commit 1343bf4

Please sign in to comment.