Skip to content

Commit

Permalink
Merge branch 'master' into anmonteiro/update-flakes
Browse files Browse the repository at this point in the history
  • Loading branch information
anmonteiro authored Mar 1, 2024
2 parents ef95f6c + 3870acb commit bfdf6eb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/piaf.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions lib/request.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions lib/response.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit bfdf6eb

Please sign in to comment.