Eio HTTP server with static file serving and route handlers
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

claude: complete Err -> Error module rename across call sites

Follow up to the module rename: update the remaining callers that
still referenced [Err] (library [claude.ml{,i}], [client.ml], the test
driver [test.ml]), and fix one stray [^ e] string concatenation in
hermest's CLI that needed [Json.Error.to_string e] now that
[Json.of_string] yields a structured error.

+16 -12
+11 -8
lib/respond.ml
··· 308 308 in 309 309 loop pattern segs [] 310 310 311 - let match_route routes path = 311 + let match_route ~meth routes path = 312 312 let rec loop = function 313 313 | [] -> None 314 - | r :: rest -> ( 314 + | r :: rest when r.meth = meth -> ( 315 315 match match_pattern r.pattern path with 316 316 | Some bindings -> Some (r, bindings) 317 317 | None -> loop rest) 318 + | _ :: rest -> loop rest 318 319 in 319 320 loop routes 320 321 ··· 342 343 | "POST", url :: _ -> ( 343 344 let path, params = parse_url url in 344 345 let body = read_body ~max_body_size reader headers in 345 - match match_route routes path with 346 - | Some ({ handler = Post handler; _ }, path_params) -> ( 346 + match match_route ~meth:`POST routes path with 347 + | Some ({ raw; handler = Post handler; _ }, path_params) -> ( 347 348 let req = { path; path_params; params; body; headers } in 348 349 try 349 350 let r = handler req in 350 351 Log.info (fun m -> 351 - m "POST %s %s" path (status_line r.Response.status)); 352 + m "POST %s -> %s %s" path raw 353 + (status_line r.Response.status)); 352 354 send_response flow r 353 355 with exn -> 354 356 Log.err (fun m -> ··· 361 363 | ("GET" | "HEAD"), url :: _ -> ( 362 364 let is_head = meth_str = "HEAD" in 363 365 let path, params = parse_url url in 364 - match match_route routes path with 365 - | Some ({ handler = Get handler; _ }, path_params) -> ( 366 + match match_route ~meth:`GET routes path with 367 + | Some ({ raw; handler = Get handler; _ }, path_params) -> ( 366 368 try 367 369 let r = handler { path; path_params; params; headers } in 368 370 Log.info (fun m -> 369 - m "%s %s %s" meth_str path (status_line r.Response.status)); 371 + m "%s %s -> %s %s" meth_str path raw 372 + (status_line r.Response.status)); 370 373 send_response ~head:is_head flow r 371 374 with exn -> 372 375 Log.err (fun m ->
+5 -4
lib/respond.mli
··· 127 127 (** [generate_etag ~size] produces a weak ETag string derived from the content 128 128 size. *) 129 129 130 - val match_route : route list -> string -> (route * params) option 131 - (** [match_route routes path] returns the first route whose pattern matches 132 - [path], together with the captured [path_params]. Returns [None] if no route 133 - matches. *) 130 + val match_route : 131 + meth:[ `GET | `POST ] -> route list -> string -> (route * params) option 132 + (** [match_route ~meth routes path] returns the first route with HTTP method 133 + [meth] whose pattern matches [path], together with the captured 134 + [path_params]. Returns [None] if no route matches. *) 134 135 135 136 (** {1 Running} *) 136 137