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)
| 1881 | // default cap is too small — but always pass an explicit cap, never |
| 1882 | // remove the wrapper. |
| 1883 | func decodeJSONWithLimit(r *http.Request, v interface{}, maxBytes int64) error { |
| 1884 | // http.MaxBytesReader.Close() is a no-op; the decoder leaves r.Body at |
| 1885 | // EOF anyway. Setting this here also lets the server return a 413 |
| 1886 | // automatically via the error we wrap below. |
| 1887 | if r.Body != nil { |
| 1888 | r.Body = http.MaxBytesReader(nil, r.Body, maxBytes) |
| 1889 | } |
| 1890 | if err := json.NewDecoder(r.Body).Decode(v); err != nil { |
| 1891 | return fmt.Errorf("invalid JSON: %w", err) |
| 1892 | } |
| 1893 | return nil |
| 1894 | } |
| 1895 | |
| 1896 | // getWorkspaceID resolves workspace slug/ID from the request. |
| 1897 | // If RequireWorkspaceAccess already resolved the workspace, reads from context. |