Skip to content

Commit

Permalink
Merge pull request #169 from thedufer/fix-headers-replace-bug
Browse files Browse the repository at this point in the history
Fix replacing non-trailing headers
  • Loading branch information
seliopou authored Mar 31, 2020
2 parents 1144ec4 + 0345a62 commit d22250e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/headers.ml
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ let replace t name value =
if CI.equal needle name
then (
if seen
then loop t name nv true
else nv::loop t name nv true)
else nv'::loop t name nv seen
then loop t needle nv true
else nv::loop t needle nv true)
else nv'::loop t needle nv seen
in
try loop t name (name,value) false
with Local -> t
Expand Down
9 changes: 8 additions & 1 deletion lib_test/test_httpaf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,13 @@ module Headers = struct
"a"
"d");

check "replace middle element"
~expect:["e", "f"; "c", "z"; "a", "b"]
(Headers.replace
(Headers.of_list ["e", "f"; "c", "d"; "a", "b"])
"c"
"z");

check "remove multiple trailing elements"
~expect:["c", "d"; "a", "d"]
(Headers.replace
Expand Down Expand Up @@ -994,7 +1001,7 @@ module Client_connection = struct
let tests =
[ "GET" , `Quick, test_get
; "Response EOF", `Quick, test_response_eof
; "report_exn" , `Quick, test_report_exn
; "report_exn" , `Quick, test_report_exn
; "input_shrunk", `Quick, test_input_shrunk
]
end
Expand Down

0 comments on commit d22250e

Please sign in to comment.