diff options
Diffstat (limited to 'src/mongo/db/dbwebserver.h')
-rw-r--r-- | src/mongo/db/dbwebserver.h | 167 |
1 files changed, 89 insertions, 78 deletions
diff --git a/src/mongo/db/dbwebserver.h b/src/mongo/db/dbwebserver.h index a7135601221..f5096abc58a 100644 --- a/src/mongo/db/dbwebserver.h +++ b/src/mongo/db/dbwebserver.h @@ -40,99 +40,110 @@ namespace mongo { - class AdminAccess; - class DbWebServer; - class OperationContext; +class AdminAccess; +class DbWebServer; +class OperationContext; - class Prioritizable { - public: - Prioritizable( double p ) : _priority(p) {} - double priority() const { return _priority; } - private: - double _priority; - }; +class Prioritizable { +public: + Prioritizable(double p) : _priority(p) {} + double priority() const { + return _priority; + } - class DbWebHandler : public Prioritizable { - MONGO_DISALLOW_COPYING(DbWebHandler); - public: - DbWebHandler( const std::string& name , double priority , bool requiresREST ); - virtual ~DbWebHandler() {} - - virtual bool handles( const std::string& url ) const { return url == _defaultUrl; } - - virtual bool requiresREST( const std::string& url ) const { return _requiresREST; } - - virtual void handle( OperationContext* txn, - const char *rq, // the full request - const std::string& url, - BSONObj params, - // set these and return them: - std::string& responseMsg, - int& responseCode, - std::vector<std::string>& headers, // if completely empty, content-type: text/html will be added - const SockAddr &from - ) = 0; - - std::string toString() const { return _toString; } - static DbWebHandler * findHandler( const std::string& url ); - - private: - std::string _name; - bool _requiresREST; - - std::string _defaultUrl; - std::string _toString; - - static std::vector<DbWebHandler*> * _handlers; - }; +private: + double _priority; +}; +class DbWebHandler : public Prioritizable { + MONGO_DISALLOW_COPYING(DbWebHandler); + +public: + DbWebHandler(const std::string& name, double priority, bool requiresREST); + virtual ~DbWebHandler() {} + + virtual bool handles(const std::string& url) const { + return url == _defaultUrl; + } + + virtual bool requiresREST(const std::string& url) const { + return _requiresREST; + } + + virtual void handle(OperationContext* txn, + const char* rq, // the full request + const std::string& url, + BSONObj params, + // set these and return them: + std::string& responseMsg, + int& responseCode, + std::vector<std::string>& + headers, // if completely empty, content-type: text/html will be added + const SockAddr& from) = 0; + + std::string toString() const { + return _toString; + } + static DbWebHandler* findHandler(const std::string& url); + +private: + std::string _name; + bool _requiresREST; + + std::string _defaultUrl; + std::string _toString; + + static std::vector<DbWebHandler*>* _handlers; +}; - class WebStatusPlugin : public Prioritizable { - public: - WebStatusPlugin( const std::string& secionName , double priority , const std::string& subheader = "" ); - virtual ~WebStatusPlugin() {} - virtual void run(OperationContext* txn, std::stringstream& ss) = 0; - /** called when web server stats up */ - virtual void init() = 0; +class WebStatusPlugin : public Prioritizable { +public: + WebStatusPlugin(const std::string& secionName, + double priority, + const std::string& subheader = ""); + virtual ~WebStatusPlugin() {} - static void initAll(); - static void runAll(OperationContext* txn, std::stringstream& ss); - private: - std::string _name; - std::string _subHeading; - static std::vector<WebStatusPlugin*> * _plugins; + virtual void run(OperationContext* txn, std::stringstream& ss) = 0; + /** called when web server stats up */ + virtual void init() = 0; - }; + static void initAll(); + static void runAll(OperationContext* txn, std::stringstream& ss); - class DbWebServer : public MiniWebServer { - public: - DbWebServer(const std::string& ip, int port, AdminAccess* webUsers); +private: + std::string _name; + std::string _subHeading; + static std::vector<WebStatusPlugin*>* _plugins; +}; - private: - virtual void doRequest(const char *rq, - std::string url, - std::string& responseMsg, - int& responseCode, - std::vector<std::string>& headers, - const SockAddr &from); +class DbWebServer : public MiniWebServer { +public: + DbWebServer(const std::string& ip, int port, AdminAccess* webUsers); - bool _allowed(OperationContext* txn, - const char* rq, - std::vector<std::string>& headers, - const SockAddr& from); +private: + virtual void doRequest(const char* rq, + std::string url, + std::string& responseMsg, + int& responseCode, + std::vector<std::string>& headers, + const SockAddr& from); - void _rejectREST(std::string& responseMsg, - int& responseCode, - std::vector<std::string>& headers); + bool _allowed(OperationContext* txn, + const char* rq, + std::vector<std::string>& headers, + const SockAddr& from); + void _rejectREST(std::string& responseMsg, + int& responseCode, + std::vector<std::string>& headers); - const std::unique_ptr<AdminAccess> _webUsers; - }; - void webServerListenThread(std::shared_ptr<DbWebServer> dbWebServer); + const std::unique_ptr<AdminAccess> _webUsers; +}; - std::string prettyHostName(); +void webServerListenThread(std::shared_ptr<DbWebServer> dbWebServer); +std::string prettyHostName(); }; |