tufao  1.3.0
An asynchronous web framework for C++ built on top of Qt
Tufao::UrlRewriterHandler Class Reference

This class provides a handler to internally (only seen by your application) rewrite the URL. More...

+ Inheritance diagram for Tufao::UrlRewriterHandler:
+ Collaboration diagram for Tufao::UrlRewriterHandler:

Public Slots

bool handleRequest (Tufao::HttpServerRequest &request, Tufao::HttpServerResponse &response) override
 Changes the request url and returns false. More...
 

Public Member Functions

 UrlRewriterHandler (const QUrl &url, QObject *parent=0)
 Constructs a UrlRewriterHandler object. More...
 
void setUrl (const QUrl &url)
 Sets the URL that will replace the old URL to url. More...
 
QUrl url () const
 Returns the url used to replace the old URLs. More...
 
- Public Member Functions inherited from Tufao::AbstractHttpServerRequestHandler
 operator std::function< bool (HttpServerRequest &, HttpServerResponse &)>()
 Implicit conversion operator to std::function functor object. More...
 
virtual bool handleRequest (Tufao::HttpServerRequest &request, Tufao::HttpServerResponse &response)=0
 Handles the request using the response object. More...
 

Static Public Member Functions

static std::function< bool(HttpServerRequest &, HttpServerResponse &)> handler (const QUrl &url)
 Returns a handler that don't depends on another object. More...
 

Detailed Description

This class provides a handler to internally (only seen by your application) rewrite the URL.

Note
The handler does NOT redirects the HTTP client to another path. The new URL can only be seen by the Tufão application itself and HTTP clients will think they are receiving a response to the path they originally asked for.

One place where this technique is useful is when you want to use one file to handle the root page of your site through HttpFileServer. This example is illustrated in the image below:

urlrewrite.png
Url rewrite example
Since
0.6

Constructor & Destructor Documentation

Tufao::UrlRewriterHandler::UrlRewriterHandler ( const QUrl &  url,
QObject *  parent = 0 
)
explicit

Constructs a UrlRewriterHandler object.

parent is passed to the QObject constructor.

url will be the new url.

Since
1.0

Member Function Documentation

static std::function<bool(HttpServerRequest&, HttpServerResponse&)> Tufao::UrlRewriterHandler::handler ( const QUrl &  url)
static

Returns a handler that don't depends on another object.

The purpose of this alternative handler is to free you of the worry of maintain the UrlRewriterHandler's object (lifetime) while the functor object is being used.

Since
1.0
bool Tufao::UrlRewriterHandler::handleRequest ( Tufao::HttpServerRequest request,
Tufao::HttpServerResponse response 
)
overrideslot

Changes the request url and returns false.

This method doesn't do anything else.

Since
1.0
void Tufao::UrlRewriterHandler::setUrl ( const QUrl &  url)

Sets the URL that will replace the old URL to url.

Since
1.0
QUrl Tufao::UrlRewriterHandler::url ( ) const

Returns the url used to replace the old URLs.

Since
1.0

The documentation for this class was generated from the following file: