Class SecureSSLRedirector

Synopsis

#include <lib/inc/drogon/plugins/SecureSSLRedirector.h>

class DROGON_EXPORT SecureSSLRedirector
    : public drogon::Plugin<SecureSSLRedirector>

Description

This plugin is used to redirect all non-HTTPS requests to HTTPS (except for those URLs matching a regular expression listed in the 'ssl_redirect_exempt' list).

The json configuration is as follows:

{
   "name": "drogon::plugin::SecureSSLRedirector",
   "dependencies": [],
   "config": {
         "ssl_redirect_exempt": ["^/.*\\.jpg", ...],
         "secure_ssl_host": "localhost:8849"
   }
}

ssl_redirect_exempt: a regular expression (for matching the path of a request) list for URLs that don't have to be redirected. secure_ssl_host: If this string is not empty, all SSL redirects will be directed to this host rather than the originally-requested host.

Enable the plugin by adding the configuration to the list of plugins in the configuration file.

Inheritance

Ancestors: Plugin

Methods

SecureSSLRedirector
initAndStartThis method must be called by drogon to initialize and start the plugin
shutdownThis method must be called by drogon to shutdown the plugin

Source

Lines 44-66 in lib/inc/drogon/plugins/SecureSSLRedirector.h.

class DROGON_EXPORT SecureSSLRedirector
    : public drogon::Plugin<SecureSSLRedirector>
{
  public:
    SecureSSLRedirector()
    {
    }
    /// This method must be called by drogon to initialize and start the plugin.
    /// It must be implemented by the user.
    virtual void initAndStart(const Json::Value &config) override;

    /// This method must be called by drogon to shutdown the plugin.
    /// It must be implemented by the user.
    virtual void shutdown() override;

  private:
    HttpResponsePtr redirectingAdvice(const HttpRequestPtr &) const;
    HttpResponsePtr redirectToSSL(const HttpRequestPtr &) const;

    std::regex exemptPegex_;
    bool regexFlag_{false};
    std::string secureHost_;
};





Add Discussion as Guest

Log in