Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Library: remove some obsolete code
  • Loading branch information
vouillon committed Sep 30, 2014
1 parent ca9ad2b commit fb1e5b1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 66 deletions.
39 changes: 1 addition & 38 deletions lib/file.ml
Expand Up @@ -140,44 +140,7 @@ let read_with_filereader (fileReader : fileReader t constr) kind file =
| `DataURL -> reader##readAsDataURL(file));
res

(* Old firefox specific part: available in firefox 3.0, deprecated in 3.6.
Those are nonstandard extensions. *)
class type old_firefox_file =
object
method getAsBinary : js_string t meth
method getAsBinary_presence : unit optdef readonly_prop
method getAsDataURL : js_string t meth
method getAsDataURL_presence : unit optdef readonly_prop
method getAsText_presence : unit optdef readonly_prop
method getAsText : js_string t -> js_string t meth
end

let old_firefox_reader kind file =
let file = (Js.Unsafe.coerce file:old_firefox_file t) in
let fail () = failwith "browser can't read file: unimplemented" in
match kind with
| `BinaryString ->
if Js.Optdef.test ( file##getAsBinary_presence )
then file##getAsBinary()
else fail ()
| `Text ->
if Js.Optdef.test ( file##getAsText_presence )
then file##getAsText(Js.string "utf8")
else fail ()
| `Text_withEncoding e ->
if Js.Optdef.test ( file##getAsText_presence )
then file##getAsText(e)
else fail ()
| `DataURL ->
if Js.Optdef.test ( file##getAsDataURL_presence )
then file##getAsDataURL()
else fail ()
(* end of old firefox specific part *)

let reader kind file =
match Js.Optdef.to_option (Js.def fileReader) with
| None -> Lwt.return (old_firefox_reader kind file)
| Some fileReader -> read_with_filereader fileReader kind file
let reader kind file = read_with_filereader fileReader kind file

let readAsBinaryString file =
reader `BinaryString file
Expand Down
35 changes: 7 additions & 28 deletions lib/xmlHttpRequest.ml
Expand Up @@ -124,10 +124,6 @@ let encode_url l =
| name,`File s -> ((Url.urlencode name) ^ "=" ^ (Url.urlencode (to_string (s##name))))
) l)

let partition_string_file l = List.partition (function
| _,`String _ -> true
| _,`File _ -> false ) l

(* Higher level interface: *)

(** type of the http headers *)
Expand Down Expand Up @@ -186,20 +182,15 @@ let perform_raw_url
Some form_arg
in

let method_, content_type, post_encode =
let method_, content_type =
match form_arg, content_type with
| None, ct -> "GET", ct, `Urlencode
| None, ct -> "GET", ct
| Some form_args, None ->
(match form_args with
| `Fields l ->
let strings,files = partition_string_file !l in
(match files with
| [] -> "POST", (Some "application/x-www-form-urlencoded"), `Urlencode
| _ ->
let boundary = generateBoundary () in
"POST", (Some ("multipart/form-data; boundary="^boundary)), `Form_data (boundary))
| `FormData f -> "POST", None, `Urlencode)
| Some _, ct -> "POST", ct, `Urlencode
| `Fields strings ->
"POST", Some "application/x-www-form-urlencoded"
| `FormData f -> "POST", None)
| Some _, ct -> "POST", ct
in
let url, url_get = extract_get_param url in
let url = match url_get@get_args with
Expand Down Expand Up @@ -286,19 +277,7 @@ let perform_raw_url
(match form_arg with
| None -> req##send (Js.null)
| Some (`Fields l) ->
ignore (
match post_encode with
| `Urlencode -> req##send(Js.some (string (encode_url !l)));return ()
| `Form_data boundary ->
(encode_multipart boundary !l >|=
(fun data ->
let data = Js.some (data##join(Js.string "")) in
(* Firefox specific interface:
Chrome can use FormData: don't need this *)
let req = (Js.Unsafe.coerce req:xmlHttpRequest_binary t) in
if Optdef.test req##sendAsBinary_presence
then req##sendAsBinary(data)
else req##send(data))))
ignore (req##send(Js.some (string (encode_url !l)));return ())
| Some (`FormData f) -> req##send_formData(f));

Lwt.on_cancel res (fun () -> req##abort ()) ;
Expand Down

0 comments on commit fb1e5b1

Please sign in to comment.