diff --git a/lib/piaf.mli b/lib/piaf.mli index 07b7a59..f6ee340 100644 --- a/lib/piaf.mli +++ b/lib/piaf.mli @@ -473,6 +473,16 @@ module Request : sig -> string -> t + val with_ : + ?meth:Method.t + -> ?target:string + -> ?version:Versions.HTTP.t + -> ?headers:Headers.t + -> ?scheme:Scheme.t + -> ?body:Body.t + -> t + -> t + val uri : t -> Uri.t val persistent_connection : t -> bool val pp_hum : Format.formatter -> t -> unit [@@ocaml.toplevel_printer] @@ -493,6 +503,14 @@ module Response : sig -> Status.t -> t + val with_ : + ?status:Status.t + -> ?headers:Headers.t + -> ?version:Versions.HTTP.t + -> ?body:Body.t + -> t + -> t + val of_string : ?version:Versions.HTTP.t -> ?headers:Headers.t diff --git a/lib/request.ml b/lib/request.ml index 7692fbb..29a938a 100644 --- a/lib/request.ml +++ b/lib/request.ml @@ -49,6 +49,15 @@ let uri { scheme; target; headers; version; _ } = let create ~scheme ~version ?(headers = Headers.empty) ~meth ~body target = { meth; target; version; headers; scheme; body } +let with_ ?meth ?target ?version ?headers ?scheme ?body request = + { meth = Option.value meth ~default:request.meth + ; target = Option.value target ~default:request.target + ; version = Option.value version ~default:request.version + ; headers = Option.value headers ~default:request.headers + ; scheme = Option.value scheme ~default:request.scheme + ; body = Option.value body ~default:request.body + } + let of_http1 ?(body = Body.empty) ~scheme request = let { Httpaf.Request.meth; target; version; headers } = request in { meth diff --git a/lib/response.ml b/lib/response.ml index 3146d5b..2e07270 100644 --- a/lib/response.ml +++ b/lib/response.ml @@ -48,6 +48,13 @@ let create = { status; headers; version; body } +let with_ ?status ?headers ?version ?body response = + { status = Option.value status ~default:response.status + ; version = Option.value version ~default:response.version + ; headers = Option.value headers ~default:response.headers + ; body = Option.value body ~default:response.body + } + let of_string ?version ?headers ~body status = create ?version ?headers ~body:(Body.of_string body) status