Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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: 3 additions & 3 deletions lib/header.ml
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,9 @@ let get_location headers =
| Some u -> Some (Uri.of_string u)

let get_links headers =
List.fold_left
(fun list link_s -> (Link.of_string link_s)@list)
[] (get_multi headers "link")
List.rev (List.fold_left
(fun list link_s -> List.rev_append (Link.of_string link_s) list)
[] (get_multi headers "link"))

let add_links headers links =
add_multi headers "link" (List.map Link.to_string links)
Expand Down
6 changes: 4 additions & 2 deletions lib/header_io.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,21 @@

let split_header str =
match Stringext.split ~max:2 ~on:':' str with
| x::y::[] -> [x; Stringext.trim_left y]
| x::y::[] -> [x; String.trim y]
| x -> x

module Make(IO : S.IO) = struct
open IO

module Transfer_IO = Transfer_io.Make(IO)

let rev _k v = List.rev v

let parse ic =
(* consume also trailing "^\r\n$" line *)
let rec parse_headers' headers =
read_line ic >>= function
|Some "" | None -> return headers
|Some "" | None -> return (Header.map rev headers)
|Some line -> begin
match split_header line with
| [hd;tl] ->
Expand Down
21 changes: 21 additions & 0 deletions lib_test/test_header.ml
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,23 @@ let link_ext_star () =
};
]) (H.get_links headers)

let trim_ws () =
let resp = get_resp ["Age: 281 "] in
let headers = headers_of_response "trim whitespace" resp in
assert_equal
~printer:(function
| None -> "None"
| Some x -> "\"" ^ x ^ "\"") (H.get headers "age") (Some "281")

let test_cachecontrol_concat () =
let resp = get_resp ["Cache-Control: public";
"Cache-Control: max-age:86400"] in
let h = headers_of_response "concat Cache-Control" resp in
assert_equal
~printer:(function
| None -> "None"
| Some x -> x) (Some "public,max-age:86400") (H.get h "Cache-Control")

;;
Printexc.record_backtrace true;
Alcotest.run "test_header" [
Expand Down Expand Up @@ -424,7 +441,11 @@ Alcotest.run "test_header" [
"content-length", `Quick, Content_range.content_length;
"content-range", `Quick, Content_range.content_range;
];
"Cache Control", [
"concat", `Quick, test_cachecontrol_concat
];
"Header", [
"get list valued", `Quick, list_valued_header;
"trim whitespace", `Quick, trim_ws;
];
]