#include <WEnvironment>
Public Types | |
enum | ContentType { XHTML1, HTML4 } |
Enumeration for HTML content type. More... | |
typedef std::vector < std::string > | ArgumentValues |
Values associated with an argument. | |
typedef std::map < std::string, ArgumentValues > | ArgumentMap |
Argument/value map. | |
typedef std::map < std::string, std::string > | CookieMap |
Cookie map. | |
Public Member Functions | |
const ArgumentMap & | arguments () const |
Arguments passed to the application. | |
const ArgumentValues & | getArgument (const std::string &argument_name) const |
Checks for existence and returns specified argument. | |
const CookieMap & | cookies () const |
Cookies set in the initial call to the application. | |
const std::string | getCookie (const std::string &cookie_name) const |
Checks for existence and returns specified argument. | |
bool | supportsCookies () const |
Returns whether the browser has enabled support for cookies. | |
bool | javaScript () const |
Returns whether the browser has enabled support for JavaScript. | |
bool | ajax () const |
Returns whether the browser has enabled support for AJAX. | |
const std::string & | locale () const |
Returns the preferred language indicated in the request header. | |
const std::string & | hostName () const |
Returns the server host name that is used by the client. | |
const std::string & | urlScheme () const |
Returns the URL scheme used for the current request (http or https). | |
const std::string & | userAgent () const |
Returns the user agent. | |
const std::string & | referer () const |
Returns the referer. | |
const std::string & | accept () const |
Returns the accept header. | |
bool | agentIsSpiderBot () const |
Returns if it is a (known) indexing spider bot. | |
const std::string & | serverSignature () const |
Web server signature. | |
const std::string & | serverSoftware () const |
Web server software. | |
const std::string & | serverAdmin () const |
Email address of the server admin. | |
const std::string & | clientAddress () const |
IP address of the client. | |
std::string | libraryVersion () const |
Version of the Wt library. | |
void | libraryVersion (int &series, int &major, int &minor) const |
Version of the Wt library, broken down. | |
std::string | sessionId () const |
Get the Wt session id. | |
std::string | getCgiValue (const std::string &varName) const |
Get a raw CGI environment variable. | |
ContentType | contentType () const |
The type of the content provided to the browser. |
The environment provides information on the client, and gives access to startup arguments.
typedef std::vector<std::string> Wt::WEnvironment::ArgumentValues |
Values associated with an argument.
One or more values may be associated with a single argument.
For example a Wt application 'foo.wt' started as http://.../foo.wt?hello=Hello&hello=World will result in both values "Hello" and "World" to be associated with the argument "hello".
typedef std::map<std::string, ArgumentValues> Wt::WEnvironment::ArgumentMap |
Argument/value map.
A std::map which associates an argument name with its set of given values.
typedef std::map<std::string, std::string> Wt::WEnvironment::CookieMap |
Cookie map.
A std::map which associates a cookie name with a cookie value.
const ArgumentMap& Wt::WEnvironment::arguments | ( | ) | const [inline] |
Arguments passed to the application.
Arguments passed to the application, either in the URL for a http GET, or in both the URL and data submitted in a http POST.
const WEnvironment::ArgumentValues & Wt::WEnvironment::getArgument | ( | const std::string & | argument_name | ) | const |
Checks for existence and returns specified argument.
Throws a std::runtime_error("missing argument: argument_name") when the argument is missing or returns the vector of values otherwise.
const CookieMap& Wt::WEnvironment::cookies | ( | ) | const [inline] |
Cookies set in the initial call to the application.
Note that cookies set with WApplication::setCookie() are not made available in the environment.
Not all clients may support cookies or have cookies enabled. See supportsCookies()
const std::string Wt::WEnvironment::getCookie | ( | const std::string & | cookie_name | ) | const |
Checks for existence and returns specified argument.
Throws a std::runtime_error("missing cookie: cookie_name") when the cookie is missing, or returns cookie value otherwise.
bool Wt::WEnvironment::supportsCookies | ( | ) | const [inline] |
Returns whether the browser has enabled support for cookies.
When the user disables cookies during the visit of the page, this value is not updated.
bool Wt::WEnvironment::javaScript | ( | ) | const [inline] |
Returns whether the browser has enabled support for JavaScript.
Without support for JavaScript, Wt will still be able to serve the application, but with one considerable limitation: only the WTimer::timeout and WInteractWidget::clicked signals will generate events. Every click will cause a complete page refresh.
bool Wt::WEnvironment::ajax | ( | ) | const [inline] |
Returns whether the browser has enabled support for AJAX.
Without support for JavaScript, Wt will still be able to serve the application, but every event will cause the application to retransmit the whole page, rendering many events inpractical.
const std::string& Wt::WEnvironment::locale | ( | ) | const [inline] |
Returns the preferred language indicated in the request header.
The language is parsed from the HTTP Accept-Language field, if present. If not, the locale is empty.
If multiple languages are present, the one with the highest "q"uality is assumed, and if a tie is present, the first one is taken.
const std::string& Wt::WEnvironment::hostName | ( | ) | const [inline] |
Returns the server host name that is used by the client.
The hostname is the unresolved host name with optional port number, which the browser used to connect to the application.
e.g. www.mydomain.com e.g. localhost:8080
for HTTP 1.1 requests, this information is fetched from the HTTP Host header. If Wt is configured behind a reverse proxy, then the last entry in the HTTP X-Forwarded-Host header field is used instead (to infer the name of the reverse proxy instead).
For HTTP 1.0 requests, the HTTP Host header is not required. When not present, the server host name is inferred from the configured server name, which defaults to the DNS name.
const std::string& Wt::WEnvironment::userAgent | ( | ) | const [inline] |
Returns the user agent.
The user agent, as reported in the HTTP User-Agent field.
const std::string& Wt::WEnvironment::referer | ( | ) | const [inline] |
Returns the referer.
The referer, as reported in the HTTP Referer field.
const std::string& Wt::WEnvironment::accept | ( | ) | const [inline] |
Returns the accept header.
The accept header, as reported in the HTTP Accept field.
bool Wt::WEnvironment::agentIsSpiderBot | ( | ) | const |
Returns if it is a (known) indexing spider bot.
Note: currently the list of know bots is quite small. This method is used internally to skip the default browser capabilities detection step since the spider usually takes too long to follow the link, and then the session has timed out.
const std::string& Wt::WEnvironment::serverSignature | ( | ) | const [inline] |
Web server signature.
The value of the CGI variable SERVER_SIGNATURE. e.g. <address>Apache Server at localhost Port 80</address>
const std::string& Wt::WEnvironment::serverSoftware | ( | ) | const [inline] |
Web server software.
The value of the CGI variable SERVER_SOFTWARE. e.g. Apache
const std::string& Wt::WEnvironment::serverAdmin | ( | ) | const [inline] |
Email address of the server admin.
The value of the CGI variable SERVER_ADMIN. e.g. root@localhost
const std::string& Wt::WEnvironment::clientAddress | ( | ) | const [inline] |
IP address of the client.
The (most likely) IP address of the client that is connected to this session.
This is taken to be the first public address that is given in the Client-IP header, or in the X-Forwarded-For header (in case the client is behind a proxy). If none of these headers is present, the remote socket IP address is used.
std::string Wt::WEnvironment::libraryVersion | ( | ) | const |
Version of the Wt library.
The version of the Wt library. e.g. 1.99.2
void Wt::WEnvironment::libraryVersion | ( | int & | series, | |
int & | major, | |||
int & | minor | |||
) | const |
Version of the Wt library, broken down.
The version of the Wt library, broken down in its three numbers, e.g. series = 1, major = 99, minor = 2.
std::string Wt::WEnvironment::sessionId | ( | ) | const |
Get the Wt session id.
Retrieves the session Id for this session. This is an auto-generated random alpha-numerical id, whose length is determined by settings in the configuration file.
std::string Wt::WEnvironment::getCgiValue | ( | const std::string & | varName | ) | const |
Get a raw CGI environment variable.
Retrieves the value for the given CGI environment variable (like SSL_CLIENT_S_DN_CN), if it is defined, otherwise an empty string.
ContentType Wt::WEnvironment::contentType | ( | ) | const [inline] |
The type of the content provided to the browser.
This is determined by listening to the capabilities of the browser. Xhtml1 is chosen only if the browser reports support for it, and it is allowed in the configuration file (wt_config.xml).
Note that Wt makes also use of common non-standard techniques implemented in every major browser.