@@ -34,12 +34,21 @@ module Make(S : Interface) : S = struct
3434 any_get := S. get;
3535 any_post := S. post
3636
37+ let add_user_agent ?headers () =
38+ match ! Req. user_agent_header, headers with
39+ | None , _ -> headers
40+ | Some h , None -> Some [ h ]
41+ | Some h , Some l ->
42+ if List. exists (fun (k , _ ) -> String. lowercase_ascii k = " user-agent" ) l then Some l
43+ else Some (h :: l)
44+
3745 (* print warnings generated when building the URL before
3846 sending the request *)
3947 let internal_get ?meth ?headers ?msg (URL url ) =
4048 EzAPI. warnings (fun s -> Printf. kprintf EzDebug. log " EzRequest.warning: %s" s);
4149 let meth = match meth with None -> None | Some m -> Some (
4250 String. uppercase_ascii @@ Meth. to_string m) in
51+ let headers = add_user_agent ?headers () in
4352 S. get ?meth ?headers ?msg url > |= fun code ->
4453 ! request_reply_hook () ;
4554 code
@@ -48,6 +57,7 @@ module Make(S : Interface) : S = struct
4857 EzAPI. warnings (fun s -> Printf. kprintf EzDebug. log " EzRequest.warning: %s" s);
4958 let meth = match meth with None -> None | Some m -> Some (
5059 String. uppercase_ascii @@ Meth. to_string m) in
60+ let headers = add_user_agent ?headers () in
5161 S. post ?meth ?content_type ?content ?headers ?msg url > |= fun code ->
5262 ! request_reply_hook () ;
5363 code
@@ -113,12 +123,6 @@ module Make(S : Interface) : S = struct
113123 let meth = Service. meth service.s in
114124 let input_encoding = Service. input service.s in
115125 let url = forge api service arg params in
116- let headers = match ! Req. user_agent_header, headers with
117- | None , _ -> headers
118- | Some h , None -> Some [ h ]
119- | Some h , Some l ->
120- if List. exists (fun (k , _ ) -> String. lowercase_ascii k = " user-agent" ) l then Some l
121- else Some (h :: l) in
122126 begin match input_encoding with
123127 | Empty ->
124128 if post then
0 commit comments