forked from artyom-beilis/cppcms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforwarder.h
More file actions
75 lines (64 loc) · 2.49 KB
/
Copy pathforwarder.h
File metadata and controls
75 lines (64 loc) · 2.49 KB
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
66
67
68
69
70
71
72
73
74
75
///////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2008-2012 Artyom Beilis (Tonkikh) <[email protected]>
//
// See accompanying file COPYING.TXT file for licensing details.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef CPPCMS_FORWARDER_H
#define CPPCMS_FORWARDER_H
#include <cppcms/defs.h>
#include <booster/hold_ptr.h>
#include <booster/shared_ptr.h>
#include <booster/noncopyable.h>
#include <booster/thread.h>
#include <string>
#include <map>
namespace cppcms {
class mount_point;
namespace http {
class context;
}
///
/// \brief Class responsble for automaticall forwarding of HTTP/CGI requests to other hosts over SCGI.
///
/// This class allows you to strasfer connections transparently and efficiently for specific applications
/// like single server responsible for Comet processing
///
class CPPCMS_API forwarder {
public:
/// \cond INTERNAL
forwarder();
~forwarder();
typedef std::pair<std::string,int> address_type;
address_type check_forwading_rules(std::string const &h,std::string const &s,std::string const &p);
address_type check_forwading_rules(char const *h,char const *s,char const *p);
/// \endcond
///
/// Add forwarding of request that match a mount_point \a p over SCGI \a ip and \a port.
///
void add_forwarding_rule(booster::shared_ptr<mount_point> p,std::string const &ip,int port);
///
/// Remove the forwarding request, you need to use smake pointer you used in add_forwarding_rule
///
void remove_forwarding_rule(booster::shared_ptr<mount_point> p);
private:
typedef std::map<booster::shared_ptr<mount_point> ,address_type> rules_type;
rules_type rules_;
booster::shared_mutex mutex_;
struct _data;
booster::hold_ptr<_data> d;
};
///
/// Forward the connection handled by \a cont to other node at IP \a ip listenning to on port \a port over
/// SCGI protocol.
///
/// The context must be released first by calling cppcms::application::release_context() and it should not
/// be used after this function call.
///
/// Please note: forwarding would not work for POST requests with multipart/form-data Content type as they
/// are stored and managed differently.
///
void CPPCMS_API forward_connection(booster::shared_ptr<http::context> cont,std::string const &ip,int port);
}
#endif