Skip to content

Commit 218eb41

Browse files
use Lurl for http queries
1 parent 5609677 commit 218eb41

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

devkit.opam

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ depends: [
2727
"base-unix"
2828
"base-threads"
2929
"stdlib-shims"
30-
"uri"
3130
"yojson" {>= "1.6.0"}
3231
"odoc" {with-doc}
3332
"ppx_expect" {with-test}

lurl.ml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
open Printf
55
open ExtLib
6+
open Ocamlnet_lite
7+
68
let ( let* ) = Result.bind
79

810
(* sync urlparse_stubs.c *)
@@ -80,9 +82,11 @@ let string_of_scheme = function
8082
| Http -> "http"
8183
| Https -> "https"
8284

83-
let decode = Web.rawurldecode
85+
(* TODO: this taken from Web, but its quite fishy. It should be investigated. *)
86+
87+
let decode s = try Netencoding.Url.decode ~plus:false s with _ -> s
8488

85-
let decode_plus = Web.urldecode
89+
let decode_plus s = try Netencoding.Url.decode ~plus:true s with _ -> s
8690

8791
module Re = struct
8892

@@ -183,9 +187,8 @@ let rec push_concat ~push ~sep f li =
183187
push sep;
184188
push_concat ~push ~sep f li
185189

186-
let encode_plus = Web.urlencode
187-
188-
let encode = Web.rawurlencode
190+
let encode_plus = Netencoding.Url.encode ~plus:true
191+
let encode = Netencoding.Url.encode ~plus:false
189192

190193
let push_path ~push path =
191194
push "/";

web.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ type ('body,'ret) http_request_ =
129129
?http_1_0:bool ->
130130
?headers:string list ->
131131
?body:'body ->
132-
http_action -> Uri.t -> 'ret
132+
http_action -> Lurl.t -> 'ret
133133

134134
type 'ret http_request = ([ `Form of (string * string) list | `Raw of string * string ], 'ret) http_request_
135135

@@ -154,7 +154,7 @@ module type HTTP = sig
154154
?http_1_0:bool ->
155155
?headers:string list ->
156156
?action:http_action ->
157-
Uri.t ->
157+
Lurl.t ->
158158
(string * string) list -> [> `Error of string | `Ok of string ] IO.t
159159
end
160160

@@ -253,8 +253,8 @@ module Http (IO : IO_TYPE) (Curl_IO : CURL with type 'a t = 'a IO.t) : HTTP with
253253

254254
(* NOTE don't forget to set http_1_0=true when sending requests to a Httpev-based server *)
255255
(* Don't use curl_setheaders when using ?headers option *)
256-
let http_request' ?ua ?timeout ?(verbose=false) ?(setup=ignore) ?timer ?max_size ?(http_1_0=false) ?headers ?body (action:http_action) (url:Uri.t) =
257-
let url = Uri.to_string url in
256+
let http_request' ?ua ?timeout ?(verbose=false) ?(setup=ignore) ?timer ?max_size ?(http_1_0=false) ?headers ?body (action:http_action) (url:Lurl.t) =
257+
let url = Lurl.to_string url in
258258
let open Curl in
259259
let action_name = string_of_http_action action in
260260

@@ -436,7 +436,7 @@ let string_of_http_code = function
436436
| 411 -> "Length Required"
437437
| 412 -> "Precondition Failed"
438438
| 413 -> "Request Entity Too Large"
439-
| 414 -> "Request-URI Too Long"
439+
| 414 -> "Request-Lurl Too Long"
440440
| 415 -> "Unsupported Media Type"
441441
| 416 -> "Requested Range Not Satisfiable"
442442
| 417 -> "Expectation Failed"

0 commit comments

Comments
 (0)