aboutsummaryrefslogtreecommitdiffstats
path: root/include/middleware.h
blob: 5e358afcb0886c799276cc8daf8e86567797edb5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#pragma once
#include "http_request.h"
#include "http_response.h"

namespace crow
{
    // Any middleware requires following 3 members:

    // struct context;
    //      storing data for the middleware; can be read from another middleware or handlers

    // template <typename AllContext>
    // void before_handle(request& req, response& res, context& ctx, AllContext& all_ctx)
    //      called before handling the request.
    //      if res.end() is called, the operation is halted. 
    //      (still call after_handle of this middleware)

    // template <typename AllContext>
    // void after_handle(request& req, response& res, context& ctx, AllContext& all_ctx)
    //      called after handling the request.

    class CookieParser
    {
        struct context
        {
            std::unordered_map<std::string, std::string> jar;
        };

        template <typename AllContext>
        void before_handle(request& req, response& res, context& ctx, AllContext& all_ctx)
        {
            // ctx == all_ctx.bind<CookieParser>()
            // ctx.jar[] = ;
        }

        template <typename AllContext>
        void after_handle(request& req, response& res, context& ctx, AllContext& all_ctx)
        {
        }
    }

    /*
    App<CookieParser, AnotherJarMW> app;
    A B C
    A::context
        int aa;

    ctx1 : public A::context
    ctx2 : public ctx1, public B::context
    ctx3 : public ctx2, public C::context

    C depends on A

    C::handle
        context.aaa

    App::context : private CookieParser::contetx, ... 
    {
        jar

    }

    SimpleApp
    */
}