Skip to content

Commit

Permalink
refactor: remove some copy-paste (#1069)
Browse files Browse the repository at this point in the history
Signed-off-by: Rudi Grinberg <[email protected]>
  • Loading branch information
rgrinberg committed Jun 30, 2024
1 parent b988f24 commit e650bcc
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 31 deletions.
29 changes: 0 additions & 29 deletions cohttp/src/header.ml
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,6 @@ let get_acceptable_languages headers =
Accept.languages
(get_multi_concat ~list_value_only:true headers "accept-language")

(* Parse the transfer-encoding and content-length headers to
* determine how to decode a body *)
let get_transfer_encoding headers =
(* It should actually be [get] as the interresting value is actually the last.*)
match get_multi_concat ~list_value_only:true headers "transfer-encoding" with
| Some "chunked" -> Transfer.Chunked
| Some _ | None -> (
match get_content_range headers with
| Some len -> Transfer.Fixed len
| None -> Transfer.Unknown)

let add_transfer_encoding headers enc =
let open Transfer in
(* Only add a header if one doesnt already exist, e.g. from the app *)
match (get_transfer_encoding headers, enc) with
| Fixed _, _ (* App has supplied a content length, so use that *) | Chunked, _
->
headers (* TODO: this is a protocol violation *)
| Unknown, Chunked -> add headers "transfer-encoding" "chunked"
| Unknown, Fixed len -> add headers "content-length" (Int64.to_string len)
| Unknown, Unknown -> headers

let add_authorization_req headers challenge =
add headers "www-authenticate" (Auth.string_of_challenge challenge)

Expand Down Expand Up @@ -108,13 +86,6 @@ let prepend_user_agent headers user_agent =
| Some ua -> replace headers k (user_agent ^ " " ^ ua)
| None -> add headers k user_agent

let connection h =
match get h "connection" with
| Some v when v = "keep-alive" -> Some `Keep_alive
| Some v when v = "close" -> Some `Close
| Some x -> Some (`Unknown x)
| _ -> None

open Sexplib0.Sexp_conv

let sexp_of_t t =
Expand Down
3 changes: 1 addition & 2 deletions http/src/http.ml
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,7 @@ module Header = struct
| Some len -> Transfer.Fixed len
| None -> Transfer.Unknown)

let add_transfer_encoding headers enc =
let open Transfer in
let add_transfer_encoding headers (enc : Transfer.encoding) =
(* Only add a header if one doesnt already exist, e.g. from the app *)
match (get_transfer_encoding headers, enc) with
| Fixed _, _ (* App has supplied a content length, so use that *)
Expand Down

0 comments on commit e650bcc

Please sign in to comment.