Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Unreleased

- cohttp: a change in #694 modified the semantics of Header.replace.
The semantics change is reverted, and a new Header.update function
is introduced which changes a header value only when present. (@mseri)

## v2.5.3 (2020-06-27)

- cohttp-async: adapt to async >= v0.14 (#699 @copy)
Expand Down
8 changes: 6 additions & 2 deletions cohttp/src/header.ml
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,12 @@ let remove h k =

let replace h k v =
let k = LString.of_string k in
if StringMap.mem k h
then StringMap.add k [v] h
StringMap.add k [v] h

let update h k v =
let k' = LString.of_string k in
if StringMap.mem k' h
then replace h k v
else h

let get h k =
Expand Down
8 changes: 6 additions & 2 deletions cohttp/src/header.mli
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,14 @@ val add_opt_unless_exists : t option -> string -> string -> t
original header parameter is not modified. *)
val remove : t -> string -> t

(** Replace the value of a key from the header map if it exists. The
original header parameter is not modified. *)
(** Replace the value of a key from the header map if it exists, otherwise it
adds it to the header map. The original header parameter is not modified. *)
val replace : t -> string -> string -> t

(** Replace the value of a key from the header map if it exists, otherwise
return the header map unmodified. The original header parameter is not modified. *)
val update: t -> string -> string -> t

(** Check if a key exists in the header. *)
val mem : t -> string -> bool

Expand Down