-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathPlug.Conn.Utils.html
271 lines (185 loc) · 7.77 KB
/
Plug.Conn.Utils.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
<!DOCTYPE html>
<html>
<head>
<title>Plug.Conn.Utils</title>
<meta charset="utf-8">
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" charset="utf-8" />
<script type="text/javascript" charset="utf-8">
relpath = '';
if (relpath != '') relpath += '/';
</script>
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
</head>
<body>
<script type="text/javascript" charset="utf-8">
if (window.top.frames.main) document.body.className = 'frames';
</script>
<div id="content">
<div class="breadcrumbs">plug v0.5.1 → <a href="overview.html">Overview</a> → <a href="Plug.html">Plug</a> → <a href="Plug.Conn.html">Conn</a> → <a href="Plug.Conn.Utils.html">Utils</a></div>
<h1>
Plug.Conn.Utils
</h1>
<ul class="summary_links">
<li><a href="#summary">Summary</a></li>
<li><a href="#functions_details">Functions</a></li>
<li><a href="#types_details">Types</a></li>
</ul>
<div id="moduledoc" class="docstring">
<p>Utilities for working with connection data</p>
</div>
<h2 id="summary">Summary<div class="detail_header_links"><a class="to_top_link" href="#content" title="To the top of the page">↑</a></div></h2>
<table class="summary">
<tr>
<td class="summary_signature"><a href="#content_type/1">content_type(binary)</a></td>
<td class="summary_synopsis"><p>Parses the request content type header</p>
</td>
</tr>
<tr>
<td class="summary_signature"><a href="#list/1">list(binary)</a></td>
<td class="summary_synopsis"><p>Parses a comma-separated header list</p>
</td>
</tr>
<tr>
<td class="summary_signature"><a href="#params/1">params(t)</a></td>
<td class="summary_synopsis"><p>Parses headers parameters</p>
</td>
</tr>
<tr>
<td class="summary_signature"><a href="#token/1">token(token)</a></td>
<td class="summary_synopsis"><p>Parses a value as defined in <a href="1">RFC-1341</a>. For convenience, trims whitespace at the end of the token. Returns false is the token is invalid</p>
</td>
</tr>
</table>
<div id="types_details" class="details_list">
<h2>Types <a class="to_top_link" href="#content" title="To the top of the page">↑</a></h2>
<div class="type_detail">
<p class="typespec" id="t:params/0">
<a href="#t:params/0">params</a> :: [{binary, binary}]
</p>
</div>
</div>
<div id="functions_details" class="details_list">
<h2>Functions</h2>
<div class="detail">
<div class="detail_header" id="content_type/1">
<span class="signature"><strong>content_type(binary)</strong></span>
<div class="detail_header_links">
<span class="detail_type">(function)</span>
<a href="#content_type/1" class="detail_link" title="Link to this function">#</a>
<a class="to_top_link" href="#content" title="To the top of the page">↑</a>
</div>
</div>
<p>Specs:</p>
<ul class="spec">
<li>content_type(binary) :: {:ok, type :: binary, subtype :: binary, <a href="#t:params/0">params</a>} | :error</li>
</ul>
<div class="docstring"><p>Parses the request content type header.</p>
<p>Type and subtype are case insensitive while the sensitiveness of params depends on its key and therefore are not handled by this parser.</p>
<h2 id="examples">Examples</h2>
<pre><code>iex> content_type "text/plain"
{:ok, "text", "plain", %{}}
iex> content_type "APPLICATION/vnd.ms-data+XML"
{:ok, "application", "vnd.ms-data+xml", %{}}
iex> content_type "x-sample/json; charset=utf-8"
{:ok, "x-sample", "json", %{"charset" => "utf-8"}}
iex> content_type "x-sample/json ; charset=utf-8 ; foo=bar"
{:ok, "x-sample", "json", %{"charset" => "utf-8", "foo" => "bar"}}
iex> content_type "\r\n text/plain;\r\n charset=utf-8\r\n"
{:ok, "text", "plain", %{"charset" => "utf-8"}}
iex> content_type "x y"
:error
iex> content_type "/"
:error
iex> content_type "x/y z"
:error</code></pre>
</div>
</div>
<div class="detail">
<div class="detail_header" id="list/1">
<span class="signature"><strong>list(binary)</strong></span>
<div class="detail_header_links">
<span class="detail_type">(function)</span>
<a href="#list/1" class="detail_link" title="Link to this function">#</a>
<a class="to_top_link" href="#content" title="To the top of the page">↑</a>
</div>
</div>
<p>Specs:</p>
<ul class="spec">
<li>list(binary) :: [binary]</li>
</ul>
<div class="docstring"><p>Parses a comma-separated header list.</p>
<h2 id="examples">Examples</h2>
<pre><code>iex> list("foo, bar")
["foo", "bar"]
iex> list("foobar")
["foobar"]
iex> list("")
[]
iex> list("empties, , are,, filtered")
["empties", "are", "filtered"]</code></pre>
</div>
</div>
<div class="detail">
<div class="detail_header" id="params/1">
<span class="signature"><strong>params(t)</strong></span>
<div class="detail_header_links">
<span class="detail_type">(function)</span>
<a href="#params/1" class="detail_link" title="Link to this function">#</a>
<a class="to_top_link" href="#content" title="To the top of the page">↑</a>
</div>
</div>
<p>Specs:</p>
<ul class="spec">
<li>params(binary) :: <a href="#t:params/0">params</a></li>
</ul>
<div class="docstring"><p>Parses headers parameters.</p>
<p>Keys are case insensitive and downcased, invalid key-value pairs are discarded.</p>
<h2 id="examples">Examples</h2>
<pre><code>iex> params("foo=bar")
%{"foo" => "bar"}
iex> params(" foo=bar ")
%{"foo" => "bar"}
iex> params("FOO=bar")
%{"foo" => "bar"}
iex> params("foo=BAR ; wat")
%{"foo" => "BAR"}
iex> params("=")
%{}</code></pre>
</div>
</div>
<div class="detail">
<div class="detail_header" id="token/1">
<span class="signature"><strong>token(token)</strong></span>
<div class="detail_header_links">
<span class="detail_type">(function)</span>
<a href="#token/1" class="detail_link" title="Link to this function">#</a>
<a class="to_top_link" href="#content" title="To the top of the page">↑</a>
</div>
</div>
<p>Specs:</p>
<ul class="spec">
<li>token(binary) :: binary | false</li>
</ul>
<div class="docstring"><p>Parses a value as defined in <a href="1">RFC-1341</a>. For convenience, trims whitespace at the end of the token. Returns false is the token is invalid.</p>
<h2 id="examples">Examples</h2>
<pre><code>iex> token("foo")
"foo"
iex> token("foo-bar")
"foo-bar"
iex> token("<foo>")
false
iex> token(~s["<foo>"])
"<foo>"
iex> token(~S["<f\oo>\"<b\ar>"])
"<foo>\"<bar>"
iex> token("foo ")
"foo"
iex> token("foo bar")
false</code></pre>
</div>
</div>
</div>
</div>
</body>
</html>