@@ -219,16 +219,14 @@ let get_substring oc buf =
219219 let b = String. create len in
220220 Lwt_bytes. blit_bytes_string buf 0 b 0 len;
221221 b
222-
223- let make_simple_req () =
222+
223+ let write_req expected req =
224224 let open Cohttp in
225225 let open Cohttp_lwt_unix in
226- let expected = " GET /foo/bar HTTP/1.1\r\n foo: bar\r\n host: localhost\r\n transfer-encoding: chunked\r\n\r\n 6\r\n foobar\r\n 0\r\n\r\n " in
227226 (* Use the low-level write_header/footer API *)
228227 let buf = Lwt_bytes. create 4096 in
229228 let oc = oc_of_buffer buf in
230229 let body = Cohttp_lwt_body. body_of_string " foobar" in
231- let req = Request. make ~encoding: Transfer. Chunked ~headers: (Header. init_with " foo" " bar" ) (Uri. of_string " /foo/bar" ) in
232230 Request. write (fun req oc ->
233231 Cohttp_lwt_body. write_body (Request. write_body req oc) body
234232 ) req oc >> = fun () ->
@@ -237,9 +235,24 @@ let make_simple_req () =
237235 * by re-using it *)
238236 let buf = Lwt_bytes. create 4096 in
239237 let oc = oc_of_buffer buf in
240- Request. write (fun req oc -> Request. write_body req oc " foobar" ) req oc >> = fun () ->
241- assert_equal expected (get_substring oc buf);
242- return ()
238+ Request. write (fun req oc -> Request. write_body req oc " foobar" ) req oc
239+ > |= fun () ->
240+ assert_equal expected (get_substring oc buf)
241+
242+ let make_simple_req () =
243+ let open Cohttp in
244+ let open Cohttp_lwt_unix in
245+ let expected = " GET /foo/bar HTTP/1.1\r\n foo: bar\r\n host: localhost\r\n transfer-encoding: chunked\r\n\r\n 6\r\n foobar\r\n 0\r\n\r\n " in
246+ let req = Request. make ~encoding: Transfer. Chunked ~headers: (Header. init_with " foo" " bar" ) (Uri. of_string " /foo/bar" ) in
247+ write_req expected req
248+
249+ let mutate_simple_req () =
250+ let open Cohttp in
251+ let open Cohttp_lwt_unix in
252+ let expected = " POST /foo/bar HTTP/1.1\r\n foo: bar\r\n host: localhost\r\n transfer-encoding: chunked\r\n\r\n 6\r\n foobar\r\n 0\r\n\r\n " in
253+ let req = Request. make ~encoding: Transfer. Chunked ~headers: (Header. init_with " foo" " bar" ) (Uri. of_string " /foo/bar" ) in
254+ Request. set_meth req `POST ;
255+ write_req expected req
243256
244257let make_simple_res () =
245258 let open Cohttp in
@@ -273,6 +286,7 @@ let test_cases =
273286 " basic_res_parse 2" , (basic_res_parse basic_res_plus_crlf);
274287 " res_content_parse" , res_content_parse;
275288 " make_simple_req" , make_simple_req;
289+ " mutate_simple_req" , mutate_simple_req;
276290 " make_simple_res" , make_simple_res;
277291 ] in
278292 List. map (fun (n ,x ) -> n > :: (fun () -> Lwt_unix. run (x () ))) tests
0 commit comments