16 #ifndef IMPALA_UTIL_WEBSERVER_H
17 #define IMPALA_UTIL_WEBSERVER_H
19 #include <squeasel/squeasel.h>
22 #include <boost/function.hpp>
23 #include <boost/thread/shared_mutex.hpp>
24 #include <rapidjson/document.h>
37 typedef boost::function<void (const ArgumentMap& args, rapidjson::Document* json)>
70 const UrlCallback& callback,
bool is_on_nav_bar =
true);
107 const char* message);
115 struct sq_request_info* request_info);
153 #endif // IMPALA_UTIL_WEBSERVER_H
struct sq_context * context_
Handle to Squeasel context; owned and freed by Squeasel internally.
std::map< std::string, UrlHandler > UrlHandlerMap
static const char * ENABLE_RAW_JSON_KEY
string path("/usr/lib/sasl2:/usr/lib64/sasl2:/usr/local/lib/sasl2:/usr/lib/x86_64-linux-gnu/sasl2")
boost::function< void(const ArgumentMap &args, rapidjson::Document *json)> UrlCallback
UrlHandler error_handler_
Catch-all handler for error messages.
Webserver()
Uses FLAGS_webserver_{port, interface}.
void Stop()
Stops the webserver synchronously.
void ErrorHandler(const ArgumentMap &args, rapidjson::Document *document)
Called when an error is encountered, e.g. when a handler for a URI cannot be found.
UrlCallback template_callback_
Callback to produce a Json document to render via a template.
bool is_on_nav_bar() const
void RegisterUrlCallback(const std::string &path, const std::string &template_filename, const UrlCallback &callback, bool is_on_nav_bar=true)
Only one callback may be registered per URL.
std::string template_filename_
std::map< std::string, std::string > ArgumentMap
bool IsSecure() const
True if serving all traffic over SSL, false otherwise.
TNetworkAddress http_address_
The address of the interface on which to run this webserver.
static int LogMessageCallbackStatic(const struct sq_connection *connection, const char *message)
Squeasel callback for log events. Returns squeasel success code.
const UrlCallback & callback() const
void RootHandler(const ArgumentMap &args, rapidjson::Document *document)
Registered to handle "/", populates document with various system-wide information.
void GetCommonJson(rapidjson::Document *document)
UrlHandlerMap url_handlers_
const TNetworkAddress & http_address()
void BuildArgumentMap(const std::string &args, ArgumentMap *output)
const std::string & template_filename() const
boost::shared_mutex url_handlers_lock_
Lock guarding the path_handlers_ map.
bool is_on_nav_bar_
If true, the page appears in the navigation bar.
static int BeginRequestCallbackStatic(struct sq_connection *connection)
int BeginRequestCallback(struct sq_connection *connection, struct sq_request_info *request_info)
Dispatch point for all incoming requests. Returns squeasel success code.
UrlHandler(const UrlCallback &cb, const std::string &template_filename, bool is_on_nav_bar)