Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cohttp-eio: fails to consume body on error #913

Closed
talex5 opened this issue Jul 7, 2022 · 1 comment · Fixed by #929
Closed

cohttp-eio: fails to consume body on error #913

talex5 opened this issue Jul 7, 2022 · 1 comment · Fixed by #929

Comments

@talex5
Copy link
Contributor

talex5 commented Jul 7, 2022

cohttp-eio does not ensure that the body has been fully consumed before trying to parse the next request.

Example test case with the current output (add to the server.md file in #887 to run it):

# run @@ fun () ->
  Eio_mock.Flow.on_read socket [
    `Return "POST /no-such-resource HTTP/1.1\r\n\
             Content-Length: 4\r\n\
             \r\n\
             Hi\r\n";
    `Return "GET / HTTP/1.1\r\n\r\n";
  ];;
+socket: read "POST /no-such-resource HTTP/1.1\r\n"
+             "Content-Length: 4\r\n"
+             "\r\n"
+             "Hi\r\n"
+socket: wrote "HTTP/1.1 404 Not Found\r\n"
+              "\r\n"
+              "HTTP/1.1 400 Bad Request\r\n"
+              "\r\n"
Exception: Failure "Expected ' ' but got '\\r'".

I would expect something like this:

# run @@ fun () ->
  Eio_mock.Flow.on_read socket [
    `Return "POST /no-such-resource HTTP/1.1\r\n\
             Content-Length: 4\r\n\
             \r\n\
             Hi\r\n";
    `Return "GET / HTTP/1.1\r\n\r\n";
  ];;
+socket: read "POST /no-such-resource HTTP/1.1\r\n"
+             "Content-Length: 4\r\n"
+             "\r\n"
+             "Hi\r\n"
+socket: wrote "HTTP/1.1 404 Not Found\r\n"
+              "content-length: 0\r\n"
+              "\r\n"
+socket: read "GET / HTTP/1.1\r\n"
+             "\r\n"
+socket: wrote "HTTP/1.1 200 OK\r\n"
+              "content-length: 4\r\n"
+              "content-type: text/plain; charset=UTF-8\r\n"
+              "\r\n"
+              "root"
- : unit = ()

(this also demonstrates the missing content-length header, as reported in #883)

/cc @bikallem

@bikallem
Copy link
Contributor

Thanks for this bug report. Agreed. Error responses should have content-length specified.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants