Skip to content

Commit

Permalink
chore: fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
anmonteiro committed Jan 5, 2025
1 parent e1fa28d commit a19576f
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 174 deletions.
29 changes: 13 additions & 16 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

98 changes: 49 additions & 49 deletions lib/body.ml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ end = struct

let is_none t = t == none
let is_some t = not (is_none t)
let call_if_some ~sw t = t ~sw
let call_if_some ~sw t upgrade_handler = t ~sw upgrade_handler
end

module Unix_fd = struct
Expand Down Expand Up @@ -111,7 +111,10 @@ let of_stream ?(length = `Chunked) stream =
create
~length
(`Stream
{ stream; read_counter = 0; error_received = ref default_error_received })
{ stream
; read_counter = 0
; error_received = ref default_error_received
})

let of_string_stream ?(length = `Chunked) stream =
let stream =
Expand All @@ -124,7 +127,10 @@ let of_string_stream ?(length = `Chunked) stream =
create
~length
(`Stream
{ stream; read_counter = 0; error_received = ref default_error_received })
{ stream
; read_counter = 0
; error_received = ref default_error_received
})

let of_string s =
let length = `Fixed (Int64.of_int (String.length s)) in
Expand Down Expand Up @@ -157,7 +163,7 @@ let sendfile ?length path =
(create
~length
(`Sendfile
{ fd; waiter; notifier; error_received = ref default_error_received }))
{ fd; waiter; notifier; error_received = ref default_error_received }))

(* TODO: accept buffer for I/O, so that caller can pool buffers? *)
let stream_of_fd ?on_close fd =
Expand Down Expand Up @@ -331,14 +337,13 @@ module Raw = struct
module Writer : Writer
end

let to_stream :
type a.
(module Reader with type t = a)
-> ?on_eof:(body_stream -> unit)
-> body_length:length
-> body_error:Error.t
-> a
-> body_stream
let to_stream : type a.
(module Reader with type t = a)
-> ?on_eof:(body_stream -> unit)
-> body_length:length
-> body_error:Error.t
-> a
-> body_stream
=
fun (module Reader) ?on_eof ~body_length ~body_error body ->
let total_len = ref 0L in
Expand Down Expand Up @@ -383,7 +388,7 @@ module Raw = struct
| (_ : Error.t) ->
(* `None` closes the stream. The promise `t.error_received` remains
* fulfilled, which signals that the stream hasn't closed cleanly.
*)
*)
None)
and t =
lazy
Expand All @@ -394,14 +399,13 @@ module Raw = struct
in
Lazy.force t

let to_t :
type a.
(module Reader with type t = a)
-> ?on_eof:(body_stream -> unit)
-> body_length:length
-> body_error:Error.t
-> a
-> t
let to_t : type a.
(module Reader with type t = a)
-> ?on_eof:(body_stream -> unit)
-> body_length:length
-> body_error:Error.t
-> a
-> t
=
fun (module Reader) ?on_eof ~body_length ~body_error body ->
match body_length with
Expand All @@ -410,39 +414,36 @@ module Raw = struct
create
~length:body_length
(`Stream
(to_stream (module Reader) ?on_eof ~body_error ~body_length body))

let to_request_body :
type a.
(module Reader with type t = a)
-> ?on_eof:(body_stream -> unit)
-> body_length:length
-> a
-> t
(to_stream (module Reader) ?on_eof ~body_error ~body_length body))

let to_request_body : type a.
(module Reader with type t = a)
-> ?on_eof:(body_stream -> unit)
-> body_length:length
-> a
-> t
=
fun reader ?on_eof ~body_length body ->
to_t reader ?on_eof ~body_length ~body_error:`Bad_request body

let incomplete_body_error =
`Malformed_response "missing bytes in response body"

let to_response_body :
type a.
(module Reader with type t = a)
-> ?on_eof:(body_stream -> unit)
-> body_length:length
-> a
-> t
let to_response_body : type a.
(module Reader with type t = a)
-> ?on_eof:(body_stream -> unit)
-> body_length:length
-> a
-> t
=
fun reader ?on_eof ~body_length body ->
to_t reader ?on_eof ~body_length ~body_error:incomplete_body_error body

let flush_and_close :
type a.
(module Writer with type t = a)
-> a
-> ([ `Written | `Closed ] -> unit)
-> unit
let flush_and_close : type a.
(module Writer with type t = a)
-> a
-> ([ `Written | `Closed ] -> unit)
-> unit
=
fun (module Writer) body f ->
Writer.close body;
Expand All @@ -451,12 +452,11 @@ module Raw = struct
exception Local

let stream_write_body =
let stream_write_body :
type a.
(module Writer with type t = a)
-> a
-> Bigstringaf.t IOVec.t Stream.t
-> unit
let stream_write_body : type a.
(module Writer with type t = a)
-> a
-> Bigstringaf.t IOVec.t Stream.t
-> unit
=
fun (module Writer) body stream ->
Stream.iter
Expand Down
18 changes: 9 additions & 9 deletions lib/http1.ml
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ module MakeHTTP1 (Runtime_scheme : Scheme.Runtime.SCHEME) :
t, t.runtime

let request
t
~flush_headers_immediately
~error_handler
~response_handler
req
t
~flush_headers_immediately
~error_handler
~response_handler
req
=
let response_handler response body =
let request_method =
Expand All @@ -85,7 +85,7 @@ module MakeHTTP1 (Runtime_scheme : Scheme.Runtime.SCHEME) :
*
* A server MUST NOT send any Transfer-Encoding or Content-Length
* header fields in a 2xx (Successful) response to CONNECT.
*)
*)
`GET
in
(* TODO: revisit whether this is necessary. *)
Expand Down Expand Up @@ -156,7 +156,7 @@ module MakeHTTP1 (Runtime_scheme : Scheme.Runtime.SCHEME) :
end

let make_error_handler ~fd error_handler :
Eio.Net.Sockaddr.stream -> Httpun.Server_connection.error_handler
Eio.Net.Sockaddr.stream -> Httpun.Server_connection.error_handler
=
fun client_addr ?request error start_response ->
let start_response headers = start_response (Headers.to_http1 headers) in
Expand All @@ -178,7 +178,7 @@ module MakeHTTP1 (Runtime_scheme : Scheme.Runtime.SCHEME) :
(error :> Error.server)

let make_request_handler ~sw ~config ~fd handler :
Eio.Net.Sockaddr.stream -> Httpun.Reqd.t Gluten.reqd -> unit
Eio.Net.Sockaddr.stream -> Httpun.Reqd.t Gluten.reqd -> unit
=
fun client_addr reqd ->
let { Gluten.reqd; upgrade } = reqd in
Expand Down Expand Up @@ -217,7 +217,7 @@ module MakeHTTP1 (Runtime_scheme : Scheme.Runtime.SCHEME) :
reqd

let create_connection_handler ~config ~request_handler ~error_handler :
Server_intf.connection_handler
Server_intf.connection_handler
=
fun ~sw fd sockaddr ->
let request_handler =
Expand Down
53 changes: 25 additions & 28 deletions lib/http_server_impl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ module Logs =

type upgrade = Gluten.impl -> unit

let report_exn :
type reqd.
(module Http_intf.HTTPServerCommon with type Reqd.t = reqd)
-> reqd
-> exn
-> unit
let report_exn : type reqd.
(module Http_intf.HTTPServerCommon with type Reqd.t = reqd)
-> reqd
-> exn
-> unit
=
fun (module Http) reqd exn ->
Logs.err (fun m ->
Expand All @@ -54,14 +53,13 @@ let report_exn :
raw_backtrace);
Http.Reqd.report_exn reqd exn

let do_sendfile :
type writer.
(module Http_intf.HTTPServerCommon with type Body.Writer.t = writer)
-> src_fd:Unix.file_descr
-> fd:Eio_unix.Net.stream_socket_ty Eio.Net.stream_socket
-> report_exn:(exn -> unit)
-> writer
-> unit
let do_sendfile : type writer.
(module Http_intf.HTTPServerCommon with type Body.Writer.t = writer)
-> src_fd:Unix.file_descr
-> fd:Eio_unix.Net.stream_socket_ty Eio.Net.stream_socket
-> report_exn:(exn -> unit)
-> writer
-> unit
=
fun (module Http) ~src_fd ~fd ~report_exn response_body ->
let fd = Option.get (Eio_unix.Resource.fd_opt fd) in
Expand Down Expand Up @@ -179,20 +177,19 @@ let handle_request :
with
| exn -> report_exn exn)

let handle_error :
type writer reqd.
?request:Request.t
-> (module Http_intf.HTTPServerCommon
with type Reqd.t = reqd
and type Body.Writer.t = writer)
-> start_response:(Headers.t -> writer)
-> error_handler:Server_intf.error_handler
-> scheme:Scheme.t
-> version:Versions.HTTP.t
-> fd:Eio_unix.Net.stream_socket_ty Eio.Net.stream_socket
-> Eio.Net.Sockaddr.stream
-> Error.server
-> unit
let handle_error : type writer reqd.
?request:Request.t
-> (module Http_intf.HTTPServerCommon
with type Reqd.t = reqd
and type Body.Writer.t = writer)
-> start_response:(Headers.t -> writer)
-> error_handler:Server_intf.error_handler
-> scheme:Scheme.t
-> version:Versions.HTTP.t
-> fd:Eio_unix.Net.stream_socket_ty Eio.Net.stream_socket
-> Eio.Net.Sockaddr.stream
-> Error.server
-> unit
=
fun ?request
(module Http)
Expand Down
Loading

0 comments on commit a19576f

Please sign in to comment.