- WS handshake: same-origin CheckOrigin instead of allow-all
- route_ws require_auth/需要登录: broadcast/room need a session by default,
explicit opt-out for public feeds; unauthenticated handshakes get 401
- WS limits: 1 MiB per message, 256 replies per connect; transport errors
return {ok:false, error} instead of an empty success; empty rooms GC'd
- net host: enforce the 8 MiB response cap while reading (incl. error and
SSE error paths) so a peer cannot exhaust memory
- url_encode: %20 for space (URL segment semantics, not form +)
- docs: sync 网页 (route_ws 需要登录, connect caps) and CHANGELOG
- tests: gold expectations, live fixture opt-out, hub GC, ws auth gate
Co-authored-by: Cursor <cursoragent@cursor.com>
85 lines
2.4 KiB
Markdown
85 lines
2.4 KiB
Markdown
---
|
|
title: lib/net
|
|
description: English HTTP(S) wrappers. Optional headers / content_type via host aliases.
|
|
---
|
|
|
|
English HTTP(S) wrappers. Optional headers / content_type via host aliases.
|
|
|
|
## http_get
|
|
+ `url`
|
|
+ `headers`=None
|
|
|
|
HTTPS supported. Optional named arg `headers=` (map). Responses are capped at 8 MiB before decoding, so an upstream cannot exhaust the interpreter's memory.
|
|
|
|
*> host_http_get url=`url` headers=`headers`*
|
|
|
|
## http_post
|
|
+ `url`
|
|
+ `body`
|
|
+ `content_type`=None
|
|
+ `headers`=None
|
|
|
|
Default content type is JSON. Optional `content_type=` / `headers=` (map).
|
|
|
|
*> host_http_post url=`url` body=`body` content_type=`content_type` headers=`headers`*
|
|
|
|
## http_post_sse
|
|
+ `url`
|
|
+ `body`
|
|
+ `content_type`=None
|
|
+ `headers`=None
|
|
+ `echo`=False
|
|
|
|
POST and consume OpenAI-compatible SSE. Returns `{status, events}` where `events` is a list of `{type, …}` maps (`delta` / `done` / `error`). Optional `echo=True` prints delta text to stdout as chunks arrive.
|
|
|
|
*> host_http_post_sse url=`url` body=`body` content_type=`content_type` headers=`headers` echo=`echo`*
|
|
|
|
## openai_sse_parse
|
|
+ `text`
|
|
+ `echo`=False
|
|
|
|
Offline: parse an OpenAI chat SSE body into the same event list (no network).
|
|
|
|
*> host_openai_sse_parse text=`text` echo=`echo`*
|
|
|
|
## http_request
|
|
+ `method`
|
|
+ `url`
|
|
+ `body`=None
|
|
+ `content_type`=None
|
|
+ `headers`=None
|
|
|
|
Optional `body=` / `content_type=` / `headers=`.
|
|
|
|
*> host_http_request method=`method` url=`url` body=`body` content_type=`content_type` headers=`headers`*
|
|
|
|
## url_encode
|
|
+ `text`
|
|
|
|
Percent-encode a URL segment. Spaces become `%20` (not form/query `+`), so literal `+` remains unambiguous in paths.
|
|
|
|
*> host_url_encode text=`text`*
|
|
|
|
## cookie_parse
|
|
+ `text`
|
|
+ `is_response`=False
|
|
|
|
Parse a `Cookie` request header (default) or one or more `Set-Cookie` response headers (`is_response=True`) into a list of `{name, value, path, domain, expires, max_age, secure, http_only, same_site}`.
|
|
|
|
*> host_cookie_parse text=`text` is_response=`is_response`*
|
|
|
|
## multipart_parse
|
|
+ `body`
|
|
+ `boundary`
|
|
|
|
Parse a `multipart/form-data` request body (given its `boundary`) into a list of `{name, filename?, content_type?, value}` parts.
|
|
|
|
*> host_multipart_parse body=`body` boundary=`boundary`*
|
|
|
|
## markdown_parse
|
|
+ `text`
|
|
|
|
Parse Markdown / GFM into HTML (pure transform, no network I/O).
|
|
|
|
*> host_markdown_parse text=`text`*
|