OpenSDN source code
http_server.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 
6 #ifndef __HTTP_SERVER_H__
7 #define __HTTP_SERVER_H__
8 
9 #include <map>
10 #include <string>
11 
12 #include <boost/function.hpp>
13 
14 #include "io/ssl_server.h"
15 #include "base/util.h"
16 
17 #define HTTP_WILDCARD_ENTRY "_match_any_"
18 
19 class EventManager;
20 class HttpRequest;
21 class HttpSession;
22 struct SslConfig {
23  std::string keyfile;
24  std::string certfile;
25  std::string ca_cert;
28 
29  explicit SslConfig()
30  : keyfile(), certfile(), ca_cert(), ssl_enabled(false), ssl_insecure(false) {
31  }
33  }
34 };
35 
36 class HttpServer : public SslServer {
37 public:
38  typedef boost::function<void(HttpSession *session, const HttpRequest *)>
40  explicit HttpServer(EventManager *evm, const SslConfig &config=SslConfig(),
41  uint8_t dscp = 0);
42  virtual ~HttpServer();
43 
44  virtual SslSession *AllocSession(SslSocket *socket);
45  virtual bool AcceptSession(SslSession *session);
46  virtual bool AcceptSession(TcpSession *session);
47 
48  void RegisterHandler(const std::string &path, HttpHandlerFn handler);
49  HttpHandlerFn GetHandler(const std::string &path);
50  void Shutdown();
51  void UpdateDscp(uint8_t value);
52 
53 private:
54  typedef std::map<std::string, HttpHandlerFn> HandlerTrie;
56  uint8_t dscp_value_;
58 };
59 
60 #endif // __HTTP_SERVER_H__
HttpServer(EventManager *evm, const SslConfig &config=SslConfig(), uint8_t dscp=0)
Definition: http_server.cc:13
void RegisterHandler(const std::string &path, HttpHandlerFn handler)
Definition: http_server.cc:103
uint8_t dscp_value_
Definition: http_server.h:56
boost::function< void(HttpSession *session, const HttpRequest *)> HttpHandlerFn
Definition: http_server.h:39
virtual ~HttpServer()
Definition: http_server.cc:68
HttpHandlerFn GetHandler(const std::string &path)
Definition: http_server.cc:107
HandlerTrie http_handlers_
Definition: http_server.h:55
void Shutdown()
Definition: http_server.cc:72
std::map< std::string, HttpHandlerFn > HandlerTrie
Definition: http_server.h:54
virtual bool AcceptSession(SslSession *session)
Definition: http_server.cc:94
virtual SslSession * AllocSession(SslSocket *socket)
Definition: http_server.cc:77
void UpdateDscp(uint8_t value)
Definition: http_server.cc:119
DISALLOW_COPY_AND_ASSIGN(HttpServer)
boost::asio::ssl::stream< boost::asio::ip::tcp::socket > SslSocket
Definition: ssl_server.h:17
static EventManager evm
std::string ca_cert
Definition: http_server.h:25
std::string certfile
Definition: http_server.h:24
bool ssl_enabled
Definition: http_server.h:26
std::string keyfile
Definition: http_server.h:23
bool ssl_insecure
Definition: http_server.h:27