carlos / todomvc-bakeoff Public
fix(ocaml): answer 413 for oversized bodies
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+6
−6
apps/ocaml/bin/main.ml+6 −6
diff --git a/apps/ocaml/bin/main.ml b/apps/ocaml/bin/main.ml| index 3e1f655..48a4cec 100644 |
| --- a/apps/ocaml/bin/main.ml |
| +++ b/apps/ocaml/bin/main.ml |
| @@ -31,15 +31,15 @@ let to_app_request req body = |
| } |
| let callback app _conn req body = |
| - let read_body () = |
| + let body = |
| match Http.Request.meth req with |
| - | `POST -> Eio.Buf_read.(parse_exn take_all) ~max_size:max_body body |
| - | _ -> "" |
| + | `POST -> Eio.Buf_read.(parse take_all) ~max_size:max_body body |
| + | _ -> Ok "" |
| in |
| let (res : Todo.App.response) = |
| - match read_body () with |
| - | body -> Todo.App.handle app (to_app_request req body) |
| - | exception Eio.Buf_read.Buffer_limit_exceeded -> Todo.App.text 413 "Too large\n" |
| + match body with |
| + | Ok body -> Todo.App.handle app (to_app_request req body) |
| + | Error _ -> Todo.App.text 413 "Request body too large\n" |
| in |
| let headers = Http.Header.of_list res.headers in |
| let status = Http.Status.of_int res.status in |