Bundle Lightweight embedded web server. Handles inbound HTTP requests with typed access to method, path, headers, and body; Response supports content-type, compression, redirects, and cookies. Compile with -lib net_server.
Response
Web Response
Operations
ClearAll #
Clears the entire body response
method : public : ClearAll() ~ NilExample
response->WriteBody("draft content");
response->ClearAll(); # discard draft
response->WriteBody("final content");Redirect #
Redirects a quary URL
method : public : Redirect(url:String) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| url | String | URL redirect |
Return
| Type | Description |
|---|---|
| Bool | number of bytes sent |
Example
# redirect to a new URL
response->Redirect("https://example.com/new-path");RemoveHeader #
Removes a HTTP header
method : public : RemoveHeader(name:String) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| name | String | header name |
Return
| Type | Description |
|---|---|
| Bool | true successful, false otherwise |
Example
response->SetHeader("X-Debug", "1");
response->RemoveHeader("X-Debug"); # strip before sending
response->WriteBody("Done");SetContentType #
Set the content type
method : public : SetContentType(type:String) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| type | String | content type |
Example
response->SetContentType("application/json");
response->WriteBody("{\"status\":\"ok\"}");SetHeader #
Sets a HTTP header
method : public : SetHeader(name:String, value:String) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| name | String | header name |
| value | String | header value |
Return
| Type | Description |
|---|---|
| Bool | true successful, false otherwise |
Example
response->SetHeader("Cache-Control", "no-cache");
response->SetHeader("X-Custom-Header", "my-value");
response->WriteBody("OK");WriteBody #
Writes a string response to the message body
method : public : WriteBody(data:String) ~ IntParameters
| Name | Type | Description |
|---|---|---|
| data | String | string response |
Return
| Type | Description |
|---|---|
| Int | number of bytes sent |
Example
response->SetContentType("text/html");
bytes_sent := response->WriteBody("<html><body>Hello</body></html>");
bytes_sent->PrintLine(); # number of bytes writtenWriteBody #
Writes a byte array response to the message body
method : public : WriteBody(data:Byte[]) ~ IntParameters
| Name | Type | Description |
|---|---|---|
| data | Byte | byte array response |
Return
| Type | Description |
|---|---|
| Int | number of bytes sent |
Example
img_bytes := System.IO.Filesystem.FileReader->ReadBinaryFile("logo.png");
response->SetContentType("image/png");
response->WriteBody(img_bytes);