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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
|
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="Loïc Hoguin based on a design from (Soft10) Pol Cámara">
<title>Nine Nines: cowboy_rest(3)</title>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:400,700,400italic' rel='stylesheet' type='text/css'>
<link href="/css/99s.css?r=1" rel="stylesheet">
<link rel="shortcut icon" href="/img/ico/favicon.ico">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="/img/ico/apple-touch-icon-114.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="/img/ico/apple-touch-icon-72.png">
<link rel="apple-touch-icon-precomposed" href="/img/ico/apple-touch-icon-57.png">
</head>
<body class="">
<header id="page-head">
<div id="topbar" class="container">
<div class="row">
<div class="span2">
<h1 id="logo"><a href="/" title="99s">99s</a></h1>
</div>
<div class="span10">
<div id="side-header">
<nav>
<ul>
<li><a title="Hear my thoughts" href="/articles">Articles</a></li>
<li><a title="Watch my talks" href="/talks">Talks</a></li>
<li class="active"><a title="Read the docs" href="/docs">Documentation</a></li>
<li><a title="Request my services" href="/services">Consulting & Training</a></li>
</ul>
</nav>
<ul id="social">
<li>
<a href="https://github.com/ninenines" title="Check my Github repositories"><img src="/img/ico_github.png" data-hover="/img/ico_github_alt.png" alt="Github"></a>
</li>
<li>
<a title="Contact me" href="mailto:[email protected]"><img src="/img/ico_mail.png" data-hover="/img/ico_mail_alt.png"></a>
</li>
</ul>
</div>
</div>
</div>
</div>
</header>
<div id="contents" class="two_col">
<div class="container">
<div class="row">
<div id="docs" class="span9 maincol">
<h1 class="lined-header"><span>cowboy_rest(3)</span></h1>
<div class="sect1">
<h2 id="_name">Name</h2>
<div class="sectionbody">
<div class="paragraph"><p>cowboy_rest - REST handlers</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_description">Description</h2>
<div class="sectionbody">
<div class="paragraph"><p>The module <code>cowboy_rest</code> implements the HTTP state machine.</p></div>
<div class="paragraph"><p>Implementing REST handlers is not enough to provide a REST
interface; this interface must also follow the REST
constraints including HATEOAS (hypermedia as the engine
of application state).</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_callbacks">Callbacks</h2>
<div class="sectionbody">
<div class="paragraph"><p>REST handlers implement the following interface:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000000">init</span></span>(<span style="color: #009900">Req</span>, <span style="color: #009900">State</span>)
<span style="color: #990000">-></span> {<span style="color: #FF6600">cowboy_rest</span>, <span style="color: #009900">Req</span>, <span style="color: #009900">State</span>}
<span style="color: #009900">Callback</span>(<span style="color: #009900">Req</span>, <span style="color: #009900">State</span>)
<span style="color: #990000">-></span> {<span style="color: #009900">Result</span>, <span style="color: #009900">Req</span>, <span style="color: #009900">State</span>}
| {<span style="color: #FF6600">stop</span>, <span style="color: #009900">Req</span>, <span style="color: #009900">State</span>}
<span style="font-weight: bold"><span style="color: #000000">terminate</span></span>(<span style="color: #009900">Reason</span>, <span style="color: #009900">Req</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-></span> <span style="color: #FF6600">ok</span> <span style="font-style: italic"><span style="color: #9A1900">%% optional</span></span>
<span style="color: #009900">Req</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">cowboy_req:req</span></span>()
<span style="color: #009900">State</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">any</span></span>()
<span style="color: #009900">Reason</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000080">normal</span></span>
| {<span style="color: #FF6600">crash</span>, <span style="color: #FF6600">error</span> | <span style="font-weight: bold"><span style="color: #000080">exit</span></span> | <span style="font-weight: bold"><span style="color: #000080">throw</span></span>, <span style="font-weight: bold"><span style="color: #000000">any</span></span>()}
<span style="color: #009900">Callback</span> <span style="color: #990000">-</span> <span style="color: #FF6600">see</span> <span style="color: #FF6600">below</span>
<span style="color: #009900">Result</span> <span style="color: #990000">-</span> <span style="color: #FF6600">see</span> <span style="color: #FF6600">below</span>
<span style="color: #009900">Default</span> <span style="color: #990000">-</span> <span style="color: #FF6600">see</span> <span style="color: #FF6600">below</span></tt></pre></div></div>
<div class="paragraph"><p>The <code>init/2</code> callback is common to all handlers. To switch
to the REST handler behavior, it must return <code>cowboy_rest</code>
as the first element of the tuple.</p></div>
<div class="paragraph"><p>The <code>Callback/2</code> above represents all the REST-specific
callbacks. They are described in the following section
of this manual. REST-specific callbacks differ by their
name, semantics, result and default values. The default
value is the one used when the callback has not been
implemented. They otherwise all follow the same interface.</p></div>
<div class="paragraph"><p>The <code>stop</code> tuple can be returned to stop REST processing.
If no response was sent before then, Cowboy will send a
<em>204 No Content</em>.</p></div>
<div class="paragraph"><p>The optional <code>terminate/3</code> callback will ultimately be called
with the reason for the termination of the handler.
Cowboy will terminate the process right after this. There
is no need to perform any cleanup in this callback.</p></div>
<div class="paragraph"><p>The following terminate reasons are defined for loop handlers:</p></div>
<div class="dlist"><dl>
<dt class="hdlist1">
normal
</dt>
<dd>
<p>
The handler terminated normally.
</p>
</dd>
<dt class="hdlist1">
{crash, Class, Reason}
</dt>
<dd>
<p>
A crash occurred in the handler. <code>Class</code> and <code>Reason</code> can be
used to obtain more information about the crash. The function
<code>erlang:get_stacktrace/0</code> can also be called to obtain the
stacktrace of the process when the crash occurred.
</p>
</dd>
</dl></div>
</div>
</div>
<div class="sect1">
<h2 id="_rest_callbacks">REST callbacks</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_acceptcallback">AcceptCallback</h3>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="color: #009900">AcceptCallback</span>(<span style="color: #009900">Req</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-></span> {<span style="color: #009900">Result</span>, <span style="color: #009900">Req</span>, <span style="color: #009900">State</span>}
<span style="color: #009900">Result</span> <span style="color: #990000">::</span> <span style="color: #000080">true</span> | {<span style="color: #000080">true</span>, <span style="color: #009900">URI</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">iodata</span></span>()} | <span style="color: #000080">false</span>}
<span style="color: #009900">Default</span> <span style="color: #990000">-</span> <span style="color: #FF6600">crash</span></tt></pre></div></div>
<div class="paragraph"><p>Process the request body.</p></div>
<div class="paragraph"><p>This function should create or update the resource using the
request body.</p></div>
<div class="paragraph"><p>For PUT requests, the body is a representation of the resource
that is being created or replaced.</p></div>
<div class="paragraph"><p>For POST requests, the body is typically application-specific
instructions on how to process the request, but it may also
be a representation of the resource. When creating a new
resource with POST at a different location, return <code>{true, URI}</code>
with <code>URI</code> the new location.</p></div>
<div class="paragraph"><p>For PATCH requests, the body is a series of instructions on
how to update the resource. Patch files or JSON Patch are
examples of such media types.</p></div>
<div class="paragraph"><p>A response body may be sent. The appropriate media type, charset
and language for the response can be retrieved from the Req
object using the <code>media_type</code>, <code>charset</code> and <code>language</code> keys,
respectively. The body can be set using
<a href="../cowboy_req.set_resp_body">cowboy_req:set_resp_body(3)</a>.</p></div>
</div>
<div class="sect2">
<h3 id="_allowed_methods">allowed_methods</h3>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000000">allowed_methods</span></span>(<span style="color: #009900">Req</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-></span> {<span style="color: #009900">Result</span>, <span style="color: #009900">Req</span>, <span style="color: #009900">State</span>}
<span style="color: #009900">Result</span> <span style="color: #990000">::</span> [<span style="font-weight: bold"><span style="color: #000080">binary</span></span>()] <span style="font-style: italic"><span style="color: #9A1900">%% case sensitive</span></span>
<span style="color: #009900">Default</span> <span style="color: #990000">::</span> [<span style="color: #990000"><<</span><span style="color: #FF0000">"GET"</span><span style="color: #990000">>></span>, <span style="color: #990000"><<</span><span style="color: #FF0000">"HEAD"</span><span style="color: #990000">>></span>, <span style="color: #990000"><<</span><span style="color: #FF0000">"OPTIONS"</span><span style="color: #990000">>></span>]</tt></pre></div></div>
<div class="paragraph"><p>Return the list of allowed methods.</p></div>
</div>
<div class="sect2">
<h3 id="_allow_missing_post">allow_missing_post</h3>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000000">allow_missing_post</span></span>(<span style="color: #009900">Req</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-></span> {<span style="color: #009900">Result</span>, <span style="color: #009900">Req</span>, <span style="color: #009900">State</span>}
<span style="color: #009900">Result</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">boolean</span></span>()
<span style="color: #009900">Default</span> <span style="color: #990000">::</span> <span style="color: #000080">true</span></tt></pre></div></div>
<div class="paragraph"><p>Return whether POST is allowed when the resource doesn’t exist.</p></div>
<div class="paragraph"><p>Returning <code>true</code> here means that a new resource will be
created. The URI for the newly created resource should be
returned from the <code>AcceptCallback</code> function.</p></div>
</div>
<div class="sect2">
<h3 id="_charsets_provided">charsets_provided</h3>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000000">charsets_provided</span></span>(<span style="color: #009900">Req</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-></span> {<span style="color: #009900">Result</span>, <span style="color: #009900">Req</span>, <span style="color: #009900">State</span>}
<span style="color: #009900">Result</span> <span style="color: #990000">::</span> [<span style="font-weight: bold"><span style="color: #000080">binary</span></span>()] <span style="font-style: italic"><span style="color: #9A1900">%% lowercase; case insensitive</span></span>
<span style="color: #009900">Default</span> <span style="color: #990000">-</span> <span style="color: #FF6600">skip</span> <span style="color: #FF6600">this</span> <span style="color: #FF6600">step</span></tt></pre></div></div>
<div class="paragraph"><p>Return the list of charsets the resource provides in order
of preference.</p></div>
<div class="paragraph"><p>During content negotiation Cowboy will pick the most
appropriate charset for the client. The client advertises
charsets it prefers with the accept-charset header. When
that header is missing, Cowboy picks the first charset
from the resource.</p></div>
<div class="paragraph"><p>Cowboy will add the negotiated <code>charset</code> to the Req object
after this step completes:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000000">req</span></span>() <span style="color: #990000">::</span> #{
<span style="color: #0000FF">charset</span> <span style="color: #990000">=></span> <span style="font-weight: bold"><span style="color: #000080">binary</span></span>() <span style="font-style: italic"><span style="color: #9A1900">%% lowercase; case insensitive</span></span>
}</tt></pre></div></div>
</div>
<div class="sect2">
<h3 id="_content_types_accepted">content_types_accepted</h3>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000000">content_types_accepted</span></span>(<span style="color: #009900">Req</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-></span> {<span style="color: #009900">Result</span>, <span style="color: #009900">Req</span>, <span style="color: #009900">State</span>}
<span style="color: #009900">Result</span> <span style="color: #990000">::</span> [{<span style="font-weight: bold"><span style="color: #000080">binary</span></span>() | <span style="color: #009900">ParsedMime</span>, <span style="color: #009900">AcceptCallback</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000080">atom</span></span>()}]
<span style="color: #009900">ParsedMime</span> <span style="color: #990000">::</span> {<span style="color: #009900">Type</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000080">binary</span></span>(), <span style="color: #009900">SubType</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000080">binary</span></span>(), <span style="color: #FF6600">'*'</span> | <span style="color: #009900">Params</span>}
<span style="color: #009900">Params</span> <span style="color: #990000">::</span> [{<span style="color: #009900">Key</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000080">binary</span></span>(), <span style="color: #009900">Value</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000080">binary</span></span>()}]
<span style="color: #009900">Default</span> <span style="color: #990000">-</span> <span style="color: #FF6600">crash</span></tt></pre></div></div>
<div class="paragraph"><p>Return the list of media types the resource accepts in
order of preference.</p></div>
<div class="paragraph"><p>A media type is made of different parts. The media type
<code>text/html;charset=utf-8</code> is of type <code>text</code>, subtype <code>html</code>
and has a single parameter <code>charset</code> with value <code>utf-8</code>.</p></div>
<div class="paragraph"><p>Cowboy will match the content-type request header against
the media types the server accepts and select the appropriate
callback. When that header is missing, or when the server does not
accept this media type, the request fails and an error response
is returned. Cowboy will execute the callback immediately otherwise.</p></div>
<div class="paragraph"><p>An empty parameters list <code>[]</code> means that no parameters will be
accepted. When any parameter is acceptable, the tuple form
should be used with parameters as the atom <code>'*'</code>.</p></div>
<div class="paragraph"><p>Cowboy treats all parameters as case sensitive, except for the
<code>charset</code> parameter, which is known to be case insensitive. You
should therefore always provide the charset as a lowercase
binary string.</p></div>
</div>
<div class="sect2">
<h3 id="_content_types_provided">content_types_provided</h3>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000000">content_types_provided</span></span>(<span style="color: #009900">Req</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-></span> {<span style="color: #009900">Result</span>, <span style="color: #009900">Req</span>, <span style="color: #009900">State</span>}
<span style="color: #009900">Result</span> <span style="color: #990000">::</span> [{<span style="font-weight: bold"><span style="color: #000080">binary</span></span>() | <span style="color: #009900">ParsedMime</span>, <span style="color: #009900">ProvideCallback</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000080">atom</span></span>()}]
<span style="color: #009900">ParsedMime</span> <span style="color: #990000">::</span> {<span style="color: #009900">Type</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000080">binary</span></span>(), <span style="color: #009900">SubType</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000080">binary</span></span>(), <span style="color: #FF6600">'*'</span> | <span style="color: #009900">Params</span>}
<span style="color: #009900">Params</span> <span style="color: #990000">::</span> [{<span style="color: #009900">Key</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000080">binary</span></span>(), <span style="color: #009900">Value</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000080">binary</span></span>()}]
<span style="color: #009900">Default</span> <span style="color: #990000">-</span> [{{ <span style="color: #990000"><<</span><span style="color: #FF0000">"text"</span><span style="color: #990000">>></span>, <span style="color: #990000"><<</span><span style="color: #FF0000">"html"</span><span style="color: #990000">>></span>, <span style="color: #FF6600">'*'</span>}, <span style="color: #FF6600">to_html</span>}]</tt></pre></div></div>
<div class="paragraph"><p>Return the list of media types the resource provides in
order of preference.</p></div>
<div class="paragraph"><p>A media type is made of different parts. The media type
<code>text/html;charset=utf-8</code> is of type <code>text</code>, subtype <code>html</code>
and has a single parameter <code>charset</code> with value <code>utf-8</code>.</p></div>
<div class="paragraph"><p>During content negotiation Cowboy will pick the most appropriate
media type for the client. The client advertises media types it
prefers with the accept header. When that header is missing,
the content negotiation fails and an error response is returned.</p></div>
<div class="paragraph"><p>The callback given for the selected media type will be called
at the end of the execution of GET and HEAD requests when a
representation must be sent to the client.</p></div>
<div class="paragraph"><p>An empty parameters list <code>[]</code> means that no parameters will be
accepted. When any parameter is acceptable, the tuple form
should be used with parameters as the atom <code>'*'</code>.</p></div>
<div class="paragraph"><p>Cowboy treats all parameters as case sensitive, except for the
<code>charset</code> parameter, which is known to be case insensitive. You
should therefore always provide the charset as a lowercase
binary string.</p></div>
<div class="paragraph"><p>Cowboy will add the negotiated <code>media_type</code> to the Req object
after this step completes:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000000">req</span></span>() <span style="color: #990000">::</span> #{
<span style="color: #0000FF">media_type</span> <span style="color: #990000">=></span> <span style="color: #009900">ParsedMime</span>
}</tt></pre></div></div>
</div>
<div class="sect2">
<h3 id="_delete_completed">delete_completed</h3>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000000">delete_completed</span></span>(<span style="color: #009900">Req</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-></span> {<span style="color: #009900">Result</span>, <span style="color: #009900">Req</span>, <span style="color: #009900">State</span>}
<span style="color: #009900">Result</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">boolean</span></span>()
<span style="color: #009900">Default</span> <span style="color: #990000">::</span> <span style="color: #000080">true</span></tt></pre></div></div>
<div class="paragraph"><p>Return whether the resource has been fully deleted from the
system, including from any internal cache.</p></div>
<div class="paragraph"><p>Returning <code>false</code> will result in a <em>202 Accepted</em> response
being sent instead of a <em>200 OK</em> or <em>204 No Content</em>.</p></div>
</div>
<div class="sect2">
<h3 id="_delete_resource">delete_resource</h3>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000000">delete_resource</span></span>(<span style="color: #009900">Req</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-></span> {<span style="color: #009900">Result</span>, <span style="color: #009900">Req</span>, <span style="color: #009900">State</span>}
<span style="color: #009900">Result</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">boolean</span></span>()
<span style="color: #009900">Default</span> <span style="color: #990000">::</span> <span style="color: #000080">false</span></tt></pre></div></div>
<div class="paragraph"><p>Delete the resource.</p></div>
<div class="paragraph"><p>Cowboy will send an error response when this function
returns <code>false</code>.</p></div>
</div>
<div class="sect2">
<h3 id="_expires">expires</h3>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000000">expires</span></span>(<span style="color: #009900">Req</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-></span> {<span style="color: #009900">Result</span>, <span style="color: #009900">Req</span>, <span style="color: #009900">State</span>}
<span style="color: #009900">Result</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">calendar:datetime</span></span>() | <span style="font-weight: bold"><span style="color: #000080">binary</span></span>() | <span style="color: #000080">undefined</span>
<span style="color: #009900">Default</span> <span style="color: #990000">::</span> <span style="color: #000080">undefined</span></tt></pre></div></div>
<div class="paragraph"><p>Return the resource’s expiration date.</p></div>
</div>
<div class="sect2">
<h3 id="_forbidden">forbidden</h3>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000000">forbidden</span></span>(<span style="color: #009900">Req</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-></span> {<span style="color: #009900">Result</span>, <span style="color: #009900">Req</span>, <span style="color: #009900">State</span>}
<span style="color: #009900">Result</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">boolean</span></span>()
<span style="color: #009900">Default</span> <span style="color: #990000">::</span> <span style="color: #000080">false</span></tt></pre></div></div>
<div class="paragraph"><p>Return whether access to the resource is forbidden.</p></div>
<div class="paragraph"><p>A <em>403 Forbidden</em> response will be sent if this
function returns <code>true</code>. This status code means that
access is forbidden regardless of authentication,
and that the request shouldn’t be repeated.</p></div>
</div>
<div class="sect2">
<h3 id="_generate_etag">generate_etag</h3>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000000">generate_etag</span></span>(<span style="color: #009900">Req</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-></span> {<span style="color: #009900">Result</span>, <span style="color: #009900">Req</span>, <span style="color: #009900">State</span>}
<span style="color: #009900">Result</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000080">binary</span></span>() | {<span style="color: #FF6600">weak</span> | <span style="color: #FF6600">strong</span>, <span style="font-weight: bold"><span style="color: #000080">binary</span></span>()}
<span style="color: #009900">Default</span> <span style="color: #990000">-</span> <span style="color: #FF6600">no</span> <span style="color: #FF6600">etag</span> <span style="color: #FF6600">value</span></tt></pre></div></div>
<div class="paragraph"><p>Return the entity tag of the resource.</p></div>
<div class="paragraph"><p>When a binary is returned, the value is automatically
parsed to a tuple. The binary must be in the same
format as the etag header, including quotes.</p></div>
</div>
<div class="sect2">
<h3 id="_is_authorized">is_authorized</h3>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000000">is_authorized</span></span>(<span style="color: #009900">Req</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-></span> {<span style="color: #009900">Result</span>, <span style="color: #009900">Req</span>, <span style="color: #009900">State</span>}
<span style="color: #009900">Result</span> <span style="color: #990000">::</span> <span style="color: #000080">true</span> | {<span style="color: #000080">false</span>, <span style="color: #009900">AuthHeader</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">iodata</span></span>()}
<span style="color: #009900">Default</span> <span style="color: #990000">-</span> <span style="color: #000080">true</span></tt></pre></div></div>
<div class="paragraph"><p>Return whether the user is authorized to perform the action.</p></div>
<div class="paragraph"><p>This function should be used to perform any necessary
authentication of the user before attempting to perform
any action on the resource.</p></div>
<div class="paragraph"><p>When authentication fails, the <code>AuthHeader</code> value will
be sent in the www-authenticate header for the
<em>401 Unauthorized</em> response.</p></div>
</div>
<div class="sect2">
<h3 id="_is_conflict">is_conflict</h3>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000000">is_conflict</span></span>(<span style="color: #009900">Req</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-></span> {<span style="color: #009900">Result</span>, <span style="color: #009900">Req</span>, <span style="color: #009900">State</span>}
<span style="color: #009900">Result</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">boolean</span></span>()
<span style="color: #009900">Default</span> <span style="color: #990000">::</span> <span style="color: #000080">false</span></tt></pre></div></div>
<div class="paragraph"><p>Return whether the PUT request results in a conflict.</p></div>
<div class="paragraph"><p>A <em>409 Conflict</em> response is sent when <code>true</code>.</p></div>
</div>
<div class="sect2">
<h3 id="_known_methods">known_methods</h3>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000000">known_methods</span></span>(<span style="color: #009900">Req</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-></span> {<span style="color: #009900">Result</span>, <span style="color: #009900">Req</span>, <span style="color: #009900">State</span>}
<span style="color: #009900">Result</span> <span style="color: #990000">::</span> [<span style="font-weight: bold"><span style="color: #000080">binary</span></span>()] <span style="font-style: italic"><span style="color: #9A1900">%% case sensitive</span></span>
<span style="color: #009900">Default</span> <span style="color: #990000">::</span> [<span style="color: #990000"><<</span><span style="color: #FF0000">"GET"</span><span style="color: #990000">>></span>, <span style="color: #990000"><<</span><span style="color: #FF0000">"HEAD"</span><span style="color: #990000">>></span>, <span style="color: #990000"><<</span><span style="color: #FF0000">"POST"</span><span style="color: #990000">>></span>, <span style="color: #990000"><<</span><span style="color: #FF0000">"PUT"</span><span style="color: #990000">>></span>,
<span style="color: #990000"><<</span><span style="color: #FF0000">"PATCH"</span><span style="color: #990000">>></span>, <span style="color: #990000"><<</span><span style="color: #FF0000">"DELETE"</span><span style="color: #990000">>></span>, <span style="color: #990000"><<</span><span style="color: #FF0000">"OPTIONS"</span><span style="color: #990000">>></span>]</tt></pre></div></div>
<div class="paragraph"><p>Return the list of known methods.</p></div>
<div class="paragraph"><p>The full list of methods known by the server should be
returned, regardless of their use in the resource.</p></div>
<div class="paragraph"><p>The default value lists the methods Cowboy knows and
implement in <code>cowboy_rest</code>.</p></div>
</div>
<div class="sect2">
<h3 id="_languages_provided">languages_provided</h3>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000000">languages_provided</span></span>(<span style="color: #009900">Req</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-></span> {<span style="color: #009900">Result</span>, <span style="color: #009900">Req</span>, <span style="color: #009900">State</span>}
<span style="color: #009900">Result</span> <span style="color: #990000">::</span> [<span style="font-weight: bold"><span style="color: #000080">binary</span></span>()] <span style="font-style: italic"><span style="color: #9A1900">%% lowercase; case insensitive</span></span>
<span style="color: #009900">Default</span> <span style="color: #990000">-</span> <span style="color: #FF6600">skip</span> <span style="color: #FF6600">this</span> <span style="color: #FF6600">step</span></tt></pre></div></div>
<div class="paragraph"><p>Return the list of languages the resource provides in order
of preference.</p></div>
<div class="paragraph"><p>During content negotiation Cowboy will pick the most
appropriate language for the client. The client advertises
languages it prefers with the accept-language header. When
that header is missing, Cowboy picks the first language
from the resource.</p></div>
<div class="paragraph"><p>Cowboy will add the negotiated <code>language</code> to the Req object
after this step completes:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000000">req</span></span>() <span style="color: #990000">::</span> #{
<span style="color: #0000FF">language</span> <span style="color: #990000">=></span> <span style="font-weight: bold"><span style="color: #000080">binary</span></span>() <span style="font-style: italic"><span style="color: #9A1900">%% lowercase; case insensitive</span></span>
}</tt></pre></div></div>
</div>
<div class="sect2">
<h3 id="_last_modified">last_modified</h3>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000000">last_modified</span></span>(<span style="color: #009900">Req</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-></span> {<span style="color: #009900">Result</span>, <span style="color: #009900">Req</span>, <span style="color: #009900">State</span>}
<span style="color: #009900">Result</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">calendar:datetime</span></span>()
<span style="color: #009900">Default</span> <span style="color: #990000">-</span> <span style="color: #FF6600">no</span> <span style="color: #FF6600">last</span> <span style="color: #FF6600">modified</span> <span style="color: #FF6600">value</span></tt></pre></div></div>
<div class="paragraph"><p>Return the resource’s last modification date.</p></div>
<div class="paragraph"><p>This date will be used to test against the if-modified-since
and if-unmodified-since headers, and sent as the last-modified
header in the response to GET and HEAD requests.</p></div>
</div>
<div class="sect2">
<h3 id="_malformed_request">malformed_request</h3>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000000">malformed_request</span></span>(<span style="color: #009900">Req</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-></span> {<span style="color: #009900">Result</span>, <span style="color: #009900">Req</span>, <span style="color: #009900">State</span>}
<span style="color: #009900">Result</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">boolean</span></span>()
<span style="color: #009900">Default</span> <span style="color: #990000">::</span> <span style="color: #000080">false</span></tt></pre></div></div>
<div class="paragraph"><p>Return whether the request is malformed.</p></div>
<div class="paragraph"><p>A request is malformed when a component required by the
resource is invalid. This may include the query string
or individual headers. They should be parsed and validated
in this function. The body should not be read at this point.</p></div>
</div>
<div class="sect2">
<h3 id="_moved_permanently">moved_permanently</h3>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000000">moved_permanently</span></span>(<span style="color: #009900">Req</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-></span> {<span style="color: #009900">Result</span>, <span style="color: #009900">Req</span>, <span style="color: #009900">State</span>}
<span style="color: #009900">Result</span> <span style="color: #990000">::</span> {<span style="color: #000080">true</span>, <span style="color: #009900">URI</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">iodata</span></span>()} | <span style="color: #000080">false</span>
<span style="color: #009900">Default</span> <span style="color: #990000">::</span> <span style="color: #000080">false</span></tt></pre></div></div>
<div class="paragraph"><p>Return whether the resource was permanently moved, and
what its new location is.</p></div>
</div>
<div class="sect2">
<h3 id="_moved_temporarily">moved_temporarily</h3>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000000">moved_temporarily</span></span>(<span style="color: #009900">Req</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-></span> {<span style="color: #009900">Result</span>, <span style="color: #009900">Req</span>, <span style="color: #009900">State</span>}
<span style="color: #009900">Result</span> <span style="color: #990000">::</span> {<span style="color: #000080">true</span>, <span style="color: #009900">URI</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">iodata</span></span>()} | <span style="color: #000080">false</span>
<span style="color: #009900">Default</span> <span style="color: #990000">::</span> <span style="color: #000080">false</span></tt></pre></div></div>
<div class="paragraph"><p>Return whether the resource was temporarily moved, and
what its new location is.</p></div>
</div>
<div class="sect2">
<h3 id="_multiple_choices">multiple_choices</h3>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000000">multiple_choices</span></span>(<span style="color: #009900">Req</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-></span> {<span style="color: #009900">Result</span>, <span style="color: #009900">Req</span>, <span style="color: #009900">State</span>}
<span style="color: #009900">Result</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">boolean</span></span>()
<span style="color: #009900">Default</span> <span style="color: #990000">::</span> <span style="color: #000080">false</span></tt></pre></div></div>
<div class="paragraph"><p>Return whether the client should engage in reactive
negotiation.</p></div>
<div class="paragraph"><p>Return <code>true</code> when the server has multiple representations
of a resource, each with their specific identifier, but is
unable to determine which is best for the client. For
example an image might have different sizes and the server
is unable to determine the capabilities of the client.</p></div>
<div class="paragraph"><p>When returning <code>true</code> the server should send a body with
links to the different representations. If the server has
a preferred representation it can send its link inside a
location header.</p></div>
</div>
<div class="sect2">
<h3 id="_options">options</h3>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000000">options</span></span>(<span style="color: #009900">Req</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-></span> {<span style="color: #FF6600">ok</span>, <span style="color: #009900">Req</span>, <span style="color: #009900">State</span>}</tt></pre></div></div>
<div class="paragraph"><p>Respond to an OPTIONS request.</p></div>
<div class="paragraph"><p>The response should inform the client the communication
options available for this resource. By default Cowboy
will send a <em>200 OK</em> response with the allow header set.</p></div>
</div>
<div class="sect2">
<h3 id="_previously_existed">previously_existed</h3>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000000">previously_existed</span></span>(<span style="color: #009900">Req</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-></span> {<span style="color: #009900">Result</span>, <span style="color: #009900">Req</span>, <span style="color: #009900">State</span>}
<span style="color: #009900">Result</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">boolean</span></span>()
<span style="color: #009900">Default</span> <span style="color: #990000">::</span> <span style="color: #000080">false</span></tt></pre></div></div>
<div class="paragraph"><p>Return whether the resource existed previously.</p></div>
</div>
<div class="sect2">
<h3 id="_providecallback">ProvideCallback</h3>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="color: #009900">ProvideCallback</span>(<span style="color: #009900">Req</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-></span> {<span style="color: #009900">Result</span>, <span style="color: #009900">Req</span>, <span style="color: #009900">State</span>}
<span style="color: #009900">Result</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">cowboy_req:resp_body</span></span>()
<span style="color: #009900">Default</span> <span style="color: #990000">-</span> <span style="color: #FF6600">crash</span></tt></pre></div></div>
<div class="paragraph"><p>Return the response body.</p></div>
<div class="paragraph"><p>The response body can be provided either as the actual data
to be sent or a tuple indicating which file to send.</p></div>
<div class="paragraph"><p>This function is called for both GET and HEAD requests. For
the latter the body is not sent, however.</p></div>
<div class="paragraph"><p>Note that there used to be a way to stream the response body.
It was temporarily removed and will be added back in a later
release.</p></div>
</div>
<div class="sect2">
<h3 id="_resource_exists">resource_exists</h3>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000000">resource_exists</span></span>(<span style="color: #009900">Req</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-></span> {<span style="color: #009900">Result</span>, <span style="color: #009900">Req</span>, <span style="color: #009900">State</span>}
<span style="color: #009900">Result</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">boolean</span></span>()
<span style="color: #009900">Default</span> <span style="color: #990000">::</span> <span style="color: #000080">true</span></tt></pre></div></div>
<div class="paragraph"><p>Return whether the resource exists.</p></div>
</div>
<div class="sect2">
<h3 id="_service_available">service_available</h3>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000000">service_available</span></span>(<span style="color: #009900">Req</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-></span> {<span style="color: #009900">Result</span>, <span style="color: #009900">Req</span>, <span style="color: #009900">State</span>}
<span style="color: #009900">Result</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">boolean</span></span>()
<span style="color: #009900">Default</span> <span style="color: #990000">::</span> <span style="color: #000080">true</span></tt></pre></div></div>
<div class="paragraph"><p>Return whether the service is available.</p></div>
<div class="paragraph"><p>A <em>503 Service Unavailable</em> response will be sent when this
function returns <code>false</code>.</p></div>
</div>
<div class="sect2">
<h3 id="_uri_too_long">uri_too_long</h3>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000000">uri_too_long</span></span>(<span style="color: #009900">Req</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-></span> {<span style="color: #009900">Result</span>, <span style="color: #009900">Req</span>, <span style="color: #009900">State</span>}
<span style="color: #009900">Result</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">boolean</span></span>()
<span style="color: #009900">Default</span> <span style="color: #990000">::</span> <span style="color: #000080">false</span></tt></pre></div></div>
<div class="paragraph"><p>Return whether the requested URI is too long.</p></div>
<div class="paragraph"><p>This function can be used to further restrict the length
of the URI for this specific resource.</p></div>
</div>
<div class="sect2">
<h3 id="_valid_content_headers">valid_content_headers</h3>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000000">valid_content_headers</span></span>(<span style="color: #009900">Req</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-></span> {<span style="color: #009900">Result</span>, <span style="color: #009900">Req</span>, <span style="color: #009900">State</span>}
<span style="color: #009900">Result</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">boolean</span></span>()
<span style="color: #009900">Default</span> <span style="color: #990000">::</span> <span style="color: #000080">true</span></tt></pre></div></div>
<div class="paragraph"><p>Return whether the content headers are valid.</p></div>
<div class="paragraph"><p>This callback can be used to reject requests that have
invalid content header values, for example an unsupported
content-encoding.</p></div>
</div>
<div class="sect2">
<h3 id="_valid_entity_length">valid_entity_length</h3>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000000">valid_entity_length</span></span>(<span style="color: #009900">Req</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-></span> {<span style="color: #009900">Result</span>, <span style="color: #009900">Req</span>, <span style="color: #009900">State</span>}
<span style="color: #009900">Result</span> <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">boolean</span></span>()
<span style="color: #009900">Default</span> <span style="color: #990000">::</span> <span style="color: #000080">true</span></tt></pre></div></div>
<div class="paragraph"><p>Return whether the request body length is within acceptable boundaries.</p></div>
<div class="paragraph"><p>A <em>413 Request Entity Too Large</em> response will be sent if this
function returns <code>false</code>.</p></div>
</div>
<div class="sect2">
<h3 id="_variances">variances</h3>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="font-weight: bold"><span style="color: #000000">variances</span></span>(<span style="color: #009900">Req</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-></span> {<span style="color: #009900">Result</span>, <span style="color: #009900">Req</span>, <span style="color: #009900">State</span>}
<span style="color: #009900">Result</span> <span style="color: #990000">::</span> [<span style="font-weight: bold"><span style="color: #000080">binary</span></span>()] <span style="font-style: italic"><span style="color: #9A1900">%% case insensitive</span></span>
<span style="color: #009900">Default</span> <span style="color: #990000">::</span> []</tt></pre></div></div>
<div class="paragraph"><p>Return the list of request headers that affect the
representation of the resource.</p></div>
<div class="paragraph"><p>Cowboy automatically adds the accept, accept-charset and
accept-language headers when necessary.</p></div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_see_also">See also</h2>
<div class="sectionbody">
<div class="paragraph"><p><a href="..">cowboy(7)</a>,
<a href="../cowboy_handler">cowboy_handler(3)</a></p></div>
</div>
</div>
</div>
<div class="span3 sidecol">
<h3>
Cowboy
2.0
Function Reference
</h3>
<ul>
<li><a href="/docs/en/cowboy/2.0/guide">User Guide</a></li>
<li><a href="/docs/en/cowboy/2.0/manual">Function Reference</a></li>
</ul>
<h4 id="docs-nav">Navigation</h4>
<h4>Version select</h4>
<ul>
<li><a href="/docs/en/cowboy/2.4/manual">2.4</a></li>
<li><a href="/docs/en/cowboy/2.3/manual">2.3</a></li>
<li><a href="/docs/en/cowboy/2.2/manual">2.2</a></li>
<li><a href="/docs/en/cowboy/2.1/manual">2.1</a></li>
<li><a href="/docs/en/cowboy/2.0/manual">2.0</a></li>
<li><a href="/docs/en/cowboy/1.0/manual">1.0</a></li>
</ul>
</div>
</div>
</div>
</div>
<footer>
<div class="container">
<div class="row">
<div class="span6">
<p id="scroll-top"><a href="#">↑ Scroll to top</a></p>
<nav>
<ul>
<li><a href="mailto:[email protected]" title="Contact us">Contact us</a></li><li><a href="https://github.com/ninenines/ninenines.github.io" title="Github repository">Contribute to this site</a></li>
</ul>
</nav>
</div>
<div class="span6 credits">
<p><img src="/img/footer_logo.png"></p>
<p>Copyright © Loïc Hoguin 2012-2018</p>
</div>
</div>
</div>
</footer>
<script src="/js/custom.js"></script>
</body>
</html>
|