4.5. HTTP and WebSocket library (libhv)
The DASHV module provides HTTP and WebSocket networking built on top of the libhv library. It exposes WebSocket client/server types, HTTP request/response handling, route registration, cookie and form-data helpers, and an HTTP client for making outbound requests.
Use dashv_boost for the high-level daScript wrappers (HvWebServer,
HvWebSocketClient). The low-level C++ bindings live in this module.
All functions and symbols are in “dashv” module, use require to get access to it.
require dashv
WebSocket client / server / channel objects are exposed to daScript as
value-sized Handle<T> integers backed by HandleRegistry<T>. For
leak diagnostics on these handles (and an overview of the other
built-in leak detectors) see 6. HandleRegistry (dasHV handle objects) in the
Memory Leak Detection — Diagnostics Cheat Sheet guide.
See also:
dashv_boost — high-level wrapper classes
Memory Leak Detection — Diagnostics Cheat Sheet — leak diagnostics cheat sheet
4.5.1. Enumerations
- http_method
HTTP request method.
- Values:
DELETE = 0 - Delete resource
GET = 1 - Get resource
HEAD = 2 - Head request (headers only)
POST = 3 - Post data
PUT = 4 - Put resource
CONNECT = 5 - Connect tunnel
OPTIONS = 6 - Options inspection
TRACE = 7 - Trace echo
COPY = 8 - WebDAV copy
LOCK = 9 - WebDAV lock
MKCOL = 10 - WebDAV create collection
MOVE = 11 - WebDAV move
PROPFIND = 12 - WebDAV property find
PROPPATCH = 13 - WebDAV property patch
SEARCH = 14 - WebDAV search
UNLOCK = 15 - WebDAV unlock
BIND = 16 - WebDAV bind
REBIND = 17 - WebDAV rebind
UNBIND = 18 - WebDAV unbind
ACL = 19 - WebDAV ACL
REPORT = 20 - WebDAV report
MKACTIVITY = 21 - WebDAV make activity
CHECKOUT = 22 - WebDAV checkout
MERGE = 23 - WebDAV merge
MSEARCH = 14 - UPnP multicast search
NOTIFY = 25 - UPnP notify
SUBSCRIBE = 26 - UPnP subscribe
UNSUBSCRIBE = 27 - UPnP unsubscribe
PATCH = 28 - Partial update
PURGE = 29 - Cache purge
MKCALENDAR = 30 - CalDAV create calendar
LINK = 31 - Link resources
UNLINK = 32 - Unlink resources
SOURCE = 33 - Retrieve source
- http_status
HTTP response status code.
- Values:
CONTINUE = 100 - 100 Continue
SWITCHING_PROTOCOLS = 101 - 101 Switching Protocols
PROCESSING = 102 - 102 Processing
OK = 200 - 200 OK
CREATED = 201 - 201 Created
ACCEPTED = 202 - 202 Accepted
NON_AUTHORITATIVE_INFORMATION = 203 - 203 Non-Authoritative Information
NO_CONTENT = 204 - 204 No Content
RESET_CONTENT = 205 - 205 Reset Content
PARTIAL_CONTENT = 206 - 206 Partial Content
MULTI_STATUS = 207 - 207 Multi-Status
ALREADY_REPORTED = 208 - 208 Already Reported
IM_USED = 226 - 226 IM Used
MULTIPLE_CHOICES = 300 - 300 Multiple Choices
MOVED_PERMANENTLY = 301 - 301 Moved Permanently
FOUND = 302 - 302 Found
SEE_OTHER = 303 - 303 See Other
NOT_MODIFIED = 304 - 304 Not Modified
USE_PROXY = 305 - 305 Use Proxy
TEMPORARY_REDIRECT = 307 - 307 Temporary Redirect
PERMANENT_REDIRECT = 308 - 308 Permanent Redirect
BAD_REQUEST = 400 - 400 Bad Request
UNAUTHORIZED = 401 - 401 Unauthorized
PAYMENT_REQUIRED = 402 - 402 Payment Required
FORBIDDEN = 403 - 403 Forbidden
NOT_FOUND = 404 - 404 Not Found
METHOD_NOT_ALLOWED = 405 - 405 Method Not Allowed
NOT_ACCEPTABLE = 406 - 406 Not Acceptable
PROXY_AUTHENTICATION_REQUIRED = 407 - 407 Proxy Authentication Required
REQUEST_TIMEOUT = 408 - 408 Request Timeout
CONFLICT = 409 - 409 Conflict
GONE = 410 - 410 Gone
LENGTH_REQUIRED = 411 - 411 Length Required
PRECONDITION_FAILED = 412 - 412 Precondition Failed
PAYLOAD_TOO_LARGE = 413 - 413 Payload Too Large
URI_TOO_LONG = 414 - 414 URI Too Long
UNSUPPORTED_MEDIA_TYPE = 415 - 415 Unsupported Media Type
RANGE_NOT_SATISFIABLE = 416 - 416 Range Not Satisfiable
EXPECTATION_FAILED = 417 - 417 Expectation Failed
MISDIRECTED_REQUEST = 421 - 421 Misdirected Request
UNPROCESSABLE_ENTITY = 422 - 422 Unprocessable Entity
LOCKED = 423 - 423 Locked
FAILED_DEPENDENCY = 424 - 424 Failed Dependency
UPGRADE_REQUIRED = 426 - 426 Upgrade Required
PRECONDITION_REQUIRED = 428 - 428 Precondition Required
TOO_MANY_REQUESTS = 429 - 429 Too Many Requests
REQUEST_HEADER_FIELDS_TOO_LARGE = 431 - 431 Request Header Fields Too Large
UNAVAILABLE_FOR_LEGAL_REASONS = 451 - 451 Unavailable For Legal Reasons
INTERNAL_SERVER_ERROR = 500 - 500 Internal Server Error
NOT_IMPLEMENTED = 501 - 501 Not Implemented
BAD_GATEWAY = 502 - 502 Bad Gateway
SERVICE_UNAVAILABLE = 503 - 503 Service Unavailable
GATEWAY_TIMEOUT = 504 - 504 Gateway Timeout
HTTP_VERSION_NOT_SUPPORTED = 505 - 505 HTTP Version Not Supported
VARIANT_ALSO_NEGOTIATES = 506 - 506 Variant Also Negotiates
INSUFFICIENT_STORAGE = 507 - 507 Insufficient Storage
LOOP_DETECTED = 508 - 508 Loop Detected
NOT_EXTENDED = 510 - 510 Not Extended
NETWORK_AUTHENTICATION_REQUIRED = 511 - 511 Network Authentication Required
- ws_opcode
WebSocket frame opcode.
- Values:
WS_OPCODE_CONTINUE = 0 - Continuation frame
WS_OPCODE_TEXT = 1 - Text frame
WS_OPCODE_BINARY = 2 - Binary frame
WS_OPCODE_CLOSE = 8 - Close connection
WS_OPCODE_PING = 9 - Ping keepalive
WS_OPCODE_PONG = 10 - Pong reply
- ws_session_type
WebSocket session type.
- Values:
WS_CLIENT = 0 - Client session
WS_SERVER = 1 - Server session
4.5.2. Handled structures
- HttpMessage
Base type for HTTP messages, providing header access.
- HttpResponse
HTTP response with status code, headers, and body.
- Fields:
body : das_string - Response body content.
content : void? - Content string.
status_code : http_status - HTTP status code.
- HttpResponseWriter
HTTP response writer for streaming responses. Supports chunked transfer encoding and SSE events. Obtained through async HTTP handlers registered with SSE.
- HttpRequest
HTTP request with URL, method, headers, body, and parameters.
- Fields:
body : das_string - Request body content.
method : http_method - HTTP method (GET, POST, etc.).
url : das_string - Full request URL.
scheme : das_string - URL scheme (http or https).
host : das_string - Host name.
port : int - Port number.
path : das_string - URL path component.
timeout : uint16 - Overall request timeout in seconds.
connect_timeout : uint16 - Connection timeout in seconds.
- HttpContext
HTTP request/response context passed to route handlers.
4.5.3. Handled types
- WebSocketClient
Opaque handle to an outbound WebSocket connection.
Created by make_web_socket_client and released by destroy_web_socket_client; used by the HvWebSocketClient wrapper class.
- WebSocketServer
Opaque handle to a running HTTP/WebSocket server.
Created by make_web_socket_server and released by destroy_web_socket_server; used by the HvWebServer wrapper class.
- WebSocketAdmission
Generation-checked ticket for a pending WebSocket upgrade. Expires on submitted decision, timeout, disconnect or server shutdown; it does not retain a valid HTTP request pointer.
- WebSocketChannel
Opaque handle to a server-side WebSocket client connection.
Passed to onWsOpen / onWsMessage / onWsClose and to send; becomes dead after the peer disconnects.
4.5.4. WebSocket client
make_web_socket_client (class: void?; info: StructInfo const?) : WebSocketClient
send (channel: WebSocketChannel; msg: string; len: int; fragment: int; opcode: ws_opcode) : int
send (channel: WebSocketChannel; msg: string; len: int; opcode: ws_opcode; fin: bool) : int
send (channel: WebSocketChannel; msg: string; opcode: ws_opcode; fin: bool) : int
send (self: WebSocketClient; msg: string; len: int; opcode: ws_opcode) : int
4.5.4.1. close
- close(channel: WebSocketChannel ): int
Closes a connected WebSocket channel. Returns 0 on success and -1 for an invalid channel handle.
- Arguments:
channel : WebSocketChannel
- close(self: WebSocketClient ): int
- destroy_web_socket_client(arg0: WebSocketClient ): bool
Releases the client handle. Returns true if the handle was live, false if already dead.
- Arguments:
arg0 : WebSocketClient
- is_connected(self: WebSocketClient ): bool
Returns true if the WebSocket client is currently connected.
- Arguments:
self : WebSocketClient
- make_web_socket_client(class: void?; info: StructInfo const? ): WebSocketClient
Creates a new low-level WebSocket client bound to a daScript class instance.
- Arguments:
class : void? implicit
info : StructInfo? implicit
- open(self: WebSocketClient; url: string ): int
Opens a WebSocket connection to the specified URL. Returns 0 on success.
- Arguments:
self : WebSocketClient
url : string implicit
4.5.4.2. send
- send(channel: WebSocketChannel; msg: string; len: int; fragment: int; opcode: ws_opcode ): int
Sends a message frame on the WebSocket channel with the given opcode and fin flag. Returns the number of bytes sent, or a negative error code.
- Arguments:
channel : WebSocketChannel
msg : string implicit
len : int
fragment : int
opcode : ws_opcode
- send(channel: WebSocketChannel; msg: string; len: int; opcode: ws_opcode; fin: bool ): int
- send(channel: WebSocketChannel; msg: string; opcode: ws_opcode; fin: bool ): int
- send(self: WebSocketClient; msg: string ): int
- send(self: WebSocketClient; msg: string; len: int; opcode: ws_opcode ): int
4.5.4.3. tick
- tick(self: WebSocketClient )
Drains one batch of queued HTTP/WebSocket events and invokes the user callbacks. Call periodically from the owning thread.
- Arguments:
self : WebSocketClient
- tick(server: WebSocketServer )
4.5.5. WebSocket server lifecycle
- bound_port(server: WebSocketServer ): int
The port the server listens on: the one passed to make_web_socket_server, or, when that was 0,
the free port the operating system picked. Valid once start has succeeded; -1 otherwise.
- Arguments:
server : WebSocketServer
- destroy_web_socket_server(arg0: WebSocketServer ): bool
Releases the server handle. Returns true if the handle was live. When this drops the last reference, ~hv::WebSocketServer runs and stops the background workers; call stop() explicitly if you keep other references to the server.
- Arguments:
arg0 : WebSocketServer
- make_web_socket_server(port: int; https_port: int; pathToCert: string; class: void?; info: StructInfo const? ): WebSocketServer
Creates a new low-level WebSocket/HTTP server on the given port, optionally with TLS.
- Arguments:
port : int
https_port : int
pathToCert : string implicit
class : void? implicit
info : StructInfo? implicit
- set_bind_host(server: WebSocketServer; host: string ): bool
Selects the WebSocket server interface to bind before start. Returns false for an invalid server handle, an empty host, or a host that is too long.
- Arguments:
server : WebSocketServer
host : string implicit
- start(server: WebSocketServer ): int
Starts the server’s background workers. Returns 0 on success, a negative error code otherwise.
- Arguments:
server : WebSocketServer
- stop(server: WebSocketServer ): int
Stops the server and drains pending events. Returns 0 on success.
- Arguments:
server : WebSocketServer
4.5.6. WebSocket channel send
4.5.7. Handle operations
WebSocketAdmission!= (arg0: WebSocketAdmission; arg1: WebSocketAdmission) : bool
WebSocketAdmission== (arg0: WebSocketAdmission; arg1: WebSocketAdmission) : bool
WebSocketChannel!= (arg0: WebSocketChannel; arg1: WebSocketChannel) : bool
WebSocketChannel== (arg0: WebSocketChannel; arg1: WebSocketChannel) : bool
WebSocketClient!= (arg0: WebSocketClient; arg1: WebSocketClient) : bool
WebSocketClient== (arg0: WebSocketClient; arg1: WebSocketClient) : bool
WebSocketServer!= (arg0: WebSocketServer; arg1: WebSocketServer) : bool
WebSocketServer== (arg0: WebSocketServer; arg1: WebSocketServer) : bool
- WebSocketAdmission!=(arg0: WebSocketAdmission; arg1: WebSocketAdmission ): bool
Compares WebSocket admission ticket identity and generation for inequality.
- Arguments:
arg0 : WebSocketAdmission
arg1 : WebSocketAdmission
- WebSocketAdmission==(arg0: WebSocketAdmission; arg1: WebSocketAdmission ): bool
Compares WebSocket admission ticket identity and generation. Equality does not imply that either ticket remains alive.
- Arguments:
arg0 : WebSocketAdmission
arg1 : WebSocketAdmission
- WebSocketChannel!=(arg0: WebSocketChannel; arg1: WebSocketChannel ): bool
Handle inequality: returns true if the two handles refer to different channels (or at least one is null).
- Arguments:
arg0 : WebSocketChannel
arg1 : WebSocketChannel
- WebSocketChannel==(arg0: WebSocketChannel; arg1: WebSocketChannel ): bool
Handle equality: returns true if both refer to the same channel.
- Arguments:
arg0 : WebSocketChannel
arg1 : WebSocketChannel
- WebSocketClient!=(arg0: WebSocketClient; arg1: WebSocketClient ): bool
Handle inequality: returns true if the two handles refer to different clients (or at least one is null).
- Arguments:
arg0 : WebSocketClient
arg1 : WebSocketClient
- WebSocketClient==(arg0: WebSocketClient; arg1: WebSocketClient ): bool
Handle equality: returns true if both refer to the same client.
- Arguments:
arg0 : WebSocketClient
arg1 : WebSocketClient
- WebSocketServer!=(arg0: WebSocketServer; arg1: WebSocketServer ): bool
Handle inequality: returns true if the two handles refer to different servers (or at least one is null).
- Arguments:
arg0 : WebSocketServer
arg1 : WebSocketServer
- WebSocketServer==(arg0: WebSocketServer; arg1: WebSocketServer ): bool
Handle equality: returns true if both refer to the same live server.
- Arguments:
arg0 : WebSocketServer
arg1 : WebSocketServer
4.5.7.1. is_alive
- is_alive(arg0: WebSocketAdmission ): bool
Returns whether this WebSocket admission ticket is still registered. A decision can still lose a race with its deadline or connection closing.
- Arguments:
arg0 : WebSocketAdmission
- is_alive(arg0: WebSocketChannel ): bool
- is_alive(arg0: WebSocketClient ): bool
- is_alive(arg0: WebSocketServer ): bool
4.5.8. HTTP route registration
ANY (server: WebSocketServer; url: string; lambda: lambda<():void>)
DELETE (server: WebSocketServer; url: string; lambda: lambda<():void>)
DELETE (url: string; headers: table<string, string>; block: block<(HttpResponse?):void>)
GET (server: WebSocketServer; url: string; lambda: lambda<():void>)
GET (url: string; headers: table<string, string>; block: block<(HttpResponse?):void>)
HEAD (server: WebSocketServer; url: string; lambda: lambda<():void>)
HEAD (url: string; headers: table<string, string>; block: block<(HttpResponse?):void>)
PATCH (server: WebSocketServer; url: string; lambda: lambda<():void>)
PATCH (url: string; text: string; block: block<(HttpResponse?):void>)
POST (server: WebSocketServer; url: string; lambda: lambda<():void>)
POST (url: string; text: string; block: block<(HttpResponse?):void>)
POST (url: string; text: string; headers: table<string, string>; block: block<(HttpResponse?):void>)
PUT (server: WebSocketServer; url: string; lambda: lambda<():void>)
PUT (url: string; text: string; block: block<(HttpResponse?):void>)
PUT (url: string; text: string; headers: table<string, string>; block: block<(HttpResponse?):void>)
SSE (server: WebSocketServer; url: string; lambda: lambda<():void>)
STREAM (server: WebSocketServer; url: string; lambda: lambda<():void>)
- ANY(server: WebSocketServer; url: string; lambda: lambda<():void> )
Warning
This is unsafe operation.
Registers a handler that matches any HTTP method (GET/POST/PUT/etc) for the given URL path.
- Arguments:
server : WebSocketServer
url : string implicit
lambda : lambda<void>
4.5.8.1. DELETE
- DELETE(server: WebSocketServer; url: string; lambda: lambda<():void> )
Warning
This is unsafe operation.
Registers a DELETE route handler, or performs an HTTP DELETE client request.
- Arguments:
server : WebSocketServer
url : string implicit
lambda : lambda<void>
- DELETE(url: string; block: block<(HttpResponse?):void> )
- DELETE(url: string; headers: table<string, string>; block: block<(HttpResponse?):void> )
4.5.8.2. GET
- GET(server: WebSocketServer; url: string; lambda: lambda<():void> )
Warning
This is unsafe operation.
Registers a GET route handler, or performs an HTTP GET client request.
- Arguments:
server : WebSocketServer
url : string implicit
lambda : lambda<void>
- GET(url: string; block: block<(HttpResponse?):void> )
- GET(url: string; headers: table<string, string>; block: block<(HttpResponse?):void> )
4.5.8.3. HEAD
- HEAD(server: WebSocketServer; url: string; lambda: lambda<():void> )
Warning
This is unsafe operation.
Registers an HTTP HEAD handler for the given URL path.
- Arguments:
server : WebSocketServer
url : string implicit
lambda : lambda<void>
- HEAD(url: string; block: block<(HttpResponse?):void> )
- HEAD(url: string; headers: table<string, string>; block: block<(HttpResponse?):void> )
4.5.8.4. PATCH
- PATCH(server: WebSocketServer; url: string; lambda: lambda<():void> )
Warning
This is unsafe operation.
Registers an HTTP PATCH handler for the given URL path.
- Arguments:
server : WebSocketServer
url : string implicit
lambda : lambda<void>
- PATCH(url: string; text: string; block: block<(HttpResponse?):void> )
- PATCH(url: string; text: string; headers: table<string, string>; block: block<(HttpResponse?):void> )
- PATCH(url: string; text: string; headers: table<string, string>; from: table<string, string>; block: block<(HttpResponse?):void> )
4.5.8.5. POST
- POST(server: WebSocketServer; url: string; lambda: lambda<():void> )
Warning
This is unsafe operation.
Registers a POST route handler, or performs an HTTP POST client request.
- Arguments:
server : WebSocketServer
url : string implicit
lambda : lambda<void>
- POST(url: string; text: string; block: block<(HttpResponse?):void> )
- POST(url: string; text: string; headers: table<string, string>; block: block<(HttpResponse?):void> )
- POST(url: string; text: string; headers: table<string, string>; from: table<string, string>; block: block<(HttpResponse?):void> )
4.5.8.6. PUT
- PUT(server: WebSocketServer; url: string; lambda: lambda<():void> )
Warning
This is unsafe operation.
Registers a PUT route handler, or performs an HTTP PUT client request.
- Arguments:
server : WebSocketServer
url : string implicit
lambda : lambda<void>
- PUT(url: string; text: string; block: block<(HttpResponse?):void> )
- PUT(url: string; text: string; headers: table<string, string>; block: block<(HttpResponse?):void> )
- PUT(url: string; text: string; headers: table<string, string>; from: table<string, string>; block: block<(HttpResponse?):void> )
- SSE(server: WebSocketServer; url: string; lambda: lambda<():void> )
Warning
This is unsafe operation.
Registers a Server-Sent Events (SSE) streaming handler for the given URL path.
- Arguments:
server : WebSocketServer
url : string implicit
lambda : lambda<void>
- STREAM(server: WebSocketServer; url: string; lambda: lambda<():void> )
Warning
This is unsafe operation.
Registers a streaming HTTP route: the handler runs on the server’s tick thread and drives an HttpResponseWriter to emit Server-Sent Events, chunked data, or one buffered body. The same route serves both streaming and non-streaming responses.
- Arguments:
server : WebSocketServer
url : string implicit
lambda : lambda<void>
4.5.9. HTTP server configuration
- STATIC(server: WebSocketServer; path: string; dir: string )
Registers a static-file route: serves files under dir at the URL prefix path.
- Arguments:
server : WebSocketServer
path : string implicit
dir : string implicit
- WEBSOCKET_UPGRADE(server: WebSocketServer; timeout_ms: int; handler: lambda<():void> ): bool
Warning
This is unsafe operation.
Registers a deferred WebSocket admission callback before server start. Timeout must be 1–60000 milliseconds. The callback runs on the script tick thread with a borrowed request and a ticket; accept or reject the ticket after checking application policy. Returns false for invalid timeout, missing server or running server.
- Arguments:
server : WebSocketServer
timeout_ms : int
handler : lambda<void>
- accept_websocket(admission: WebSocketAdmission; protocol: string ): int
Submits acceptance of a live, undecided WebSocket ticket. Returns zero when queued, otherwise an error for an expired ticket, an overly long protocol or CR/LF in it. The ticket becomes unusable after submission. The connection loop then checks protocol syntax and whether the client offered it; a mismatch sends HTTP 400 rather than upgrading.
- Arguments:
admission : WebSocketAdmission
protocol : string implicit
- allow_cors(server: WebSocketServer )
Enables cross-origin resource sharing (CORS) on all server responses.
- Arguments:
server : WebSocketServer
- reject_websocket(admission: WebSocketAdmission; status: int ): int
Submits rejection of a live, undecided WebSocket ticket with HTTP status 400–599. Returns zero when submitted, otherwise an error; the ticket becomes unusable after submission.
- Arguments:
admission : WebSocketAdmission
status : int
- set_access_log(server: WebSocketServer; enabled: bool ): bool
Enables or disables libhv request access logging before server start. Returns false for a missing or running server. It does not control application logs or lifecycle diagnostics.
- Arguments:
server : WebSocketServer
enabled : bool
- set_connection_limits(server: WebSocketServer; pending_messages: int; pending_bytes: int; write_buffer_bytes: int ): bool
Sets per-WebSocket pending message, pending byte, and write-buffer limits before server start. All limits must be positive. Returns false for invalid values, invalid server ownership, or a server that has already started.
Pending limits include messages currently draining on the owner thread. Exceeding a limit closes that peer without consuming another peer’s allowance. The write limit covers libhv’s unsent socket buffer, not bytes already accepted by the OS.
- Arguments:
server : WebSocketServer
pending_messages : int
pending_bytes : int
write_buffer_bytes : int
- set_document_root(server: WebSocketServer; dir: string )
Sets the root directory used for serving static files.
- Arguments:
server : WebSocketServer
dir : string implicit
- set_error_page(server: WebSocketServer; filename: string )
Sets the file served when the server returns an error response.
- Arguments:
server : WebSocketServer
filename : string implicit
- set_home_page(server: WebSocketServer; filename: string )
Sets the file served when a request maps to a directory (e.g. index.html).
- Arguments:
server : WebSocketServer
filename : string implicit
- set_index_of(server: WebSocketServer; dir: string )
Enables directory listing for the given directory path.
- Arguments:
server : WebSocketServer
dir : string implicit
- set_limits(server: WebSocketServer; http_body_bytes: int; websocket_message_bytes: int; pending_events: int; pending_bytes: int ): bool
Sets positive HTTP-body, complete WebSocket-message, pending-event count and queued-payload byte limits before start. Returns false for invalid values or a running server. Oversized HTTP bodies return 413; saturated HTTP admission returns 503. WebSocket overflow closes the connection. Never calling this retains legacy unbounded configuration.
- Arguments:
server : WebSocketServer
http_body_bytes : int
websocket_message_bytes : int
pending_events : int
pending_bytes : int
4.5.10. HTTP response helpers
REDIRECT (response: HttpResponse?; location: string; status: http_status) : http_status
SERVE_FILE (response: HttpResponse?; filepath: string) : http_status
SERVE_FILE (server: WebSocketServer; writer: HttpResponseWriter?; filepath: string) : int
set_content_type (request: HttpRequest?; content_type: string)
set_content_type (response: HttpResponse?; content_type: string)
set_header (request: HttpRequest?; key: string; value: string)
set_header (response: HttpResponse?; key: string; value: string)
set_header (server: WebSocketServer; writer: HttpResponseWriter?; key: string; value: string) : int
- DATA(response: HttpResponse?; data: string; length: int; status: http_status = dashv::http_status.OK ): http_status
Sends raw data as the response body with the given status code.
- Arguments:
response : HttpResponse? implicit
data : string implicit
length : int
status : http_status
- JSON(response: HttpResponse?; json_string: string; status: http_status = dashv::http_status.OK ): http_status
Sends a JSON response with the given status code.
- Arguments:
response : HttpResponse? implicit
json_string : string implicit
status : http_status
- REDIRECT(response: HttpResponse?; location: string; status: http_status ): http_status
Sends an HTTP redirect response to the specified location.
- Arguments:
response : HttpResponse? implicit
location : string implicit
status : http_status
4.5.10.1. SERVE_FILE
- SERVE_FILE(response: HttpResponse?; filepath: string ): http_status
Sends a file as the response body, setting the content type automatically.
- Arguments:
response : HttpResponse? implicit
filepath : string implicit
- SERVE_FILE(server: WebSocketServer; writer: HttpResponseWriter?; filepath: string ): int
- SERVE_FILE_STREAM(server: WebSocketServer; writer: HttpResponseWriter?; filepath: string; max_bytes: int64 ): int
Queues a bounded regular-file response through a live streaming writer. Returns zero when queued, or -1 for invalid server/writer ownership, an empty path, or a nonpositive size limit. The queued operation responds with 404 for an unavailable or non-regular file, 413 above max_bytes, or 200 otherwise. HEAD sends no body.
The event loop reads at most one 64 KiB chunk after the previous write drains. Disconnect and server shutdown release the transfer. Existing response headers are retained; an unset content type defaults to application/octet-stream.
- Arguments:
server : WebSocketServer
writer : HttpResponseWriter? implicit
filepath : string implicit
max_bytes : int64
- TEXT_PLAIN(response: HttpResponse?; text: string; status: http_status = dashv::http_status.OK ): http_status
Sends a plain-text response with the given status code.
- Arguments:
response : HttpResponse? implicit
text : string implicit
status : http_status
4.5.10.2. set_content_type
- set_content_type(request: HttpRequest?; content_type: string )
Sets the Content-Type header on a response or request.
- Arguments:
request : HttpRequest? implicit
content_type : string implicit
- set_content_type(response: HttpResponse?; content_type: string )
4.5.10.3. set_header
- set_header(request: HttpRequest?; key: string; value: string )
Sets a response or request header.
- Arguments:
request : HttpRequest? implicit
key : string implicit
value : string implicit
- set_header(response: HttpResponse?; key: string; value: string )
- set_header(server: WebSocketServer; writer: HttpResponseWriter?; key: string; value: string ): int
4.5.11. HTTP client requests
- request(request: HttpRequest?; block: block<(HttpResponse?):void> )
Sends an HTTP request configured via an HttpRequest object and invokes the block with the response.
- Arguments:
request : HttpRequest? implicit
block : block<( HttpResponse?):void> implicit
4.5.11.1. request_cb
- request_cb(request: HttpRequest?; on_body: block<(string):void>; on_complete: block<(HttpResponse?):void> )
Sends an HTTP request and invokes on_body with each body chunk as a string as it arrives, then calls on_complete with the final response. Use this for streaming protocols like SSE where the body is delivered incrementally.
- Arguments:
request : HttpRequest? implicit
on_body : block<(string):void> implicit
on_complete : block<( HttpResponse?):void> implicit
- request_cb(request: HttpRequest?; on_body: block<(uint8 const?;int):void>; on_complete: block<(HttpResponse?):void> )
- request_checked(request: HttpRequest?; ca_file: string; max_response_bytes: int; block: block<(HttpResponse?#):void> ): int
Performs synchronous verified HTTPS with a response-body limit of 1–16777216 bytes. Empty ca_file selects system trust; otherwise the given CA file establishes trust. Timeout must be 1–120 seconds. Redirects, retries and request proxies are disabled. Returns zero on transport success and then invokes block with a borrowed response, including non-2xx statuses; other results do not invoke block. Truncation, oversized bodies, invalid URLs and TLS verification failure are errors. Copy any needed response data inside block.
- Arguments:
request : HttpRequest? implicit
ca_file : string implicit
max_response_bytes : int
block : block<( HttpResponse?#):void> implicit
- status_message(response: HttpResponse? ): string
Returns the status message string for the given HTTP response.
- Arguments:
response : HttpResponse? implicit
4.5.12. Message and header access
- HttpResponse.content_length(self: HttpResponse ): int
Returns the content length of the HTTP response body.
- Arguments:
self : HttpResponse implicit
- client_ip(request: HttpRequest? ): string
Peer address of the connection the request arrived on, as recorded by the server when it accepted the socket. Unlike a header such as X-Forwarded-For, a client cannot set this, so it is what a service checks to tell a loopback caller from a proxied one; it is empty when the server did not record an address.
- Arguments:
request : HttpRequest? implicit
- each_header(message: HttpMessage?; block: block<(string;string):void> )
Iterates over all headers of an HTTP message, invoking the block with each key-value pair.
- Arguments:
message : HttpMessage? implicit
block : block<(string;string):void> implicit
- get_header(message: HttpMessage?; key: string ): string
Returns the value of a specific HTTP header from a message.
- Arguments:
message : HttpMessage? implicit
key : string implicit
4.5.13. Request configuration
- allow_redirect(request: HttpRequest?; on: bool )
Enables or disables automatic following of HTTP redirects.
- Arguments:
request : HttpRequest? implicit
on : bool
- each_param(request: HttpRequest?; block: block<(string;string):void> )
Iterates over all query parameters of an HTTP request, invoking the block with each key-value pair.
- Arguments:
request : HttpRequest? implicit
block : block<(string;string):void> implicit
- get_param(request: HttpRequest?; key: string ): string
Returns the value of a query parameter from an HTTP request.
- Arguments:
request : HttpRequest? implicit
key : string implicit
- set_basic_auth(request: HttpRequest?; username: string; password: string )
Sets HTTP Basic authentication credentials on a request.
- Arguments:
request : HttpRequest? implicit
username : string implicit
password : string implicit
- set_bearer_token_auth(request: HttpRequest?; token: string )
Sets a Bearer token authentication header on a request.
- Arguments:
request : HttpRequest? implicit
token : string implicit
- set_connect_timeout(request: HttpRequest?; seconds: int )
Sets the connection timeout in seconds.
- Arguments:
request : HttpRequest? implicit
seconds : int
- set_param(request: HttpRequest?; key: string; value: string )
Sets a query parameter on an HTTP request.
- Arguments:
request : HttpRequest? implicit
key : string implicit
value : string implicit
- set_timeout(request: HttpRequest?; seconds: int )
Sets the overall request timeout in seconds.
- Arguments:
request : HttpRequest? implicit
seconds : int
4.5.15. Form data
each_form_field (request: HttpRequest?; block: block<(string;string;string):void>)
get_form_data (request: HttpRequest?; name: string) : string
get_url_encoded (request: HttpRequest?; key: string) : string
save_form_file (request: HttpRequest?; name: string; path: string) : int
set_form_data (request: HttpRequest?; name: string; value: string)
set_form_file (request: HttpRequest?; name: string; filepath: string)
set_url_encoded (request: HttpRequest?; key: string; value: string)
- each_form_field(request: HttpRequest?; block: block<(string;string;string):void> )
Iterates over all form fields of a server-side request, invoking the block with name, filename, and content type.
- Arguments:
request : HttpRequest? implicit
block : block<(string;string;string):void> implicit
- get_form_data(request: HttpRequest?; name: string ): string
Returns the value of a form field from a server-side request.
- Arguments:
request : HttpRequest? implicit
name : string implicit
- get_url_encoded(request: HttpRequest?; key: string ): string
Returns the value of a URL-encoded form field from a server-side request.
- Arguments:
request : HttpRequest? implicit
key : string implicit
- save_form_file(request: HttpRequest?; name: string; path: string ): int
Saves an uploaded form file to disk. Returns 0 on success.
- Arguments:
request : HttpRequest? implicit
name : string implicit
path : string implicit
- set_form_data(request: HttpRequest?; name: string; value: string )
Sets a form field value on a multipart request.
- Arguments:
request : HttpRequest? implicit
name : string implicit
value : string implicit
- set_form_file(request: HttpRequest?; name: string; filepath: string )
Attaches a file to a multipart request.
- Arguments:
request : HttpRequest? implicit
name : string implicit
filepath : string implicit
- set_url_encoded(request: HttpRequest?; key: string; value: string )
Sets a URL-encoded form field on a request.
- Arguments:
request : HttpRequest? implicit
key : string implicit
value : string implicit
4.5.16. SSE response writer
close_writer (server: WebSocketServer; writer: HttpResponseWriter?)
end_headers (server: WebSocketServer; writer: HttpResponseWriter?; key: string; value: string) : int
is_writer_connected (server: WebSocketServer; writer: HttpResponseWriter?) : bool
release_writer (server: WebSocketServer; writer: HttpResponseWriter?)
set_writer_keepalive_timeout (server: WebSocketServer; writer: HttpResponseWriter?; timeout_ms: int)
sse_event (server: WebSocketServer; writer: HttpResponseWriter?; data: string; event: string) : int
write_chunked (server: WebSocketServer; writer: HttpResponseWriter?; data: string) : int
- close_writer(server: WebSocketServer; writer: HttpResponseWriter? )
Finishes a streamed response and releases the writer, closing the connection.
- Arguments:
server : WebSocketServer
writer : HttpResponseWriter? implicit
- end_headers(server: WebSocketServer; writer: HttpResponseWriter?; key: string; value: string ): int
Ends the response header block, sending the status line and one header (key and value), so the body can then be streamed with write_chunked.
- Arguments:
server : WebSocketServer
writer : HttpResponseWriter? implicit
key : string implicit
value : string implicit
- is_writer_connected(server: WebSocketServer; writer: HttpResponseWriter? ): bool
Returns true while the writer’s client connection is still open (false for null, unknown, or released writers). The asynchronous writer operations never report a dead peer, so a long-lived stream polls this to evict clients that disconnected.
- Arguments:
server : WebSocketServer
writer : HttpResponseWriter? implicit
- release_writer(server: WebSocketServer; writer: HttpResponseWriter? )
Releases a chunked/SSE response writer previously obtained from the server.
- Arguments:
server : WebSocketServer
writer : HttpResponseWriter? implicit
- respond(server: WebSocketServer; writer: HttpResponseWriter?; status: int; content_type: string; body: string ): int
Sends a complete buffered response (status code, content type, and whole body) through the streaming response writer.
- Arguments:
server : WebSocketServer
writer : HttpResponseWriter? implicit
status : int
content_type : string implicit
body : string implicit
- set_writer_keepalive_timeout(server: WebSocketServer; writer: HttpResponseWriter?; timeout_ms: int )
Sets how long a retained streaming response writer may remain inactive before it expires. Extend the timeout for deferred work, then restore the normal timeout before sending the terminal response.
- Arguments:
server : WebSocketServer
writer : HttpResponseWriter? implicit
timeout_ms : int
- sse_event(server: WebSocketServer; writer: HttpResponseWriter?; data: string; event: string ): int
Writes one Server-Sent Events frame (the data payload plus an optional event name; an empty name emits an unnamed event) to the streaming response writer.
- Arguments:
server : WebSocketServer
writer : HttpResponseWriter? implicit
data : string implicit
event : string implicit
- write_chunked(server: WebSocketServer; writer: HttpResponseWriter?; data: string ): int
Writes one chunk of body data to the streaming response writer using chunked transfer encoding.
- Arguments:
server : WebSocketServer
writer : HttpResponseWriter? implicit
data : string implicit
4.5.17. Logging
- hv_set_log_file(path: string )
Sends libhv’s own log to a daily file <path>.YYYYMMDD.log (the directory must exist) instead of libhv.YYYYMMDD.log in the working directory. An empty path changes nothing; DASLIVE_HV_LOG still routes the log to a console or silences it.
- Arguments:
path : string implicit