1. Dmitry Grebeniuk
  2. amall

Commits

Dmitry Grebeniuk  committed 6a0c556

monadic 'list map' -> List.rev_map

  • Participants
  • Parent commits 878a354
  • Branches default

Comments (0)

Files changed (1)

File src/amall_http.ml

View file
     )
 ;
 
-value list_map_all func lst =
-  inner [] lst
-  where rec inner rev_acc lst =
-    match lst with
-    [ [] -> I.return & List.rev rev_acc
-    | [h :: t] ->
-        func h >>= fun fh -> inner [fh :: rev_acc] t
-    ]
-;
-
 
 value can_upgrade_to_websocket rq =
   let (ver_maj, ver_min) = rq.rq_version
           max_headers_size
     | I.IE_done headers_rev -> I.return headers_rev
     ] >>= fun header_lines_rev ->
-    list_map_all
-      (  fun line ->
-           let (hname, sep, hval_sp) =
-             String.split_by_first ( (=) ':' ) line in
-           if String.length sep = 0 then fail "header without ':'"
-           else
-             let hval = String.trim is_whitespace hval_sp in
-             I.return (hname, hval)
-      )
-      header_lines_rev
-    >>= fun header_lines ->
+    (try
+       I.return &
+       List.rev_map
+         (fun line ->
+            let (hname, sep, hval_sp) =
+              String.split_by_first ( (=) ':' ) line in
+            if String.length sep = 0
+            then
+              raise (Bad_request "header without ':'")  (* inlined 'fail' *)
+            else
+              let hval = String.trim is_whitespace hval_sp in
+              (hname, hval)
+         )
+         header_lines_rev
+     with [ e -> I.throw_err e ]
+    ) >>= fun header_lines ->
     let rq_headers = make_headers header_lines in
     let rq_uri =
       match (request_uri__.authority, rq_headers.rqh_host) with