improve headers api

This commit is contained in:
Astazium 2026-09-22 16:10:52 +03:00
parent e8d36427ba
commit 4667b801d3
7 changed files with 57 additions and 33 deletions

View file

@ -197,7 +197,7 @@ The ServerSocket class for the HTTP server is identical to the TCP server's
The `handler` may respond in two ways:
* return a response table `{status: int, headers: table<string>, body: string|Bytearray}`
* return a response table `{status: int, headers: table<string,string>, body: string|Bytearray}`
(any field may be omitted; `status` defaults to `200`);
* or call `request:respond(status, body, headers)` itself, e.g. from a
coroutine, for a delayed answer. In that case the handler's return value
@ -213,7 +213,7 @@ The `request` class has the following fields and methods:
request.method -> string, e.g. "GET"
request.path -> string, decoded path without the query string
request.query -> string, raw query string (part after '?', if any)
request.headers -> table<string>, "Name: value" entries
request.headers -> table<string,string>, {["Name"] = "value", ...}
request.body -> string|Bytearray
request.remote_addr -> string
request.remote_port -> int
@ -226,14 +226,14 @@ request:json() -> any
request:respond(
[optional] status: int=200,
[optional] body: string|Bytearray,
[optional] headers: table<string>
[optional] headers: table<string,string>
)
-- Builds a JSON response table ready to be returned from a handler.
network.http_json(
data: any,
[optional] status: int=200,
[optional] headers: table<string>
[optional] headers: table<string,string>
) --> table
```

View file

@ -267,7 +267,7 @@ network.http_open(
Ответить на запрос `handler` может двумя способами:
* вернуть таблицу ответа `{status: int, headers: table<string>, body: string}`
* вернуть таблицу ответа `{status: int, headers: table<string,string>, body: string}`
(любое поле можно опустить; `status` по умолчанию равен `200`);
* или самостоятельно вызвать `request:respond(status, body, headers)`,
например из корутины, для отложенного ответа. В этом случае возвращаемое
@ -282,7 +282,7 @@ network.http_open(
request.method -> string, например "GET"
request.path -> string, декодированный путь без строки запроса
request.query -> string, необработанная строка запроса (часть после '?', если есть)
request.headers -> table<string>, записи вида "Имя: значение"
request.headers -> table<string,string>, {["Имя"] = "значение", ...}
request.body -> string|Bytearray
request.remote_addr -> string
request.remote_port -> int
@ -295,14 +295,14 @@ request:json() -> any
request:respond(
[опционально] status: int=200,
[опционально] body: string|Bytearray,
[опционально] headers: table<string>
[опционально] headers: table<string,string>
)
-- Собирает таблицу JSON-ответа, готовую для возврата из обработчика.
network.http_json(
data: any,
[опционально] status: int=200,
[опционально] headers: table<string>
[опционально] headers: table<string,string>
) -> table
```