API reference
GDWebServer
Low-level server using HTTP/1.1 responses for HTTP/1 requests and independent streams for TLS-negotiated HTTP/2 requests.
Methods
body_limit(bytes: int) -> voidheader_limits(bytes: int, values: int) -> voidlisten(port: int, host: String = "127.0.0.1") -> Variant, Errport() -> intstop() -> voidis_listening() -> boolpoll() -> PackedInt32Arrayget_method(id: int) -> Stringget_path(id: int) -> Stringget_query(id: int) -> Stringget_header(id: int, name: String) -> Stringget_headers(id: int) -> Dictionaryread_body(id: int, bytes: int = 32768) -> Dictionaryrespond(id: int, status: int, body: PackedByteArray, content_type: String = "text/plain; charset=utf-8") -> voidrespond_with(id: int, status: int, headers: Dictionary, body: PackedByteArray) -> voidconnection_count() -> intdropped_headers() -> int
body_limit
body_limit(bytes: int) -> voidSet the body-reader limit for all requests.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
bytes | int | Required | Byte count; it counts encoded bytes rather than text characters. |
Return value
void
No value is returned.
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
header_limits
header_limits(bytes: int, values: int) -> voidSet request-header byte and field-count limits.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
bytes | int | Required | Byte count; it counts encoded bytes rather than text characters. |
values | int | Required | Maximum number of header values accepted. |
Return value
void
No value is returned.
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
listen
listen(port: int, host: String = "127.0.0.1") -> Variant, ErrStart an HTTP listener on the specified host and port.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
port | int | Required | Network port number. A listening port of zero lets the OS select a port. |
host | String | "127.0.0.1" | Hostname or IP address used for connecting or binding. |
Return value
Variant, Err
Errors
The result carries a value and an Err. Check the error before using the value; a failure may retain partial progress. In a function returning value, Err, use ? to propagate failure to the caller. The ! operator terminates the program on failure; in serve it fails the current handler.
port
port() -> intReturn the actual listen port, including kernel-assigned ports.
Parameters
No parameters.
Return value
int
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
stop
stop() -> voidClose the listener and all connections, releasing retained buffers.
Parameters
No parameters.
Return value
void
No value is returned.
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
is_listening
is_listening() -> boolReport whether the HTTP listener is active.
Parameters
No parameters.
Return value
bool
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
poll
poll() -> PackedInt32ArrayAdvance connections and return ready request IDs, valid until the next poll.
Parameters
No parameters.
Return value
PackedInt32Array
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
get_method
get_method(id: int) -> StringReturn the request method.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | int | Required | Identifier previously returned by the corresponding API. |
Return value
String
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
get_path
get_path(id: int) -> StringReturn the path component of the request target.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | int | Required | Identifier previously returned by the corresponding API. |
Return value
String
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
get_query
get_query(id: int) -> StringReturn the query component of the request target.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | int | Required | Identifier previously returned by the corresponding API. |
Return value
String
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
get_header
get_header(id: int, name: String) -> StringReturn the named request-header value.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | int | Required | Identifier previously returned by the corresponding API. |
name | String | Required | Name used to register or look up the corresponding entry. |
Return value
String
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
get_headers
get_headers(id: int) -> DictionaryReturn request headers as a dictionary with lowercase names.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | int | Required | Identifier previously returned by the corresponding API. |
Return value
Dictionary
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
read_body
read_body(id: int, bytes: int = 32768) -> DictionaryRead one body chunk through the low-level API, returning state and data.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | int | Required | Identifier previously returned by the corresponding API. |
bytes | int | 32768 | Byte count; it counts encoded bytes rather than text characters. |
Return value
Dictionary
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
respond
respond(id: int, status: int, body: PackedByteArray, content_type: String = "text/plain; charset=utf-8") -> voidSubmit the common response form with just content and type.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | int | Required | Identifier previously returned by the corresponding API. |
status | int | Required | HTTP response status code. |
body | PackedByteArray | Required | Content to write or include in the response. |
content_type | String | "text/plain; charset=utf-8" | Media type sent in the HTTP Content-Type header. |
Return value
void
No value is returned.
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
respond_with
respond_with(id: int, status: int, headers: Dictionary, body: PackedByteArray) -> voidSubmit a response with additional headers.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
id | int | Required | Identifier previously returned by the corresponding API. |
status | int | Required | HTTP response status code. |
headers | Dictionary | Required | Response header names and their values. |
body | PackedByteArray | Required | Content to write or include in the response. |
Return value
void
No value is returned.
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
connection_count
connection_count() -> intReturn the number of retained connections.
Parameters
No parameters.
Return value
int
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.
dropped_headers
dropped_headers() -> intCumulative number of omitted headers.
Parameters
No parameters.
Return value
int
Errors
This call has no Err return slot. Its return type and documented sentinel values determine how to inspect the result.