Request
Web server request
Operations
- New
- GetContent
- GetContentBytes
- GetCookie
- GetCookies
- GetHeader
- GetLocalPort
- GetMethod
- GetParam
- GetParams
- GetPath
- GetQuery
- GetRemoteAddress
- GetRequestLine
- HasContent
- HasCookie
- HasParam
- ParseAttribs
- ParseCookies
- ParseParams
- SetConnectionInfo
GetContent #
Gets the request body content
method : public : GetContent() ~ StringReturn
| Type | Description |
|---|---|
| String | request content |
Example
# inside ProcessPost:
if(request->HasContent()) {
body := request->GetContent();
body->PrintLine(); # raw POST body string
};GetContentBytes #
Gets the request body content as bytes
method : public : GetContentBytes() ~ Byte[]Return
| Type | Description |
|---|---|
| Byte | request content as bytes |
GetCookie #
Gets a cookie value
method : public : GetCookie(name:String) ~ CookieParameters
| Name | Type | Description |
|---|---|---|
| name | String | cookie name |
Return
| Type | Description |
|---|---|
| Cookie | cookie value |
GetCookies #
Gets cookies
method : public : GetCookies() ~ Vector<Cookie>Return
| Type | Description |
|---|---|
| Vector<Cookie> | cookies |
GetHeader #
Gets a request header
method : public : GetHeader(name:String) ~ StringParameters
| Name | Type | Description |
|---|---|---|
| name | String | header name |
Return
| Type | Description |
|---|---|
| String | request header |
GetLocalPort #
Gets the port this server is bound to. This is the port passed to Serve, not a socket-level lookup of the accepted connection.
method : public : GetLocalPort() ~ IntReturn
| Type | Description |
|---|---|
| Int | local port, or 0 if the server did not supply one |
GetMethod #
Gets the HTTP verb. The verb is parsed by the server to choose a handler method; this exposes it to handlers that need it directly.
method : public : GetMethod() ~ StringReturn
| Type | Description |
|---|---|
| String | HTTP verb, or Nil if the server did not supply one |
GetParam #
Gets a parameter value
method : public : GetParam(name:String) ~ StringParameters
| Name | Type | Description |
|---|---|---|
| name | String | parameter name |
Return
| Type | Description |
|---|---|
| String | parameter value |
Example
# inside ProcessGet or ProcessPost:
name := request->GetParam("username");
if(name <> Nil) {
"Hello, {$name}!"->PrintLine();
};GetParams #
Gets parameters
method : public : GetParams() ~ Map<String,String>Return
| Type | Description |
|---|---|
| Map<String,String> | parameters |
GetPath #
Gets the request path
method : public : GetPath() ~ StringReturn
| Type | Description |
|---|---|
| String | request path |
Example
# inside ProcessGet:
path := request->GetPath();
path->PrintLine(); # e.g. /api/usersGetQuery #
Gets the request query
method : public : GetQuery() ~ StringReturn
| Type | Description |
|---|---|
| String | request query |
GetRemoteAddress #
Gets the address of the connected peer.
method : public : GetRemoteAddress() ~ StringReturn
| Type | Description |
|---|---|
| String | peer address, or Nil if the server did not supply one |
GetRequestLine #
Gets the request line
method : public : GetRequestLine() ~ StringReturn
| Type | Description |
|---|---|
| String | request line |
HasContent #
Checks for request body content
method : public : HasContent() ~ BoolReturn
| Type | Description |
|---|---|
| Bool | true if content exists, false otherwise |
HasCookie #
Checks for a cookie
method : public : HasCookie(name:String) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| name | String | cookie name |
Return
| Type | Description |
|---|---|
| Bool | true if cookie exists, false otherwise |
HasParam #
Checks for a parameter
method : public : HasParam(name:String) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| name | String | parameter name |
Return
| Type | Description |
|---|---|
| Bool | true if parameter exists, false otherwise |
New # constructor
Constructor
New(request_line:String, request_headers:Map<String,String>)Parameters
| Name | Type | Description |
|---|---|---|
| request_line | String | HTTP request line |
| request_headers | Map<String,String> | HTTP request headers |
New # constructor
Constructor
New(request_line:String, request_headers:Map<String,String>, content:Byte[])Parameters
| Name | Type | Description |
|---|---|---|
| request_line | String | HTTP request line |
| request_headers | Map<String,String> | HTTP request headers |
| content | Byte | request body content |
ParseAttribs # function
Parses an attribute string
function : ParseAttribs(attrib_str:String) ~ Map<String,String>Parameters
| Name | Type | Description |
|---|---|---|
| attrib_str | String | attribute string |
Return
| Type | Description |
|---|---|
| Map<String,String> | map of names/values |
SetConnectionInfo #
Sets connection metadata. Called by the server immediately after the request is constructed; handlers should treat these as read-only.
method : public : SetConnectionInfo(request_verb:String, remote_address:String, local_port:Int) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| request_verb | String | HTTP verb, e.g. GET or POST |
| remote_address | String | address of the connected peer |
| local_port | Int | port this server is bound to |