diff --git a/async/httpaf_async.ml b/async/httpaf_async.ml index b493586..95a30fb 100644 --- a/async/httpaf_async.ml +++ b/async/httpaf_async.ml @@ -90,16 +90,17 @@ let read fd buffer = open Httpaf module Server = struct - let create_connection_handler ?config ~request_handler ~error_handler = + module Config = Server_connection.Config + + let create_connection_handler ?(config=Config.default) ~request_handler ~error_handler = fun client_addr socket -> let fd = Socket.fd socket in let writev = Faraday_async.writev_of_fd fd in let request_handler = request_handler client_addr in let error_handler = error_handler client_addr in - let conn = Server_connection.create ?config ~error_handler request_handler in + let conn = Server_connection.create ~config ~error_handler request_handler in let read_complete = Ivar.create () in - (* XXX(seliopou): Make this configurable *) - let buffer = Buffer.create 0x1000 in + let buffer = Buffer.create config.read_buffer_size in let rec reader_thread () = match Server_connection.next_read_operation conn with | `Read -> diff --git a/lib/httpaf.mli b/lib/httpaf.mli index 8c69f1f..24804b5 100644 --- a/lib/httpaf.mli +++ b/lib/httpaf.mli @@ -695,7 +695,8 @@ end module Server_connection : sig module Config : sig type t = - { response_buffer_size : int (** Default is [1024] *) + { read_buffer_size : int (** Default is [4096] *) + ; response_buffer_size : int (** Default is [1024] *) ; response_body_buffer_size : int (** Default is [4096] *) } diff --git a/lib/server_connection.ml b/lib/server_connection.ml index ee3c653..f0a66a8 100644 --- a/lib/server_connection.ml +++ b/lib/server_connection.ml @@ -48,11 +48,13 @@ module Writer = Serialize.Writer module Config = struct type t = - { response_buffer_size : int + { read_buffer_size : int + ; response_buffer_size : int ; response_body_buffer_size : int } let default = - { response_buffer_size = 0x400 + { read_buffer_size = 0x1000 + ; response_buffer_size = 0x400 ; response_body_buffer_size = 0x1000 } end @@ -128,7 +130,7 @@ let create ?(config=Config.default) ?(error_handler=default_error_handler) reque { Config . response_buffer_size ; response_body_buffer_size - } = config + ; _ } = config in let writer = Writer.create ~buffer_size:response_buffer_size () in let request_queue = Queue.create () in diff --git a/lwt/httpaf_lwt.ml b/lwt/httpaf_lwt.ml index 2da8c10..779b4f1 100644 --- a/lwt/httpaf_lwt.ml +++ b/lwt/httpaf_lwt.ml @@ -78,20 +78,19 @@ module Server = struct type request_handler = Lwt_unix.file_descr Httpaf.Server_connection.request_handler + module Config = Httpaf.Server_connection.Config - - let create_connection_handler ?config ~request_handler ~error_handler = + let create_connection_handler ?(config=Config.default) ~request_handler ~error_handler = fun client_addr socket -> let module Server_connection = Httpaf.Server_connection in let connection = Server_connection.create - ?config + ~config ~error_handler:(error_handler client_addr) (request_handler client_addr) in - - let read_buffer = Buffer.create 0x1000 in + let read_buffer = Buffer.create config.read_buffer_size in let read_loop_exited, notify_read_loop_exited = Lwt.wait () in let rec read_loop () =