From b7372ed82aa36a250b9d75d8acc23ecc88ab9dda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonin=20D=C3=A9cimo?= Date: Tue, 9 Jul 2024 15:39:26 +0200 Subject: [PATCH 1/2] Fix typos --- CHANGES.md | 10 +++++----- README.md | 2 +- cohttp-async/examples/s3_cp.ml | 20 +++++++++---------- cohttp-eio/src/client_intf.ml | 2 +- cohttp-lwt-jsoo/src/cohttp_lwt_jsoo.ml | 2 +- cohttp-lwt-unix/src/server.ml | 2 +- cohttp-lwt-unix/test/test_client.ml | 2 +- cohttp-lwt-unix/test/test_parser.ml | 2 +- cohttp-lwt/src/connection_cache.ml | 2 +- cohttp-lwt/src/s.ml | 2 +- cohttp-mirage.opam | 2 +- cohttp-mirage/src/cohttp_mirage.ml | 2 +- .../src/cohttp_server_lwt_unix.mli | 4 ++-- cohttp/src/code.mli | 2 +- cohttp/src/connection.mli | 2 +- cohttp/src/header.mli | 9 +++++---- dune-project | 2 +- http/fuzz/fuzz_header.ml | 13 ++++++------ http/src/http.ml | 6 +++--- http/src/http.mli | 8 ++++---- test_helpers/cohttp_test/src/cohttp_test.mli | 2 +- 21 files changed, 50 insertions(+), 48 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index dfe98821fd..bf82b9d064 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -19,7 +19,7 @@ ## v6.0.0~beta1 (2023-10-27) - cohttp-eio: move new Cohttp.{Client,Server} modules under Cohttp.Generic (mseri #1003) - cohttp-eio: Add Client.make_generic and HTTPS support. (talex5 #1002) -- cohttp: move generic client and server signatures to cohttp and use them across all packges. (mefyl #984) +- cohttp: move generic client and server signatures to cohttp and use them across all packages. (mefyl #984) - cohttp-eio: Complete rewrite to follow common interfaces and behaviors. (mefyl #984) ## v6.0.0~alpha2 (2023-08-08) @@ -141,7 +141,7 @@ **Breaking** the headers are no-longer lowercased when parsed, the headers key comparison is case insensitive instead. - cohttp-lwt-unix: Adopt ocaml-conduit 5.0.0 (smorimoto #787) - **Breaking** `Conduit_lwt_unix.connect`'s `ctx` param type chaged from `ctx` to `ctx Lazy.t` + **Breaking** `Conduit_lwt_unix.connect`'s `ctx` param type changed from `ctx` to `ctx Lazy.t` - cohttp-mirage: fix deprecated fmt usage (tmcgilchrist #783) - lwt_jsoo: Use logs for the warnings and document it (mseri #776) @@ -161,7 +161,7 @@ - Use implicit executable dependency for generate.exe (TheLortex #735) - cohttp: fix chunked encoding of empty body (mefyl #715) - cohttp-async: fix body not being uploaded with unchunked Async.Pipe (mefyl #706) -- cohttp-{async, lwt}: fix suprising behaviours of Body.is_empty (anuragsoni #714 #712 #713) +- cohttp-{async, lwt}: fix surprising behaviours of Body.is_empty (anuragsoni #714 #712 #713) - refactoring of tests (mseri #709, dinosaure #692) - update documentation (dinosaure #716, mseri #720) - fix deadlock in logging (dinosaure #722) @@ -273,7 +273,7 @@ Async: Expert response action no longer writes empty HTTP body (#647 by andreas) In cohttp.0.99, a number of subpackages were turned into explicit opam packages to simplify dependency management. -To aid migration, some compatability shims were left in place so that +To aid migration, some compatibility shims were left in place so that the old findlib names would continue to work. They have now been removed as of this release. If you were still using them, then please rename them as follows: @@ -380,7 +380,7 @@ and avsm. ## 0.22.0 (2017-03-09) -* Lwt: ensure conn_closed is cosed once client goes away (#528) +* Lwt: ensure conn_closed is closed once client goes away (#528) * Use the Logs library for logging. (#532) ## 0.21.1 (2017-02-18) diff --git a/README.md b/README.md index b9fc604aad..87f16886dc 100644 --- a/README.md +++ b/README.md @@ -435,7 +435,7 @@ Assuming that the server is running in cohttp's source directory: $ cohttp-curl-lwt 'http://0.0.0.0:8080/README.md' ``` -Other examples using the async api are avaliable in the +Other examples using the async api are available in the [cohttp-async/examples](https://github.com/mirage/ocaml-cohttp/tree/master/cohttp-async/examples) folder in the sources. diff --git a/cohttp-async/examples/s3_cp.ml b/cohttp-async/examples/s3_cp.ml index 0a5e5750c8..f74b1eef60 100644 --- a/cohttp-async/examples/s3_cp.ml +++ b/cohttp-async/examples/s3_cp.ml @@ -298,10 +298,10 @@ module S3 = struct } [@@deriving sexp] - let make_request ?body conf ~meth ~bucket ~objekt = + let make_request ?body conf ~meth ~bucket ~object_ = let host_str = region_host_string conf.region in let uri = - Printf.sprintf "https://%s/%s/%s" host_str bucket objekt |> Uri.of_string + Printf.sprintf "https://%s/%s/%s" host_str bucket object_ |> Uri.of_string in let time = Time.now () in (* If PUT add content length *) @@ -334,16 +334,16 @@ module S3 = struct | _ -> failwith "not possible right now" end -type s3path = { bucket : string; objekt : string } +type s3path = { bucket : string; object_ : string } type cmd = S3toLocal of s3path * string | LocaltoS3 of string * s3path let determine_s3_parts s = - (* Takes: string of the form s3:/// *) + (* Takes: string of the form s3:/// *) let s = String.drop_prefix s 5 in let parts = String.split ~on:'/' s in match parts with - | bucket :: rst -> { bucket; objekt = String.concat ~sep:"/" rst } - | _ -> failwith "error format must be 's3:///'" + | bucket :: rst -> { bucket; object_ = String.concat ~sep:"/" rst } + | _ -> failwith "error format must be 's3:///'" let determine_paths src dst = let is_s3 s = String.is_prefix ~prefix:"s3://" s in @@ -360,7 +360,7 @@ let main region_str aws_access_key aws_secret_key src dst () = let conf = { region; aws_access_key; aws_secret_key } in match determine_paths src dst with | S3toLocal (src, dst) -> ( - make_request conf ~meth:`GET ~bucket:src.bucket ~objekt:src.objekt + make_request conf ~meth:`GET ~bucket:src.bucket ~object_:src.object_ >>= fun (resp, body) -> match Http.Response.(resp.status) with | #Http.Status.success -> @@ -368,7 +368,7 @@ let main region_str aws_access_key aws_secret_key src dst () = Out_channel.with_file ~f:(fun oc -> Out_channel.output_string oc s) dst; - Core.Printf.printf "Wrote s3://%s to %s\n" (src.bucket ^ src.objekt) + Core.Printf.printf "Wrote s3://%s to %s\n" (src.bucket ^ src.object_) dst | _ -> Core.Printf.printf "Error: %s\n" @@ -378,12 +378,12 @@ let main region_str aws_access_key aws_secret_key src dst () = let body = In_channel.with_file src ~f:(fun ic -> In_channel.input_all ic) in - make_request ~body conf ~meth:`PUT ~bucket:dst.bucket ~objekt:dst.objekt + make_request ~body conf ~meth:`PUT ~bucket:dst.bucket ~object_:dst.object_ >>= fun (resp, body) -> match Http.Response.status resp with | #Http.Status.success -> Core.Printf.printf "Wrote %s to s3://%s\n" src - (dst.bucket ^ dst.objekt); + (dst.bucket ^ dst.object_); return () | _ -> Body.to_string body >>| fun s -> diff --git a/cohttp-eio/src/client_intf.ml b/cohttp-eio/src/client_intf.ml index 5edd74b299..854ae5856f 100644 --- a/cohttp-eio/src/client_intf.ml +++ b/cohttp-eio/src/client_intf.ml @@ -15,7 +15,7 @@ module type BASE = sig (Http.Response.t * Eio.Flow.source_ty r, string) Result.t Io.t) with_context (** Send an HTTP request with arbitrary method and a body. If the URI has a - host, we use a TCP connection, otherwaise a UNIX domain socket. *) + host, we use a TCP connection, otherwise a UNIX domain socket. *) end module type S = sig diff --git a/cohttp-lwt-jsoo/src/cohttp_lwt_jsoo.ml b/cohttp-lwt-jsoo/src/cohttp_lwt_jsoo.ml index 5a4dd1b0d8..9ebd2200f7 100644 --- a/cohttp-lwt-jsoo/src/cohttp_lwt_jsoo.ml +++ b/cohttp-lwt-jsoo/src/cohttp_lwt_jsoo.ml @@ -250,7 +250,7 @@ module Make_client_async (P : Params) = Make_api (struct with | e (* If we exhaust the stack, it is possible that - Lwt.wakeup just aboves marks the promise as + Lwt.wakeup just above marks the promise as completed, but raises Stack_overflow while running the promise callbacks. In this case waking calling wakeup_exn on the already diff --git a/cohttp-lwt-unix/src/server.ml b/cohttp-lwt-unix/src/server.ml index b3830a99dc..abf24d59cb 100644 --- a/cohttp-lwt-unix/src/server.ml +++ b/cohttp-lwt-unix/src/server.ml @@ -14,7 +14,7 @@ exception Isnt_a_file let respond_file ?headers ~fname () = Lwt.catch (fun () -> - (* Check this isnt a directory first *) + (* Check this isn't a directory first *) ( fname |> Lwt_unix.stat >>= fun s -> if Unix.(s.st_kind <> S_REG) then Lwt.fail Isnt_a_file else Lwt.return_unit ) diff --git a/cohttp-lwt-unix/test/test_client.ml b/cohttp-lwt-unix/test/test_client.ml index 6ce34644a1..c2f0997341 100644 --- a/cohttp-lwt-unix/test/test_client.ml +++ b/cohttp-lwt-unix/test/test_client.ml @@ -178,7 +178,7 @@ let test_unknown uri = in tests handler uri -(* In that difficult case one might be better of using a Connection_cache which +(* In that difficult case one might be better off using a Connection_cache which * will take care of those trivial retries and reconnecting: *) module Cache = Cohttp_lwt_unix.Connection_cache diff --git a/cohttp-lwt-unix/test/test_parser.ml b/cohttp-lwt-unix/test/test_parser.ml index eeda8e67a7..60c09f8404 100644 --- a/cohttp-lwt-unix/test/test_parser.ml +++ b/cohttp-lwt-unix/test/test_parser.ml @@ -353,7 +353,7 @@ let test_cases = List.map (fun (n, x) -> n >:: fun () -> Lwt_main.run (x ())) tests (* Returns true if the result list contains successes only. - Copied from ounit2 source as it isnt exposed by the mli *) + Copied from ounit2 source as it isn't exposed by the mli *) let rec was_successful = function | [] -> true | RSuccess _ :: t | RSkip _ :: t -> was_successful t diff --git a/cohttp-lwt/src/connection_cache.ml b/cohttp-lwt/src/connection_cache.ml index b16e2f4c2b..cb4eae8d5e 100644 --- a/cohttp-lwt/src/connection_cache.ml +++ b/cohttp-lwt/src/connection_cache.ml @@ -38,7 +38,7 @@ end = struct res end -(** This functor keeps a cache of connecions for reuse. Connections are reused +(** This functor keeps a cache of connections for reuse. Connections are reused based on their remote {!type:Conduit.endp} (effectively IP / port). *) module Make (Connection : S.Connection) (Sleep : S.Sleep) : sig include S.Connection_cache diff --git a/cohttp-lwt/src/s.ml b/cohttp-lwt/src/s.ml index e7d85465ad..7386b48620 100644 --- a/cohttp-lwt/src/s.ml +++ b/cohttp-lwt/src/s.ml @@ -132,7 +132,7 @@ module type Connection = sig closed as soon as possible. If [true], it is assumed the remote end does support pipelining and multiple requests may be sent even before receiving any reply. By default we wait for the first response to decide - whether connection keep-alive and pipelining is suppored. Chunked + whether connection keep-alive and pipelining is supported. Chunked encoding can only be used when pipelining is supported. Therefore better avoid using chunked encoding on the very first request. @param ctx See [Net.ctx] diff --git a/cohttp-mirage.opam b/cohttp-mirage.opam index 7532b3a4b6..58059a7608 100644 --- a/cohttp-mirage.opam +++ b/cohttp-mirage.opam @@ -2,7 +2,7 @@ opam-version: "2.0" synopsis: "CoHTTP implementation for the MirageOS unikernel" description: """ -This HTTP implementation uses the Cohttp portable implementaiton +This HTTP implementation uses the Cohttp portable implementation along with the Lwt threading library in order to provide a `Cohttp_mirage` functor that can be used in MirageOS unikernels to build very small and efficient HTTP clients and servers diff --git a/cohttp-mirage/src/cohttp_mirage.ml b/cohttp-mirage/src/cohttp_mirage.ml index b132728388..75871cbb8e 100644 --- a/cohttp-mirage/src/cohttp_mirage.ml +++ b/cohttp-mirage/src/cohttp_mirage.ml @@ -9,7 +9,7 @@ module Net = Net.Make (** client modules *) -(** simple, high-level interace *) +(** simple, high-level interface *) module Client = Client diff --git a/cohttp-server-lwt-unix/src/cohttp_server_lwt_unix.mli b/cohttp-server-lwt-unix/src/cohttp_server_lwt_unix.mli index cafa6a7e80..e72b50f1de 100644 --- a/cohttp-server-lwt-unix/src/cohttp_server_lwt_unix.mli +++ b/cohttp-server-lwt-unix/src/cohttp_server_lwt_unix.mli @@ -60,7 +60,7 @@ module Body : sig (** [stream ?encoding f] respond with body generated by repeatedly applying [f]. When [f] returns [None], it will be considered terminated. - [?encoding] is the encoding to use. By deafult this is [Encoding.chunked]. *) + [?encoding] is the encoding to use. By default this is [Encoding.chunked]. *) end module Context : sig @@ -88,7 +88,7 @@ val create : ?on_exn:(exn -> unit) -> (Context.t -> unit Lwt.t) -> t (** [create ?on_exn f] creates an HTTP server that will handle every incoming request with [f] concurrently. - [on_exn] will be called on exceptions not caught in [f] or raisedd by the + [on_exn] will be called on exceptions not caught in [f] or raised by the server itself. If [on_exn] isn't provided [Lwt.async_exception_hook] will be used. *) diff --git a/cohttp/src/code.mli b/cohttp/src/code.mli index ad2712bd2c..f645561f68 100644 --- a/cohttp/src/code.mli +++ b/cohttp/src/code.mli @@ -35,7 +35,7 @@ type success_status = | `Partial_content (** partial resource return due to request header *) | `Multi_status (** XML, can contain multiple separate responses *) | `Already_reported (** results previously returned *) - | `Im_used (** request fulfilled, reponse is instance-manipulations *) ] + | `Im_used (** request fulfilled, response is instance-manipulations *) ] [@@deriving sexp] (** Success *) diff --git a/cohttp/src/connection.mli b/cohttp/src/connection.mli index 9d703a90fb..eb2ee66c76 100644 --- a/cohttp/src/connection.mli +++ b/cohttp/src/connection.mli @@ -24,7 +24,7 @@ val create : unit -> t (** Create a fresh connection identifier. *) val to_string : t -> string -(** Pretty-print a connection identifer. *) +(** Pretty-print a connection identifier. *) val compare : t -> t -> int (** Comparison function for two identifiers. More recently constructed diff --git a/cohttp/src/header.mli b/cohttp/src/header.mli index ff4f7fc104..7ed211509d 100644 --- a/cohttp/src/header.mli +++ b/cohttp/src/header.mli @@ -85,7 +85,8 @@ val remove : t -> string -> t val replace : t -> string -> string -> t (** [replace h k v] replaces the last added value of [k] from [h] and removed - all other occurences of [k] if it exists. Otherwise it adds [(k, v)] to [h]. + all other occurrences of [k] if it exists. Otherwise it adds [(k, v)] to + [h]. {e Invariant:} [forall h, k, v. get_multi (replace h k v) = [ v ]] *) @@ -124,7 +125,7 @@ val update : t -> string -> (string option -> string option) -> t except for the header name [k]. Depending on the value of [v] where [v] is [f (get h k)], the header pair [(k, v)] is added, removed or updated. - - If [v] is [None], the last occurence of [k] in [h] is removed; + - If [v] is [None], the last occurrence of [k] in [h] is removed; - If [v] is [Some w] then the last value paired with [k] in [h] is replaced by [w] if it exists. Otherwise, the pair [(k, w)] is added; @@ -138,7 +139,7 @@ val update_all : t -> string -> (string list -> string list) -> t [vs] is [f (get_multi h k)], the values associated to the header [k] are added, removed or updated. - - If [vs] is an empty list, every occurences of the header [k] in [h] are + - If [vs] is an empty list, every occurrences of the header [k] in [h] are removed; - If [vs] is a non-empty list, all values previously associated to [k] are @@ -152,7 +153,7 @@ val map : (string -> string -> string) -> t -> t val fold : (string -> string -> 'a -> 'a) -> t -> 'a -> 'a val to_lines : t -> string list -(** [to_lines h] returns header fieds as a list of lines. Beware that each line +(** [to_lines h] returns header fields as a list of lines. Beware that each line ends with "\r\n" characters. *) val to_frames : t -> string list diff --git a/dune-project b/dune-project index cccc68178f..106a0d546d 100644 --- a/dune-project +++ b/dune-project @@ -207,7 +207,7 @@ (name cohttp-mirage) (synopsis "CoHTTP implementation for the MirageOS unikernel") (description - "This HTTP implementation uses the Cohttp portable implementaiton\nalong with the Lwt threading library in order to provide a\n`Cohttp_mirage` functor that can be used in MirageOS unikernels\nto build very small and efficient HTTP clients and servers\nwithout having a hard dependency on an underlying operating\nsystem.\n\nPlease see for a self-hosted explanation\nand instructions on how to use this library.") + "This HTTP implementation uses the Cohttp portable implementation\nalong with the Lwt threading library in order to provide a\n`Cohttp_mirage` functor that can be used in MirageOS unikernels\nto build very small and efficient HTTP clients and servers\nwithout having a hard dependency on an underlying operating\nsystem.\n\nPlease see for a self-hosted explanation\nand instructions on how to use this library.") (depends (ocaml (>= 4.08)) diff --git a/http/fuzz/fuzz_header.ml b/http/fuzz/fuzz_header.ml index 35ff9390f5..e8e503ee1c 100644 --- a/http/fuzz/fuzz_header.ml +++ b/http/fuzz/fuzz_header.ml @@ -24,7 +24,7 @@ module H = Http.Header The tests below reflects the semantics we want for each function, however in some cases, it may actually be specific to the current implementation and does not necessary need to be enforced in future implementations. To make it - clear, tests are annoted by their categories: + clear, tests are annotated by their categories: - FS (Functions semantics): tests the semantics described in the documentation. @@ -403,7 +403,7 @@ let update_test () = check_eq H.(remove (update h k (fun _ -> None)) k) H.(remove h k); check_eq H.(remove (update h k (fun _ -> Some w)) k) H.(remove h k)); (*FS*) - add_test ~name:"[update h k (fun _ -> None)] removes last occurence of k." + add_test ~name:"[update h k (fun _ -> None)] removes last occurrence of k." [ headers_gen; header_name_gen ] (fun h k -> let h1 = H.update h k (fun _ -> None) in let r1 = H.get_multi h1 k in @@ -416,8 +416,8 @@ let update_test () = (*FS*) add_test ~name: - "[update h k (function Some _ -> Some w)] replaces last occurence of k." - [ headers_gen; header_name_gen; word_gen ] (fun h k w -> + "[update h k (function Some _ -> Some w)] replaces last occurrence of \ + k." [ headers_gen; header_name_gen; word_gen ] (fun h k w -> let h1 = H.update h k (fun _ -> Some w) in let r1 = H.get_multi h1 k in let r2 = @@ -441,14 +441,15 @@ let update_all_test () = check_eq H.(remove (update_all h k (fun _ -> [])) k) H.(remove h k); check_eq H.(remove (update_all h k (fun _ -> [ w ])) k) H.(remove h k)); (*FS*) - add_test ~name:"[update_all h k (fun _ -> [])] removes all occurences of k." + add_test + ~name:"[update_all h k (fun _ -> [])] removes all occurrences of k." [ headers_gen; header_name_gen ] (fun h k -> let h1 = H.update_all h k (fun _ -> []) in check_eq H.(get_multi h1 k) []); (*FS*) add_test ~name: - "[update_all h k (function _ -> [w])] removes all occurences of k and \ + "[update_all h k (function _ -> [w])] removes all occurrences of k and \ adds w." [ headers_gen; header_name_gen; word_gen ] (fun h k w -> let h1 = H.update_all h k (fun _ -> [ w ]) in let r1 = H.get_multi h1 k in diff --git a/http/src/http.ml b/http/src/http.ml index 85158de658..27ba28e6eb 100644 --- a/http/src/http.ml +++ b/http/src/http.ml @@ -25,7 +25,7 @@ module Header = struct else let len = String.length a in len = String.length b - (* Note: at this point we konw that [a] and [b] have the same length. *) + (* Note: at this point we know that [a] and [b] have the same length. *) && (* [word_loop a b i len] compares strings [a] and [b] from offsets [i] (included) to [len] (excluded), one word at a time. @@ -312,7 +312,7 @@ module Header = struct (* Parse the transfer-encoding and content-length headers to * determine how to decode a body *) let get_transfer_encoding headers = - (* It should actually be [get] as the interresting value is actually the last.*) + (* It should actually be [get] as the interesting value is actually the last.*) match get_multi_concat ~list_value_only:true headers "transfer-encoding" with @@ -323,7 +323,7 @@ module Header = struct | None -> Transfer.Unknown) let add_transfer_encoding headers (enc : Transfer.encoding) = - (* Only add a header if one doesnt already exist, e.g. from the app *) + (* Only add a header if one doesn't already exist, e.g. from the app *) match (get_transfer_encoding headers, enc) with | Fixed _, _ (* App has supplied a content length, so use that *) | Chunked, _ -> diff --git a/http/src/http.mli b/http/src/http.mli index 13a99954c5..4a63e64fc0 100644 --- a/http/src/http.mli +++ b/http/src/http.mli @@ -51,7 +51,7 @@ module Status : sig | `Partial_content (** partial resource return due to request header *) | `Multi_status (** XML, can contain multiple separate responses *) | `Already_reported (** results previously returned *) - | `Im_used (** request fulfilled, reponse is instance-manipulations *) ] + | `Im_used (** request fulfilled, response is instance-manipulations *) ] (** Success *) type redirection = @@ -245,7 +245,7 @@ module Header : sig val replace : t -> string -> string -> t (** [replace h k v] replaces the last added value of [k] from [h] and removed - all other occurences of [k] if it exists. Otherwise it adds [(k, v)] to + all other occurrences of [k] if it exists. Otherwise it adds [(k, v)] to [h]. {e Invariant:} [forall h, k, v. get_multi (replace h k v) = [ v ]] *) @@ -285,7 +285,7 @@ module Header : sig except for the header name [k]. Depending on the value of [v] where [v] is [f (get h k)], the header pair [(k, v)] is added, removed or updated. - - If [v] is [None], the last occurence of [k] in [h] is removed; + - If [v] is [None], the last occurrence of [k] in [h] is removed; - If [v] is [Some w] then the last value paired with [k] in [h] is replaced by [w] if it exists. Otherwise, the pair [(k, w)] is added; @@ -299,7 +299,7 @@ module Header : sig [vs] is [f (get_multi h k)], the values associated to the header [k] are added, removed or updated. - - If [vs] is an empty list, every occurences of the header [k] in [h] are + - If [vs] is an empty list, every occurrences of the header [k] in [h] are removed; - If [vs] is a non-empty list, all values previously associated to [k] are diff --git a/test_helpers/cohttp_test/src/cohttp_test.mli b/test_helpers/cohttp_test/src/cohttp_test.mli index 66180a178f..79fef83c09 100644 --- a/test_helpers/cohttp_test/src/cohttp_test.mli +++ b/test_helpers/cohttp_test/src/cohttp_test.mli @@ -21,7 +21,7 @@ module type S = sig val response_sequence : spec list -> spec (** A server that process requests using the provided specs in sequence and - crashes on further reqeusts *) + crashes on further requests *) val temp_server : ?port:int -> spec -> (Uri.t -> 'a io) -> 'a io (** Create a temporary server according to spec that lives until the callback From 1de8b778ab1db78acfc7e7da06167688bc59e81d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonin=20D=C3=A9cimo?= Date: Tue, 9 Jul 2024 15:49:11 +0200 Subject: [PATCH 2/2] Some documentation fixes --- cohttp-async/src/server.mli | 2 +- cohttp-lwt/src/s.ml | 4 +- cohttp-lwt/src/string_io.mli | 6 +- .../src/cohttp_server_lwt_unix.mli | 59 ++++++++++--------- cohttp/src/request.mli | 5 +- cohttp/src/response.mli | 9 +-- cohttp/src/server.ml | 2 +- 7 files changed, 45 insertions(+), 42 deletions(-) diff --git a/cohttp-async/src/server.mli b/cohttp-async/src/server.mli index 4a64b821f5..7d601d8317 100644 --- a/cohttp-async/src/server.mli +++ b/cohttp-async/src/server.mli @@ -32,7 +32,7 @@ type response_action = underlying {!Async_unix.Reader.t} and {!Async_unix.Writer.t}, which allows writing a response body more efficiently, stream a response or to switch protocols entirely (e.g. websockets). Processing of pipelined requests - continue after the {!unit Async_kernel.Deferred.t} is resolved. The + continue after the [unit Async_kernel.Deferred.t] is resolved. The connection can be closed by closing the {!Async_unix.Reader.t}. *) val respond : response respond_t diff --git a/cohttp-lwt/src/s.ml b/cohttp-lwt/src/s.ml index 7386b48620..18d8f7cabf 100644 --- a/cohttp-lwt/src/s.ml +++ b/cohttp-lwt/src/s.ml @@ -99,7 +99,7 @@ type call = Logs.set_level (Some Logs.Warning) ]} - @raise {!exception:Connection.Retry} + @raise {!Connection.Retry} on recoverable errors like the remote endpoint closing the connection gracefully. Even non-idempotent requests are guaranteed to not have been processed by the remote endpoint and should be retried. But beware that a @@ -217,7 +217,7 @@ module type Client = sig Uri.t -> (Http.Request.t * Body.t) Lwt_stream.t -> (Http.Response.t * Body.t) Lwt_stream.t Lwt.t - (** @deprecated use {!module Cohttp_lwt.Connection} instead. *) + (** @deprecated use {!module:Cohttp_lwt.Connection} instead. *) end (** The [Server] module implements a pipelined HTTP/1.1 server. *) diff --git a/cohttp-lwt/src/string_io.mli b/cohttp-lwt/src/string_io.mli index 59eac4d57e..b508d95531 100644 --- a/cohttp-lwt/src/string_io.mli +++ b/cohttp-lwt/src/string_io.mli @@ -17,9 +17,9 @@ (** Lwt IO implementation that uses strings to marshal and unmarshal HTTP *) -(** IO interface that uses {!buf} for input data and queues output data into a - {!Buffer.t}. Never actually blocks despite the Lwt use, although a future - revision may yield when parsing large strings. *) +(** IO interface that uses {!Cohttp.Private.String_io.buf} for input data and + queues output data into a {!Buffer.t}. Never actually blocks despite the Lwt + use, although a future revision may yield when parsing large strings. *) include Cohttp.S.IO with type 'a t = 'a Lwt.t diff --git a/cohttp-server-lwt-unix/src/cohttp_server_lwt_unix.mli b/cohttp-server-lwt-unix/src/cohttp_server_lwt_unix.mli index e72b50f1de..b0c76e315b 100644 --- a/cohttp-server-lwt-unix/src/cohttp_server_lwt_unix.mli +++ b/cohttp-server-lwt-unix/src/cohttp_server_lwt_unix.mli @@ -5,35 +5,36 @@ functionality but offers more control and better performance. The differences are as follows: - - Vastly improved performance due to optimized buffer handling - - No dependency on conduit - - No builtin logging - - An example server: {[ - open Lwt.Syntax - - let server_callback ctx = - Lwt.join - [ - Cohttp_server_lwt_unix.ontext.discard_body ctx; - Cohttp_server_lwt_unix.ontext.respond ctx - (Http.Response.make ()) - (Cohttp_server_lwt_unix.Body.string "hello world"); - ] - - let main () = - let* _server = - let listen_address = Unix.(ADDR_INET (inet_addr_loopback, 8080)) in - let server = Cohttp_server_lwt_unix.create server_callback in - Lwt_io.establish_server_with_client_address ~backlog:10_000 listen_address - (fun _addr ch -> Cohttp_server_lwt_unix.handle_connection server ch) - in - let forever, _ = Lwt.wait () in - forever - - let () = ignore (Lwt_main.run (main ())) - ]} - *) + - Vastly improved performance due to optimized buffer handling + - No dependency on conduit + - No builtin logging + + An example server: + + {[ + open Lwt.Syntax + + let server_callback ctx = + Lwt.join + [ + Cohttp_server_lwt_unix.ontext.discard_body ctx; + Cohttp_server_lwt_unix.ontext.respond ctx (Http.Response.make ()) + (Cohttp_server_lwt_unix.Body.string "hello world"); + ] + + let main () = + let* _server = + let listen_address = Unix.(ADDR_INET (inet_addr_loopback, 8080)) in + let server = Cohttp_server_lwt_unix.create server_callback in + Lwt_io.establish_server_with_client_address ~backlog:10_000 + listen_address (fun _addr ch -> + Cohttp_server_lwt_unix.handle_connection server ch) + in + let forever, _ = Lwt.wait () in + forever + + let () = ignore (Lwt_main.run (main ())) + ]} *) module Body : sig module Encoding : sig diff --git a/cohttp/src/request.mli b/cohttp/src/request.mli index 7cb3a2c227..525a594d42 100644 --- a/cohttp/src/request.mli +++ b/cohttp/src/request.mli @@ -18,8 +18,9 @@ include S.Request with type t = Http.Request.t (** This contains the metadata for a HTTP/1.x request header, including the - {!headers}, {!version}, {!meth} and {!uri}. The body is handled by the - separate {!S} module type, as it is dependent on the IO implementation. + {!field-headers}, {!field-version}, {!field-meth} and {!field-uri}. The body + is handled by the separate {!S} module type, as it is dependent on the IO + implementation. The interface exposes a [fieldslib] interface which provides individual accessor functions for each of the records below. It also provides [sexp] diff --git a/cohttp/src/response.mli b/cohttp/src/response.mli index 0adfc484b2..2330522d4e 100644 --- a/cohttp/src/response.mli +++ b/cohttp/src/response.mli @@ -18,10 +18,11 @@ include S.Response with type t = Http.Response.t (** This contains the metadata for a HTTP/1.1 response header, including the - {!encoding}, {!headers}, {!version}, {!status} code and whether to {!flush} - the connection after every body chunk (useful for server-side events and - other long-lived connection protocols). The body is handled by the separate - {!S} module type, as it is dependent on the IO implementation. + {!field-encoding}, {!field-headers}, {!field-version}, {!field-status} code + and whether to flush the connection after every body chunk (useful for + server-side events and other long-lived connection protocols). The body is + handled by the separate {!S} module type, as it is dependent on the IO + implementation. The interface exposes a [fieldslib] interface which provides individual accessor functions for each of the records below. It also provides [sexp] diff --git a/cohttp/src/server.ml b/cohttp/src/server.ml index 5ecc401a28..3228fcba29 100644 --- a/cohttp/src/server.ml +++ b/cohttp/src/server.ml @@ -16,7 +16,7 @@ module type S = sig underlying {!IO.ic} and {!IO.oc}, which allows writing a response body more efficiently, stream a response or to switch protocols entirely (e.g. websockets). Processing of pipelined requests continue after the - {!unit IO.t} is resolved. The connection can be closed by closing the + [unit IO.t] is resolved. The connection can be closed by closing the {!IO.ic}. *) type t