ASL
HttpRequest Class Reference

Detailed Description

An HTTP request that servers can read from.

An HttpRequest has a method (such as GET or POST), optional headers, and optional body. The body can be a String, a ByteArray or a Var. In the case of a Var it will be encoded as JSON and the request content type header automatically set.

See also
HttpServer

#include <Http.h>

Inheritance diagram for HttpRequest:
HttpMessage

Public Member Functions

 HttpRequest (const String &method, const String &url)
 Constructs an HttpRequest with the given method.
 
 HttpRequest (const String &method, const String &url, const Dic<> &headers)
 Constructs an HttpRequest with the given method and headers.
 
template<class T >
 HttpRequest (const String &method, const String &url, const T &data)
 Constructs an HttpRequest with the given method and body (a String, a ::ByteArray, a Var (sent as JSON) or a File)
 
template<class T >
 HttpRequest (const String &method, const String &url, const T &data, const Dic<> &headers)
 Constructs an HttpRequest with the given method, headers and body (a String, a ::ByteArray, a Var (sent as JSON) or a File)
 
const Stringmethod () const
 Returns the HTTP method (GET, POST, etc)
 
const Stringurl () const
 Returns the destination URL.
 
bool is (const char *meth, const String &pat)
 Returns true if the method is meth and the path matches pat.
 
bool is (const String &pat)
 Returns true if the path matches pat. More...
 
const Stringsuffix ()
 After a call to is() returns the part of the path that substitutes the * in the pattern.
 
const InetAddresssender ()
 Returns the address of the remote host (the client)
 
const Stringquerystring () const
 Returns the complete query string that follows the ? character in the URL path.
 
const Dicquery ()
 Returns the query converted to a Dic, assuming that it consists of keys and values like key1=value1&key2=value2.
 
const Stringquery (const String &key)
 Returns the unescaped value associated with the named key in the query; For example if the query was key1=value1&key2=value2%26, then request.query("key2") would return "value1&".
 
HttpRequestsetFollowRedirects (bool enable)
 Enables or disables automatic HTTP redirection.
 
- Public Member Functions inherited from HttpMessage
void setHeader (const String &header, const String &value)
 Adds a message header with name header and value value
 
String header (const String &name) const
 Returns the value of the header named.
 
bool hasHeader (const String &name) const
 Returns true if the message includes the given header name.
 
const Stringprotocol () const
 Returns the HTTP protocol (e.g. More...
 
void put (const ByteArray &data)
 Sets the body of the message as a binary blob.
 
void put (const String &body)
 Sets the body of the message as a text string.
 
void put (const Var &data)
 Sets the body of the message as a JSON document.
 
void put (const File &file)
 Sets the body of the message as a file.
 
const ByteArraybody () const
 Returns the binary body of the message.
 
String text () const
 Returns the message body as text.
 
Var json () const
 Returns the message body interpreted as JSON.
 
bool sendHeaders ()
 Sends the currently set headers and starts the message body.
 
void write (const String &text)
 Writes the given text string to the message body.
 
int write (const char *buffer, int n)
 Writes the given buffer to the message body.
 
void writeFile (const String &path, int begin=0, int end=0)
 Sends the content of the given file in the message body.
 
bool putFile (const String &path, int begin=0, int end=0)
 Sends the content of the given file as the message body and sets the content-length header.
 

Member Function Documentation

◆ is()

bool is ( const String pat)

Returns true if the path matches pat.

pat can be a fixed path name or a pattern including a * wildcard such as "/api/clients/ *".


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