Skip to content

Commit

Permalink
cohttp-eio: Accept \n without \r as a line terminator.
Browse files Browse the repository at this point in the history
	See https://www.rfc-editor.org/rfc/rfc7230#section-3.5:

	Although the line terminator for the start-line and header fields is
	the sequence CRLF, a recipient MAY recognize a single LF as a line
	terminator and ignore any preceding CR.
  • Loading branch information
mefyl committed Jun 19, 2023
1 parent 86171e8 commit 6b8d17b
Showing 1 changed file with 1 addition and 11 deletions.
12 changes: 1 addition & 11 deletions cohttp-eio/src/io.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,7 @@ module IO = struct
let () = Eio.Buf_read.consume ic consumed in
res

let read_line ic =
let line = Eio.Buf_read.take_while (fun c -> not (Char.equal c '\r')) ic in
match Eio.Buf_read.any_char ic with
| exception End_of_file -> None
| _ ->
let () =
match Eio.Buf_read.peek_char ic with
| Some '\n' -> Eio.Buf_read.consume ic 1
| _ -> ()
in
Some line
let read_line ic = try Some (Eio.Buf_read.line ic) with End_of_file -> None

let read ic len =
match Eio.Buf_read.ensure ic 1 with
Expand Down

0 comments on commit 6b8d17b

Please sign in to comment.