MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / decodeJSONWithLimit

Function decodeJSONWithLimit

internal/server/server.go:1847–1858  ·  view source on GitHub ↗

decodeJSONWithLimit is the size-configurable variant. Use this for endpoints that accept large payloads (e.g. bulk-import) where the default cap is too small — but always pass an explicit cap, never remove the wrapper.

(r *http.Request, v interface{}, maxBytes int64)

Source from the content-addressed store, hash-verified

1845// default cap is too small — but always pass an explicit cap, never
1846// remove the wrapper.
1847func decodeJSONWithLimit(r *http.Request, v interface{}, maxBytes int64) error {
1848 // http.MaxBytesReader.Close() is a no-op; the decoder leaves r.Body at
1849 // EOF anyway. Setting this here also lets the server return a 413
1850 // automatically via the error we wrap below.
1851 if r.Body != nil {
1852 r.Body = http.MaxBytesReader(nil, r.Body, maxBytes)
1853 }
1854 if err := json.NewDecoder(r.Body).Decode(v); err != nil {
1855 return fmt.Errorf("invalid JSON: %w", err)
1856 }
1857 return nil
1858}
1859
1860// getWorkspaceID resolves workspace slug/ID from the request.
1861// If RequireWorkspaceAccess already resolved the workspace, reads from context.

Callers 3

decodeJSONFunction · 0.85
handleImportWorkspaceMethod · 0.85

Calls 1

DecodeMethod · 0.65

Tested by 1