@@ -11,7 +11,16 @@ defmodule URI do
11
11
fragment: nil , authority: nil ,
12
12
userinfo: nil , host: nil , port: nil
13
13
14
- @ type t :: % __MODULE__ { }
14
+ @ type t :: % __MODULE__ {
15
+ scheme: nil | binary ,
16
+ path: nil | binary ,
17
+ query: nil | binary ,
18
+ fragment: nil | binary ,
19
+ authority: nil | binary ,
20
+ userinfo: nil | binary ,
21
+ host: nil | binary ,
22
+ port: nil | :inet . port_number ,
23
+ }
15
24
16
25
import Bitwise
17
26
@@ -31,6 +40,7 @@ defmodule URI do
31
40
nil
32
41
33
42
"""
43
+ @ spec default_port ( binary ) :: nil | pos_integer
34
44
def default_port ( scheme ) when is_binary ( scheme ) do
35
45
:elixir_config . get ( { :uri , scheme } )
36
46
end
@@ -47,6 +57,7 @@ defmodule URI do
47
57
application's start callback in case you want to register
48
58
new URIs.
49
59
"""
60
+ @ spec default_port ( binary , pos_integer ) :: :ok
50
61
def default_port ( scheme , port ) when is_binary ( scheme ) and port > 0 do
51
62
:elixir_config . put ( { :uri , scheme } , port )
52
63
end
@@ -76,6 +87,7 @@ defmodule URI do
76
87
** (ArgumentError) encode_query/1 values cannot be lists, got: [:a, :list]
77
88
78
89
"""
90
+ @ spec encode_query ( term ) :: binary
79
91
def encode_query ( l ) , do: Enum . map_join ( l , "&" , & pair / 1 )
80
92
81
93
@ doc """
@@ -97,6 +109,7 @@ defmodule URI do
97
109
%{"percent" => "oh yes!", "starting" => "map"}
98
110
99
111
"""
112
+ @ spec decode_query ( binary , map ) :: map
100
113
def decode_query ( q , map \\ % { } )
101
114
102
115
def decode_query ( q , % { __struct__: _ } = dict ) when is_binary ( q ) do
@@ -139,6 +152,7 @@ defmodule URI do
139
152
[{"foo", "1"}, {"bar", "2"}]
140
153
141
154
"""
155
+ @ spec query_decoder ( binary ) :: Enumerable . t
142
156
def query_decoder ( q ) when is_binary ( q ) do
143
157
Stream . unfold ( q , & do_decode_query / 1 )
144
158
end
@@ -190,6 +204,7 @@ defmodule URI do
190
204
true
191
205
192
206
"""
207
+ @ spec char_reserved? ( term ) :: boolean
193
208
def char_reserved? ( c ) do
194
209
c in ':/?#[]@!$&\' ()*+,;='
195
210
end
@@ -206,6 +221,7 @@ defmodule URI do
206
221
true
207
222
208
223
"""
224
+ @ spec char_unreserved? ( term ) :: boolean
209
225
def char_unreserved? ( c ) do
210
226
c in ?0 .. ?9 or
211
227
c in ?a .. ?z or
@@ -225,6 +241,7 @@ defmodule URI do
225
241
false
226
242
227
243
"""
244
+ @ spec char_unescaped? ( term ) :: boolean
228
245
def char_unescaped? ( c ) do
229
246
char_reserved? ( c ) or char_unreserved? ( c )
230
247
end
@@ -246,6 +263,7 @@ defmodule URI do
246
263
"a str%69ng"
247
264
248
265
"""
266
+ @ spec encode ( binary , ( byte -> boolean ) ) :: binary
249
267
def encode ( str , predicate \\ & char_unescaped? / 1 ) when is_binary ( str ) do
250
268
for << c <- str >> , into: "" , do: percent ( c , predicate )
251
269
end
@@ -259,6 +277,7 @@ defmodule URI do
259
277
"put%3A+it%2B%D0%B9"
260
278
261
279
"""
280
+ @ spec encode_www_form ( binary ) :: binary
262
281
def encode_www_form ( str ) when is_binary ( str ) do
263
282
for << c <- str >> , into: "" do
264
283
case percent ( c , & char_unreserved? / 1 ) do
@@ -288,6 +307,7 @@ defmodule URI do
288
307
"http://elixir-lang.org"
289
308
290
309
"""
310
+ @ spec decode ( binary ) :: binary
291
311
def decode ( uri ) do
292
312
unpercent ( uri , "" , false )
293
313
catch
@@ -304,6 +324,7 @@ defmodule URI do
304
324
"<all in/"
305
325
306
326
"""
327
+ @ spec decode_www_form ( binary ) :: binary
307
328
def decode_www_form ( str ) do
308
329
unpercent ( str , "" , true )
309
330
catch
@@ -366,6 +387,9 @@ defmodule URI do
366
387
port: nil, query: nil, scheme: nil, userinfo: nil}
367
388
368
389
"""
390
+ @ spec parse ( t | binary ) :: t
391
+ def parse ( uri )
392
+
369
393
def parse ( % URI { } = uri ) , do: uri
370
394
371
395
def parse ( s ) when is_binary ( s ) do
@@ -419,6 +443,7 @@ defmodule URI do
419
443
"foo://bar.baz"
420
444
421
445
"""
446
+ @ spec to_string ( t ) :: binary
422
447
defdelegate to_string ( uri ) , to: String.Chars.URI
423
448
424
449
@ doc ~S"""
@@ -436,6 +461,9 @@ defmodule URI do
436
461
"http://google.com"
437
462
438
463
"""
464
+ @ spec merge ( t | binary , t | binary ) :: t
465
+ def merge ( uri , rel )
466
+
439
467
def merge ( % URI { authority: nil } , _rel ) do
440
468
raise ArgumentError , "you must merge onto an absolute URI"
441
469
end
0 commit comments