Commits

Anonymous committed 4c8f57f

Amall_http: less IO operations when outputting http response Body_string

  • Participants
  • Parent commits b445286

Comments (0)

Files changed (1)

File src/amall_http.ml

     code
     reas
     (String.concat "" &
+     (* todo: buffer instead of list of strings *)
      List.map string_of_header &
      processed_headers
     )
 ;
 
 
-value output_body outch rs_body =
-  match rs_body with
-  [ No_body -> IO.return ()
-  | Body_string s -> IO.write outch s
-  | File_contents fn sz ->
-      output_body_file outch fn sz
-  ]
-;
-
-
 value rec output_response ~is_head outch rs : IO.m unit =
   IO.catch
     (fun () ->
   match res_hstr with
   [ `Error rs -> output_response ~is_head outch rs
   | `Ok hstr ->
-      IO.write outch hstr >>% fun () ->
       (if is_head
-       then IO.return ()
-       else output_body outch rs.rs_body
-       ) >>% fun () ->
+       then
+         IO.write outch hstr
+       else
+         match rs.rs_body with
+         [ No_body -> IO.write outch hstr
+         | Body_string s -> IO.write outch (hstr ^ s)
+         | File_contents fn sz ->
+             IO.write outch hstr >>% fun () ->
+             output_body_file outch fn sz
+         ]
+      ) >>% fun () ->
       IO.flush outch
   ]
 ;