Coder Social home page Coder Social logo

Comments (2)

talex5 avatar talex5 commented on July 20, 2024

I don't see that on my machine. Here's a self-contained test-case that includes a test client:

open Eio.Std
open Cohttp

let addr = `Tcp (Eio.Net.Ipaddr.V4.any, 8080)

let header = "POST / HTTP/1.1\r\n\
Host: 127.0.0.1:8080\r\n\
User-Agent: curl/7.88.1\r\n\
Accept: */*\r\n\
Content-Length: 3\r\n\
Content-Type: application/x-www-form-urlencoded\r\n\
\r\n\
"

let run_client net =
  Switch.run @@ fun sw ->
  let conn = Eio.Net.connect ~sw net addr in
  Eio.Flow.write conn [Cstruct.of_string header];
  traceln "waiting...";
  Eio_unix.sleep 0.8;
  traceln "done";
  Eio.Flow.write conn [Cstruct.of_string "oo"];
  Eio.Flow.shutdown conn `Send;
  traceln "Got: %S" (Eio.Flow.read_all conn)

let () =
  let handler _env _conn _req body =
    let body = Eio.Flow.read_all body in
    Printf.printf "Body read with length: %i\n%!" (String.length body);
    ( Http.Response.make
        ~status:`OK
        ~headers:(Header.of_list [])
        (),
      Eio.Flow.string_source "" )
  in
  Eio_main.run @@ fun env ->
  Eio.Switch.run @@ fun sw ->
  let socket = Eio.Net.listen env#net ~sw ~backlog:128 ~reuse_addr:true addr
  and server = Cohttp_eio.Server.make ~callback:(handler env) () in
  let log_warning ex = Printf.eprintf "%s%!" (Printexc.to_string ex) in
  Fiber.both
    (fun () -> Cohttp_eio.Server.run socket server ~on_error:log_warning)
    (fun () -> run_client env#net)

Running that, I get:

+waiting...                       
+done
Body read with length: 2
+Got: "HTTP/1.1 200 OK\r\ntransfer-encoding: chunked\r\n\r\n0\r\n\r\n"

Does it work for you?

(I'm using cohttp-eio 6.0.0~beta2)

from ocaml-cohttp.

wokalski avatar wokalski commented on July 20, 2024

I don't have a setup to test anymore. I'll close the issue for now, if I ever see it again, I will reopen it and run the repro.

from ocaml-cohttp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.