Skip to content

Commit 6252455

Browse files
committed
mising user agent header in raw request
1 parent d49809c commit 6252455

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

src/request/ezRequest.ml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,22 @@ module Make(S : Interface) : S = struct
4343
any_get := S.get;
4444
any_post := S.post
4545

46+
let add_user_agent ?headers () =
47+
match !Req.user_agent_header, headers with
48+
| None, _ -> headers
49+
| Some h, None -> Some [ h ]
50+
| Some h, Some l ->
51+
if List.exists (fun (k, _) -> String.lowercase_ascii k = "user-agent") l then Some l
52+
else Some (h :: l)
53+
54+
4655
(* print warnings generated when building the URL before
4756
sending the request *)
4857
let internal_get ?meth ?headers ?msg ?error (URL url) f =
4958
EzAPI.warnings (fun s -> Printf.kprintf EzDebug.log "EzRequest.warning: %s" s);
5059
let meth = match meth with None -> None | Some m ->
5160
Some (String.uppercase_ascii @@ Meth.to_string m) in
61+
let headers = add_user_agent ?headers () in
5262
S.get ?meth ?msg url ?headers
5363
(fun code ->
5464
!request_reply_hook ();
@@ -63,6 +73,7 @@ module Make(S : Interface) : S = struct
6373
EzAPI.warnings (fun s -> Printf.kprintf EzDebug.log "EzRequest.warning: %s" s);
6474
let meth = match meth with None -> None | Some m -> Some (
6575
String.uppercase_ascii @@ Meth.to_string m) in
76+
let headers = add_user_agent ?headers () in
6677
S.post ?meth ?content_type ?content ?headers ?msg url
6778
(fun code ->
6879
!request_reply_hook ();

src/request/ezRequest_lwt.ml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)