Skip to content

Commit

Permalink
lwt: make safe-string compliant
Browse files Browse the repository at this point in the history
Signed-off-by: Marcello Seri <marcello.seri@citrix.com>
  • Loading branch information
Marcello Seri committed May 24, 2018
1 parent 01cff30 commit fccc88b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions lwt/cohttp_unbuffered_io.ml
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ let read_http_headers c =
let buf = Buffer.create 128 in
(* We can safely read everything up to this marker: *)
let end_of_headers = "\r\n\r\n" in
let tmp = String.make (String.length end_of_headers) '\000' in
let tmp = Bytes.make (String.length end_of_headers) '\000' in
let module Scanner = struct
type t = {
marker: string;
mutable i: int;
}
let make x = { marker = x; i = 0 }
let input x c =
if c = x.marker.[x.i] then x.i <- x.i + 1 else x.i <- 0
if c = String.get x.marker (x.i) then x.i <- x.i + 1 else x.i <- 0
let remaining x = String.length x.marker - x.i
let matched x = x.i = String.length x.marker
(* let to_string x = Printf.sprintf "%d" x.i *)
Expand All @@ -75,15 +75,15 @@ let read_http_headers c =
really_read_into c tmp 0 safe_to_read >>= fun () ->

for j = 0 to safe_to_read - 1 do
Scanner.input marker tmp.[j];
Buffer.add_char buf tmp.[j]
Scanner.input marker (Bytes.get tmp j);
Buffer.add_char buf (Bytes.get tmp j)
done;
loop ()
end else return () in
loop () >>= fun () ->
return (Buffer.contents buf)

let crlf = Re_str.regexp_string "\r\n"
let crlf = Re.Str.regexp_string "\r\n"

(* We assume read_line is only used to read the HTTP header *)
let rec read_line ic = match ic.header_buffer, ic.header_buffer_idx with
Expand All @@ -94,7 +94,7 @@ let rec read_line ic = match ic.header_buffer, ic.header_buffer_idx with
| Some buf, i when i < (String.length buf) ->
begin
try
let eol = Re_str.search_forward crlf buf i in
let eol = Re.Str.search_forward crlf buf i in
let line = String.sub buf i (eol - i) in
ic.header_buffer_idx <- eol + 2;
return (Some line)
Expand All @@ -114,9 +114,9 @@ let read_exactly ic len =
| false -> return None

let read ic n =
let buf = String.make n '\000' in
let buf = Bytes.make n '\000' in
really_read_into ic.c buf 0 n >>= fun () ->
return buf
return (Bytes.unsafe_to_string buf)

let write oc x =
let buf = Cstruct.create (String.length x) in
Expand Down
2 changes: 1 addition & 1 deletion lwt/disk.ml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ let start_upload ~chunked ~uri =
let headers = match Uri.userinfo uri with
| None -> headers
| Some x ->
begin match Re_str.bounded_split_delim (Re_str.regexp_string ":") x 2 with
begin match Re.Str.bounded_split_delim (Re.Str.regexp_string ":") x 2 with
| [ user; pass ] ->
let b = Cohttp.Auth.string_of_credential (`Basic (user, pass)) in
Header.add headers "authorization" b
Expand Down

0 comments on commit fccc88b

Please sign in to comment.