Skip to content

Commit 44a4cf1

Browse files
committed
Ocsigen_response: Add Body.of_string
1 parent 2ee5645 commit 44a4cf1

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/server/ocsigen_response.ml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
module Body = struct
22
type t = ((string -> unit Lwt.t) -> unit Lwt.t) * Cohttp.Transfer.encoding
33

4-
let empty : t = (fun _write -> Lwt.return_unit), Fixed 0L
5-
let make encoding writer = writer, encoding
4+
let make encoding writer : t = writer, encoding
5+
let empty = make (Fixed 0L) (fun _write -> Lwt.return_unit)
6+
7+
let of_string s =
8+
make
9+
(Cohttp.Transfer.Fixed (Int64.of_int (String.length s)))
10+
(fun write -> write s)
611

712
let of_cohttp body =
813
( (fun write -> Cohttp_lwt.Body.write_body write body)

src/server/ocsigen_response.mli

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module Body : sig
44
type t
55

66
val empty : t
7+
val of_string : string -> t
78

89
val make :
910
Cohttp.Transfer.encoding
@@ -47,9 +48,11 @@ val of_cohttp :
4748
val to_response_expert :
4849
t
4950
-> Cohttp.Response.t * ('ic -> Lwt_io.output_channel -> unit Lwt.t)
50-
(** Response for [Cohttp_lwt_unix.Server.make_expert]. *)
51+
(** Response for [Cohttp_lwt_unix.Server.make_expert]. Set cookie headers. *)
5152

5253
val response : t -> Cohttp.Response.t
54+
(** Raw response without cookie headers set. *)
55+
5356
val body : t -> Body.t
5457
val status : t -> Cohttp.Code.status
5558
val set_status : t -> Cohttp.Code.status -> t

0 commit comments

Comments
 (0)