From 0345a622bfb6d9b775038e4a0269045ac331579a Mon Sep 17 00:00:00 2001 From: Aaron Dufour Date: Tue, 31 Mar 2020 12:05:06 +0800 Subject: [PATCH] Fix replacing non-trailing headers --- lib/headers.ml | 6 +++--- lib_test/test_httpaf.ml | 9 ++++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/headers.ml b/lib/headers.ml index 6c5320ca..ff6fce01 100644 --- a/lib/headers.ml +++ b/lib/headers.ml @@ -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 diff --git a/lib_test/test_httpaf.ml b/lib_test/test_httpaf.ml index 223e586c..333565b9 100644 --- a/lib_test/test_httpaf.ml +++ b/lib_test/test_httpaf.ml @@ -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 @@ -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