Public Types | Public Member Functions | Static Public Member Functions

Wt::WEnvironment Class Reference

A class that captures information on the application environment. More...

#include <Wt/WEnvironment>

Inheritance diagram for Wt::WEnvironment:
Inheritance graph
[legend]

List of all members.

Public Types

enum  ContentType { XHTML1, HTML4 }
 

Enumeration for HTML content type.

More...
typedef std::map< std::string,
std::string > 
CookieMap
 Cookie map.

Public Member Functions

const Http::ParameterMapgetParameterMap () const
 Parameters passed to the application.
const Http::ParameterValuesgetParameterValues (const std::string &name) const
 Returns values for a query parameter.
const std::string * getParameter (const std::string &name) const
 Returns a single value for a query parameter.
const CookieMapcookies () const
 Cookies set in the initial call to the application.
const std::string getCookie (const std::string &cookieNname) const
 Checks for existence and returns specified argument.
const std::string headerValue (const std::string &name) const
 Returns a cgi environment header value.
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.
double dpiScale () const
 Returns the browser-side DPI scaling factor.
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 the user agent is a (known) indexing spider bot.
const std::string & serverSignature () const
 Returns the web server signature.
const std::string & serverSoftware () const
 Returns the web server software.
const std::string & serverAdmin () const
 Returns the email address of the server admin.
const std::string & clientAddress () const
 Returns the IP address of the client.
const std::string & pathInfo () const
 Returns the path info of the original request (deprecated)
const std::string & internalPath () const
 Returns the initial internal path.
const std::string & deploymentPath () const
 Returns the deployment path.
void libraryVersion (int &series, int &major, int &minor) const
 Returns the version of the Wt library, broken down.
std::string sessionId () const
 Returns the Wt session id.
std::string getCgiValue (const std::string &varName) const
 Returns a raw CGI environment variable.
ContentType contentType () const
 The type of the content provided to the browser.

Static Public Member Functions

static std::string libraryVersion ()
 Returns the version of the Wt library.

Detailed Description

A class that captures information on the application environment.

The environment provides information on the client, and gives access to startup arguments.

Usage example:

 const WEnvironment& env = WApplication::instance()->environment();

 // read an application startup argument 
 // (passed as argument in the URL or POST'ed to the application).
 if (!env.getParameterValues("login").empty()) {
   std::string login = env.getParameterValues("login")[0];
   ...
 }

 // Check for JavaScript/AJAX availability before using AJAX-only
 // widgets
 Wt::WTextArea *textEdit;
 if (!env.ajax())
   textEdit = new Wt::WTextEdit(); // provide an HTML text editor
 else
   textEdit = new Wt::WTextArea(); // fall-back to a plain old text area.

Member Typedef Documentation

typedef std::map<std::string, std::string> Wt::WEnvironment::CookieMap

Cookie map.

A std::map which associates a cookie name with a cookie value.

See also:
cookies()

Member Enumeration Documentation

Enumeration for HTML content type.

Enumerator:
XHTML1 

XHTML1.x.

HTML4 

HTML4.


Member Function Documentation

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 [inline]

Returns if the user agent is a (known) indexing spider bot.

Note: currently the list of know bots is quite small. This method is used internally to render the web application for optimal indexing by bots:

  • there is no detection for JavaScript, instead the application is directly served assuming no JavaScript support.
  • session information is omitted from the Urls.
  • no sessions are created (they are immediately stopped after the request has been handled).
  • auto-generated id and name attributes are omitted from DOM nodes. In this way, the generated page is always exactly the same.
bool Wt::WEnvironment::ajax (  ) const [inline]

Returns whether the browser has enabled support for AJAX.

Without support for JavaScript/AJAX, Wt will still be able to serve the application, but with one considerable limitation: only the WTimer::timeout(), WInteractWidget::clicked(), WApplication::internalPathChanged(), and WAbstractArea::clicked() signals (and any derived signals) will generate events.

Every event will cause the complete page to be rerendered.

See also:
javaScript()
const std::string& Wt::WEnvironment::clientAddress (  ) const [inline]

Returns the 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.

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.

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 also:
supportsCookies(), getCookie()
const std::string & Wt::WEnvironment::deploymentPath (  ) const

Returns the deployment path.

This is the path at which the application is deployed.

See also:
internalPath().
double Wt::WEnvironment::dpiScale (  ) const [inline]

Returns the browser-side DPI scaling factor.

Internet Explorer scales all graphics, fonts and other elements on high-density screens to make them readable. This is controlled by the DPI setting of the display. If all goes well, you do not have to worry about this scaling factor. Unfortunately, not all elements are scaled appropriately. The scaling factor is supposed to be used only internally in Wt and is in this interface for informational purposes.

See also:
WVmlImage
std::string Wt::WEnvironment::getCgiValue ( const std::string &  varName ) const

Returns 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.

See also:
serverSignature(), serverSoftware(), serverAdmin(),
const std::string Wt::WEnvironment::getCookie ( const std::string &  cookieNname ) const

Checks for existence and returns specified argument.

Throws a std::runtime_error("Missing cookie: ...") when the cookie is missing, or returns cookie value otherwise.

const std::string * Wt::WEnvironment::getParameter ( const std::string &  name ) const

Returns a single value for a query parameter.

Returns the first value for a parameter, or 0 if the parameter is not found.

See also:
getParameterValues()
const Http::ParameterMap& Wt::WEnvironment::getParameterMap (  ) const [inline]

Parameters 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.

See also:
getParameterValues()
const Http::ParameterValues & Wt::WEnvironment::getParameterValues ( const std::string &  name ) const

Returns values for a query parameter.

Returns an empty list if the parameter was not defined.

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".

See also:
getParameterMap()
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.

Examples:

  • www.mydomain.com
  • 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::internalPath (  ) const [inline]

Returns the initial internal path.

This is the internal path with which the application was started.

For an application deployed at "/stuff/app.wt", the following three URLs are considered equivalent, and indicate an internal path "/this/there":

 http://www.mydomain.com/stuff/app.wt/this/there
 http://www.mydomain.com/stuff/app.wt#/this/there
 http://www.mydomain.com/stuff/app.wt?_=/this/there

The last form is generated by Wt when the application ends with a '/', as an alternative to the first form, which is then impossible.

See also:
WApplication::setInternalPath(), deploymentPath()
bool Wt::WEnvironment::javaScript (  ) const [inline]

Returns whether the browser has enabled support for JavaScript.

This is the same as ajax(): Wt only considers using JavaScript when it has detected AJAX support.

See also:
ajax()
std::string Wt::WEnvironment::libraryVersion (  ) [static]

Returns the version of the Wt library.

Example: "1.99.2"

void Wt::WEnvironment::libraryVersion ( int &  series,
int &  major,
int &  minor 
) const

Returns the version of the Wt library, broken down.

The version of the Wt library, broken down in its three numbers,

Example: series = 1, major = 99, minor = 2.

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.

See also:
WApplication::setLocale()
const std::string& Wt::WEnvironment::pathInfo (  ) const [inline]

Returns the path info of the original request (deprecated)

Deprecated:
Use internalPath() instead, which is consistent with the internal paths generated by Wt.

This is the equivalent of the CGI PATH_INFO environment variable.

Assume for example that the application was deployed at "stuff/app.wt". When the user accesses the application using the URL "http://www.mydomain.com/stuff/app.wt", this method would return an empty string (""). When the user accesses the site using "http://www.mydomain.com/stuff/app.wt/this/there", the result would be "/this/there".

Together with getParameter(), this allows you to supply the application with initial information.

See also:
getParameter(), internalPath()
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::serverAdmin (  ) const [inline]

Returns the email address of the server admin.

The value of the CGI variable SERVER_ADMIN.

Example: "root@localhost"

const std::string& Wt::WEnvironment::serverSignature (  ) const [inline]

Returns the web server signature.

The value of the CGI variable SERVER_SIGNATURE.

Example: <address>Apache Server at localhost Port 80</address>.

const std::string& Wt::WEnvironment::serverSoftware (  ) const [inline]

Returns the web server software.

The value of the CGI variable SERVER_SOFTWARE.

Example: "Apache"

std::string Wt::WEnvironment::sessionId (  ) const

Returns 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.

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.

See also:
cookies(), getCookie()
const std::string& Wt::WEnvironment::userAgent (  ) const [inline]

Returns the user agent.

The user agent, as reported in the HTTP User-Agent field.


Generated on Sat Dec 4 2010 06:32:35 for Wt by doxygen 1.7.2