Skip to content

Commit

Permalink
fix: get rid of flush
Browse files Browse the repository at this point in the history
We haven't yet released [Http] so it's ok to change things. It doesn't
seem right to release the library with a deprecated feature.

It's easy enough to just drop this field in [Http]

Signed-off-by: Rudi Grinberg <[email protected]>

<!-- ps-id: adbceded-c111-4ce6-8083-96c5a8a7ca26 -->
  • Loading branch information
rgrinberg committed Jun 27, 2024
1 parent fe388bb commit 300b29f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 48 deletions.
19 changes: 7 additions & 12 deletions cohttp/src/response.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,16 @@ type t = Http.Response.t = {
headers : Header.t;
version : Code.version;
status : Code.status_code;
flush : bool;
}
[@@deriving sexp]

let compare { headers; flush; version; encoding; status } y =
let compare { headers; version; encoding; status } y =
match Header.compare headers y.headers with
| 0 -> (
match Bool.compare flush y.flush with
match Stdlib.compare status y.status with
| 0 -> (
match Stdlib.compare status y.status with
| 0 -> (
match Code.compare_version version y.version with
| 0 -> Stdlib.compare encoding y.encoding
| i -> i)
match Code.compare_version version y.version with
| 0 -> Stdlib.compare encoding y.encoding
| i -> i)
| i -> i)
| i -> i
Expand All @@ -43,16 +39,16 @@ let headers t = t.headers
let encoding t = t.encoding
let version t = t.version
let status t = t.status
let flush t = t.flush

let make ?(version = `HTTP_1_1) ?(status = `OK) ?(flush = false)
?(encoding = Transfer.Chunked) ?(headers = Header.init ()) () =
ignore flush;
let encoding =
match Header.get_transfer_encoding headers with
| Transfer.Unknown -> encoding
| encoding -> encoding
in
{ encoding; headers; version; flush; status }
{ encoding; headers; version; status }

let pp_hum ppf r =
Format.fprintf ppf "%s" (r |> sexp_of_t |> Sexplib0.Sexp.to_string_hum)
Expand Down Expand Up @@ -104,8 +100,7 @@ module Make (IO : S.IO) = struct
| `Ok (version, status) ->
Header_IO.parse ic >>= fun headers ->
let encoding = Header.get_transfer_encoding headers in
let flush = false in
return (`Ok { encoding; headers; version; status; flush })
return (`Ok { encoding; headers; version; status })

let make_body_reader { encoding; _ } ic = Transfer_IO.make_reader encoding ic
let read_body_chunk = Transfer_IO.read
Expand Down
5 changes: 0 additions & 5 deletions cohttp/src/s.ml
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,13 @@ module type Response = sig
headers : Header.t; (** response HTTP headers *)
version : Code.version; (** (** HTTP version, usually 1.1 *) *)
status : Code.status_code; (** HTTP status code of the response *)
flush : bool; [@deprecated "this field will be removed in the future"]
}
[@@deriving sexp]

val encoding : t -> Transfer.encoding
val headers : t -> Header.t
val version : t -> Code.version
val status : t -> Code.status_code

val flush : t -> bool
[@@deprecated "this field will be removed in the future"]

val compare : t -> t -> int

val make :
Expand Down
18 changes: 6 additions & 12 deletions http/src/http.ml
Original file line number Diff line number Diff line change
Expand Up @@ -813,33 +813,27 @@ module Response = struct
headers : Header.t; (** response HTTP headers *)
version : Version.t; (** (** HTTP version, usually 1.1 *) *)
status : Status.t; (** HTTP status code of the response *)
flush : bool;
}

let compare { headers; flush; version; encoding; status } y =
let compare { headers; version; encoding; status } y =
match Header.compare headers y.headers with
| 0 -> (
match Bool.compare flush y.flush with
match Stdlib.compare status y.status with
| 0 -> (
match Stdlib.compare status y.status with
| 0 -> (
match Version.compare version y.version with
| 0 -> Transfer.compare_encoding encoding y.encoding
| i -> i)
match Version.compare version y.version with
| 0 -> Transfer.compare_encoding encoding y.encoding
| i -> i)
| i -> i)
| i -> i

let make ?(version = `HTTP_1_1) ?(status = `OK) ?(flush = false)
?(headers = Header.empty) () =
let make ?(version = `HTTP_1_1) ?(status = `OK) ?(headers = Header.empty) () =
let encoding = Header.get_transfer_encoding headers in
{ encoding; headers; version; flush; status }
{ encoding; headers; version; status }

let headers t = t.headers
let encoding t = t.encoding
let version t = t.version
let status t = t.status
let flush t = t.flush
let is_keep_alive { version; headers; _ } = is_keep_alive version headers

let requires_content_length ?request_meth t =
Expand Down
23 changes: 4 additions & 19 deletions http/src/http.mli
Original file line number Diff line number Diff line change
Expand Up @@ -453,22 +453,12 @@ module Response : sig
headers : Header.t; (** response HTTP headers *)
version : Version.t; (** (** HTTP version, usually 1.1 *) *)
status : Status.t; (** HTTP status code of the response *)
flush : bool;
[@deprecated
"this field will be removed in the future. Provide flush in the \
[respond_*] function instead."]
}

val encoding : t -> Transfer.encoding
val headers : t -> Header.t
val version : t -> Version.t
val status : t -> Status.t

val flush : t -> bool
[@@deprecated
"this field will be removed in the future. Provide flush in the \
[respond_*] function instead."]

val compare : t -> t -> int

val is_keep_alive : t -> bool
Expand All @@ -495,16 +485,11 @@ module Response : sig
See https://www.rfc-editor.org/rfc/rfc7230#section-3.3.2 *)

val make :
?version:Version.t ->
?status:Status.t ->
?flush:bool ->
?headers:Header.t ->
unit ->
t
?version:Version.t -> ?status:Status.t -> ?headers:Header.t -> unit -> t
(** [make ()] is a value of {!type:t}. The default values for the request, if
not specified, are: [status] is [`Ok], [version] is [`HTTP_1_1], [flush]
is [false] and [headers] is [Header.empty]. The request encoding value is
determined via the [Header.get_transfer_encoding] function. *)
not specified, are: [status] is [`Ok], [version] is [`HTTP_1_1]. The
request encoding value is determined via the
[Header.get_transfer_encoding] function. *)

val pp : Format.formatter -> t -> unit
end
Expand Down

0 comments on commit 300b29f

Please sign in to comment.