Skip to content

Commit

Permalink
cohttp*: remove special treatment of the host header
Browse files Browse the repository at this point in the history
Signed-off-by: Marcello Seri <[email protected]>
  • Loading branch information
mseri committed Jul 6, 2023
1 parent 0d252ec commit 1d8e4be
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 9 deletions.
1 change: 0 additions & 1 deletion cohttp-eio/src/client.ml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ let write_request pipeline_requests request writer body =
body
in
let headers = Http.Header.clean_dup headers in
let headers = Http.Header.Private.move_to_front headers "Host" in
let meth = Http.Method.to_string @@ Http.Request.meth request in
let version = Http.Version.to_string @@ Http.Request.version request in
Buf_write.string writer meth;
Expand Down
6 changes: 3 additions & 3 deletions cohttp-eio/tests/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ GET method request:
|> Client.read_fixed
|> print_string);;
+socket: wrote "GET / HTTP/1.1\r\n"
+ "Host: localhost\r\n"
+ "Accept: application/json\r\n"
+ "Host: localhost\r\n"
+ "User-Agent: cohttp-eio\r\n"
+ "TE: trailers\r\n"
+ "Connection: TE\r\n"
Expand Down Expand Up @@ -82,9 +82,9 @@ POST request:
|> Client.read_fixed
|> print_string);;
+socket: wrote "POST /post HTTP/1.1\r\n"
+ "Host: localhost\r\n"
+ "Accept: application/json\r\n"
+ "Content-Length: 12\r\n"
+ "Host: localhost\r\n"
+ "User-Agent: cohttp-eio\r\n"
+ "TE: trailers\r\n"
+ "Connection: TE\r\n"
Expand Down Expand Up @@ -158,10 +158,10 @@ Chunk request:
|> Client.read_fixed
|> print_string);;
+socket: wrote "POST /handle_chunk HTTP/1.1\r\n"
+ "Host: localhost\r\n"
+ "Transfer-Encoding: chunked\r\n"
+ "Content-Type: text/plain\r\n"
+ "Trailer: Expires, Header1\r\n"
+ "Host: localhost\r\n"
+ "User-Agent: cohttp-eio\r\n"
+ "TE: trailers\r\n"
+ "Connection: TE\r\n"
Expand Down
4 changes: 2 additions & 2 deletions cohttp-lwt-unix/test/test_parser.ml
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ let make_simple_req () =
let open Cohttp in
let open Cohttp_lwt_unix in
let expected =
"POST /foo/bar HTTP/1.1\r\nhost: localhost\r\nFoo: bar\r\nuser-agent: "
"POST /foo/bar HTTP/1.1\r\nFoo: bar\r\nhost: localhost\r\nuser-agent: "
^ user_agent
^ "\r\ntransfer-encoding: chunked\r\n\r\n6\r\nfoobar\r\n0\r\n\r\n"
in
Expand All @@ -285,7 +285,7 @@ let mutate_simple_req () =
let open Cohttp in
let open Cohttp_lwt_unix in
let expected =
"POST /foo/bar HTTP/1.1\r\nhost: localhost\r\nfoo: bar\r\nuser-agent: "
"POST /foo/bar HTTP/1.1\r\nfoo: bar\r\nhost: localhost\r\nuser-agent: "
^ user_agent
^ "\r\ntransfer-encoding: chunked\r\n\r\n6\r\nfoobar\r\n0\r\n\r\n"
in
Expand Down
2 changes: 0 additions & 2 deletions cohttp/src/request.ml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ let make ?(meth = `GET) ?(version = `HTTP_1_1) ?(encoding = Transfer.Unknown)
^
match Uri.port uri with Some p -> ":" ^ string_of_int p | None -> ""))
in
let headers = Header.Private.move_to_front headers "host" in
let headers =
Header.add_unless_exists headers "user-agent" Header.user_agent
in
Expand Down Expand Up @@ -204,7 +203,6 @@ module Make (IO : S.IO) = struct
Header.add_transfer_encoding headers req.encoding
else headers
in
let headers = Header.Private.move_to_front headers "host" in
IO.write oc fst_line >>= fun _ -> Header_IO.write headers oc

let make_body_writer ?flush req oc =
Expand Down
2 changes: 1 addition & 1 deletion cohttp/test/test_request.ml
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ let null_content_length_header () =
Alcotest.(check string)
"null content-length header are sent"
"PUT / HTTP/1.1\r\n\
host: someuri.com\r\n\
user-agent: ocaml-cohttp\r\n\
host: someuri.com\r\n\
content-length: 0\r\n\
\r\n"
(Buffer.to_string output)
Expand Down

0 comments on commit 1d8e4be

Please sign in to comment.