internal/api/request.go
internal/api · 141 lines · 6 declarations · source
Declarations
const maxRequestBytes
const maxRequestBytes = 1 << 20
func decode
func decode(w http.ResponseWriter, r *http.Request, into any) bool
decode validates the complete wire representation before populating a request. The standard decoder alone accepts duplicate keys, repairs invalid UTF-8 and stops after the first value; those behaviours let the same bytes mean different things to the caller and the service.
func unambiguousObject
func unambiguousObject(body []byte) error
func uniqueMembers
func uniqueMembers(d *json.Decoder, opening json.Delim, depth int) error
uniqueMembers walks tokens rather than materialising a second request tree. Nesting is bounded independently of byte size, and keys are scoped to each object. Folded keys also refuse aliases such as question/QUESTION, which encoding/json would otherwise assign to the same Go field.
func foldJSONKey
func foldJSONKey(key string) string
func validSurrogates
func validSurrogates(body []byte) bool
JSON's UTF-16 escapes must name Unicode scalar values. encoding/json repairs an unpaired surrogate to U+FFFD; doing that to evidence would change the caller's content before storage.