-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test_request: use correct user-agent
Signed-off-by: Marcello Seri <[email protected]>
- Loading branch information
Showing
1 changed file
with
16 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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%[email protected]" | ||
|
||
let header_auth = | ||
|
@@ -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 () = | ||
|
@@ -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 () = | ||
|