Commits

Anonymous committed 5edcd55

Amall_http: make_headers refactoring

Comments (0)

Files changed (1)

src/amall_http.ml

 
 (*****************************)
 
+
+value mkh_parse_connection hv =
+  List.map
+    (fun tok ->
+       if String.eq_nocase_latin1 tok "close"
+       then `Close
+       else if String.eq_nocase_latin1 tok "upgrade"
+       then `Upgrade
+       else `Other tok
+    )
+    (http_tokenize hv)
+;
+
+value mkh_parse_t_e hv =
+  List.flatten
+    (List.map
+      (fun tok ->
+         if String.eq_nocase_latin1 tok "identity"
+         then []
+         else if String.eq_nocase_latin1 tok "chunked"
+         then [`Chunked]
+         else if String.eq_nocase_latin1 tok "gzip"
+         then [`Gzip]
+         else [`Other tok]
+      )
+      (http_tokenize hv)
+    )
+;
+
 value (make_headers : list (string * string) -> rq_headers) lst =
   let connection = ref []
   and content_length = ref None
     (fun (hk, hv) ->
        let _add r = r.val := [hv :: r.val]
        and set_opt_int r =
-         try r.val := some & int_of_string hv
+         try r.val := Some (int_of_string hv)
          with [Failure _ -> ()]
        and addmap f r = r.val := List.append (f hv) r.val in
-       let parse_connection hv =
-         List.map
-           (fun tok ->
-              match String.lowercase tok with
-              [ "close" -> `Close
-              | "upgrade" -> `Upgrade
-              | _ -> `Other tok
-              ]
-           )
-           (http_tokenize hv)
-       and parse_t_e hv =
-         List.flatten
-           (List.map
-             (fun tok ->
-                match String.lowercase tok with
-                [ "identity" -> []
-                | "chunked" -> [`Chunked]
-                | "gzip" -> [`Gzip]
-                | x -> [`Other x]
-                ]
-             )
-             (http_tokenize hv)
-           )
-       in
-       match String.lowercase hk with
-       [ "connection" -> addmap parse_connection connection
-       | "content-length" -> set_opt_int content_length
-       | "transfer-length" -> set_opt_int transfer_length
-       | "transfer-encoding" -> addmap parse_t_e transfer_encoding
-       | "host" ->
-           match (host.val, Uri.parse_host_portopt hv) with
-           [ (None, ((Some _) as some_h)) -> host.val := some_h
-           | _ -> ()
-           ]
-       | _ -> ()
-       ]
+       if String.eq_nocase_latin1 hk "connection"
+       then addmap mkh_parse_connection connection
+       else if String.eq_nocase_latin1 hk "content-length"
+       then set_opt_int content_length
+       else if String.eq_nocase_latin1 hk "transfer-length"
+       then set_opt_int transfer_length
+       else if String.eq_nocase_latin1 hk "transfer-encoding"
+       then addmap mkh_parse_t_e transfer_encoding
+       else if String.eq_nocase_latin1 hk "host"
+       then
+         match (host.val, Uri.parse_host_portopt hv) with
+         [ (None, ((Some _) as some_h)) -> host.val := some_h
+         | _ -> ()
+         ]
+       else ()
     )
     lst
   in