Skip to content

Commit

Permalink
test_request: use correct user-agent
Browse files Browse the repository at this point in the history
Signed-off-by: Marcello Seri <marcello.seri@gmail.com>
  • Loading branch information
mseri committed Aug 8, 2023
1 parent 48b32e0 commit 975e7e8
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions cohttp/test/test_request.ml
Expand Up @@ -2,6 +2,8 @@ open Cohttp
module String_io = Cohttp.Private.String_io
module StringRequest = Request.Private.Make (String_io.M)

let user_agent = Cohttp.Header.user_agent

let uri_userinfo = Uri.of_string "http://foo:bar%2525@ocaml.org"

let header_auth =
Expand Down Expand Up @@ -310,21 +312,22 @@ let null_content_length_header () =
let () =
(* The user-agent in releases contentsontains the version, we need to strip
it for the test *)
let headers = Cohttp.Header.of_list [ ("user-agent", "ocaml-cohttp") ] in
let r =
Cohttp.Request.make_for_client ~headers ~chunked:false ~body_length:0L
Cohttp.Request.make_for_client ~chunked:false ~body_length:0L
`PUT
(Uri.of_string "http://someuri.com")
in
Request.write_header r output
in
Alcotest.(check string)
"null content-length header are sent"
"PUT / HTTP/1.1\r\n\
user-agent: ocaml-cohttp\r\n\
in
let expected = "PUT / HTTP/1.1\r\n\
host: someuri.com\r\n\
user-agent: " ^ user_agent ^ "\r\n\
content-length: 0\r\n\
\r\n"
in
Alcotest.(check string)
"null content-length header are sent"
expected
(Buffer.to_string output)

let useless_null_content_length_header () =
Expand All @@ -336,9 +339,14 @@ let useless_null_content_length_header () =
in
Request.write_header r output
in
let expected = "GET / HTTP/1.1\r\n\
host: someuri.com\r\n\
user-agent: " ^ user_agent ^ "\r\n\
\r\n"
in
Alcotest.(check string)
"null content-length header are not sent for bodyless methods"
"GET / HTTP/1.1\r\nhost: someuri.com\r\nuser-agent: ocaml-cohttp/\r\n\r\n"
expected
(Buffer.to_string output)

let () =
Expand Down

0 comments on commit 975e7e8

Please sign in to comment.