Documentation
¶
Overview ¶
Package nodejson writes JSON byte for byte as the previous runtime did (JavaScript's JSON.stringify) and gives an answer the ETag that runtime's dispatcher put on it, so a page's conditional request keeps working across the switch.
Index ¶
- func Answer(r *http.Request, status int, v any, h http.Header) (int, any, http.Header)
- func BodyUTF8(r *http.Request) bool
- func ETag(payload []byte) string
- func Fresh(h http.Header, etag string) bool
- func Marshal(v any) []byte
- func ParseBody(r *http.Request, limit int64, limitName string) (v any, raw string, status int, refusal string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Answer ¶
Answer is a JSON route's answer the way the old dispatcher sent it: the ETag of the exact bytes, and 304 when the caller already holds them. The value is handed on as raw JSON.
func BodyUTF8 ¶
BodyUTF8 says whether a request's body is text in UTF-8 as its content type names it (no charset, or utf-8): the previous dispatcher decoded any other charset, which ParseBody does not.
func Fresh ¶
Fresh says whether the request's If-None-Match already names the tag (the answer is then 304).
func Marshal ¶
Marshal encodes v as JSON.stringify would: no HTML escaping, U+2028 and U+2029 left as they are. Struct field order is the key order, so a struct must declare its fields in the order the old handler built its object. Strings must be valid UTF-8 (JavaScript strings had already replaced invalid bytes when they were read).
func ParseBody ¶
func ParseBody(r *http.Request, limit int64, limitName string) (v any, raw string, status int, refusal string)
ParseBody reads a body as the previous dispatcher did before a handler ran: refused past limit (413, "Body exceeded <limitName> limit"), decoded as UTF-8 without a leading BOM, then JSON (empty is {}) for a JSON type, a form as an object, anything else as text. A refusal is a status and its text/plain body; raw is the decoded text.
Types ¶
This section is empty.