Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site













SourceForge.net Logo

Http

 

class Http : public Renderer

Http is the reference parameter passed to Skylark handlers. It provides data associated with request, like POST or GET form values, session variables or cookie values, and is used to store any 'output' values like response fields, cookies, new values of session variables..

 

Public Method List

 

Http& operator()(const char *id, const Value& v)

Http& operator()(const char *id, const char *v)

Http& operator()(const char *id, const String& v)

Calls Renderer::operator(id , v) to set the value of shared space variable. Returns *this.

 


 

virtual Http& operator()(const ValueMap& map)

Calls Renderer::operator(map) to set the values of shared space variables based on key-value pairs of map. Returns *this.

 


 

Http& operator()(const char *id, const HandlerId& handler)

Http& operator()(const char *id, void (*handler)(Http&))

Calls Renderer::operator(id, handler) to set the value of shared space variable to url link. Returns *this.

 


 

Http& operator()(const char *id, const HandlerId& handler, const Value& arg1)

Http& operator()(const char *id, void (*handler)(Http&), const Value& arg1)

Calls Renderer::operator(id, handler, arg1) to set the value of shared space variable to url link with one url argument. Returns *this.

 


 

Http& operator()(const char *id, const HandlerId& handler, const Value& arg1, const Value& arg2)

Http& operator()(const char *id, void (*handler)(Http&), const Value& arg1, const Value& arg2)

Calls Renderer::operator(id, handler, arg1, arg2) to set the value of shared space variable to url link with two url arguments. Returns *this.

 


 

Http& operator()(const Sql& sql)

Calls Renderer::operator(sql) to set the values of shared space variables based on column-name/value pairs of current row fetched in sql. Returns *this.

 


 

Http& operator()(Fields rec)

Calls Renderer::operator(rec) to set the values of shared space variables based on column-name/value pairs of rec fields. Returns *this.

 


 

Http& operator()(const SqlSelect& row_sel)

Calls Renderer::operator(row_sel) to set the values of shared space variables based on column-name/value pairs of single row fetched from database using row_sel. Returns *this.

 


 

Http& operator()(const char *id, const SqlSelect& sel)

Calls Renderer::operator(id, sel) to set the value of shared space variable id to the complete result set of sel represented as ValueArray of ValueMaps. Returns *this.

 


 

Http& Render(const char *id, const String& template_name)

Calls Renderer::Render(id, template_name) to render witz template as RawHtmlText into shared space variable id. Returns *this.

 


 

Value Render(const String& template_name)

Calls Renderer::Render(template_name) to render witz template and return the result as RawHtmlText.

 


 

String GetHeader(const char *sconst

Returns HTTP request header field value.

 


 

int GetLength() const

Returns request content length.

 


 

String GetHandlerId() const

Returns the name of handler currently invoked.

 


 

Value operator[](const char *idconst

Returns the shared space variable id, void Value if missing.

 


 

int Int(const char *idconst

Returns the shared space variable id converted to integer, Null if missing or if it cannot be converted.

 


 

String operator[](int iconst

Returns the value of URL argument at position i, empty String if not available.

 


 

int Int(int iconst

Returns the value of URL argument at position i converted to integer, Null if not available.

 


 

int GetParamCount() const

Returns the number of URL arguments.

 


 

Http& ContentType(const char *s)

Sets the response content-type. Default value is "text/html; charset=UTF-8". Returns *this.

 


 

Http& Content(const char *s, const Value& data)

Sets the response content-type to s and response content to data converted to text. No html escaping is performed. Returns *this.

 


 

Http& operator<<(const Value& s)

Sets the response content to data converted to text. No html escaping is performed. Returns *this.

 


 

Http& SetRawCookie(const char *id, const String& value, Time expires = Null, const char *path = NULL, const char *domain = NULL, bool secure = false, bool httponly = false)

Sets the cookie id to value, using expires, path, domain, secure, httponly to setup cookie attributes. value is not url-encoded. Returns *this.

 


 

String GetPeerAddr() const

Returns IP address of client. If there is "X-Forwarded-For" header present (e.g. when using proxy or load balancer), it's value is used, otherwise returns value reported by TcpSocket::GetPeerAddr(). This function may return empty string if called when socket is not available (e.g. after calling Http::Finalize()).

 


 

String GetRequestContent() const

Returns the content of request.

 


 

Http& SetCookie(const char *id, const String& value, Time expires = Null, const char *path = NULL, const char *domain = NULL, bool secure = false, bool httponly = false)

Same as SetRawCookie, but url-encoding the value. Returns *this.

 


 

Http& SetHeader(const char *header, const char *data)

Sets the response HTTP header value.

 


 

Http& ClearHeader(const char *header)

Removes HTTP header from response.

 


 

Http& ClearSession()

Clears the session variables and session id (but their values in shared variable space are retained). Returns *this.

 


 

Http& SessionSet(const char *id, const Value& value)

Sets the session value id to value, also sets shared variable space to the same value. id must start with '.'. Session variables are preserved for session across HTTP requests (using session cookies). Returns *this.

 


 

Http& NewSessionId()

Sets the new session id, effectively changing the session cookie value and storage for current session. Returns *this.

 


 

Http& NewIdentity()

Sets the new CSRF prevention identity. It might be a good idea to call this function after login. Returns *this.

 


 

Http& SetLanguage(int lang)

Sets the session language to lang. This calls Renderer::SetLanguage to change the language of witz templates and also sets language related session variables ".__lang__" (integer value) and ".language" (text value), so that language can be restored during following HTTP requests. Returns *this.

 


 

Http& Response(int code, const String& ctext)

Sets the HTTP response code and reason ctext. Returns *this.

 


 

Http& RenderResult(const char *template_name)

Renders result content using witz template. Returns *this.

 


 

Http& Redirect(const char *url, int code = 302)

Sets the response to be redirection. url sets the Location: header of response, code the response code. Returns *this.

 


 

Http& Redirect(const HandlerId& handler, const Vector<Value>& arg)

Sets the redirection response to handler with a set of url arguments arg. Returns *this.

 


 

Http& Redirect(const HandlerId& handler)

Sets the redirection response to handler. Returns *this.

 


 

Http& Redirect(const HandlerId& handler, const Value& v1)

Sets the redirection response to handler with one url argument. Returns *this.

 


 

Http& Redirect(const HandlerId& handler, const Value& v1, const Value& v2)

Sets the redirection response to handler with two url arguments. Returns *this.

 


 

Http& Ux(const char *id, const String& text)

Sets the response in special Skylark format used to provide Ajax support. When using "skylark.js" module for Ajax, this response replaces html element with specified html id to text. (text is not html-escaped). Returns *this.

 


 

Http& UxRender(const char *id, const char *template_name)

Sets the response in special Skylark format used to provide Ajax support. When using "skylark.js" module for Ajax, this response replaces html element with specified html id to the rendered template. Returns *this.

 


 

Http& UxSet(const char *id, const String& value)

Sets the response in special Skylark format used to provide Ajax support. When using "skylark.js" module for Ajax, this response replaces the value of html element with specified html id to the rendered template. Returns *this.

 


 

Http& UxRun(const String& js_code)

Sets the response in special Skylark format used to provide Ajax support. When using "skylark.js" module for Ajax, this response makes browser to run arbitrary javascript code. Returns *this.

 


 

String GetResponse() const

Returns the current response.

 


 

void Finalize()

Sends HTTP response for current request, based on data already rendered at the point of call. Finalize is normally called by Skylark after handler finishes, but it is possible to call it earlier to send response to the client and then continue processing, e.g. to process some large dataset submitted by client.

 


 

void Dispatch(TcpSocket& socket)

This method is not usually called by client application. Skylark framework calls it to process incoming HTTP request.

 

Last edit by cxl on 05/04/2015. Do you want to contribute?. T++