summaryrefslogtreecommitdiffstats
path: root/docs/en/cowboy/2.1/manual/cowboy_stream/index.html
blob: 2dd1200b228a4a347c60115a9e229b5b4d6ef029 (plain) (blame)
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
<!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">

    <meta name="generator" content="Hugo 0.30.2" />

    <title>Nine Nines: cowboy_stream(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="Keep in touch!" href="http://twitter.com/lhoguin"><img src="/img/ico_microblog.png" data-hover="/img/ico_microblog_alt.png"></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_stream(3)</span></h1>

<div class="sect1">
<h2 id="_name">Name</h2>
<div class="sectionbody">
<div class="paragraph"><p>cowboy_handler - Stream handlers</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_description">Description</h2>
<div class="sectionbody">
<div class="paragraph"><p>The module <code>cowboy_stream</code> defines a callback interface
and a protocol for handling HTTP streams.</p></div>
<div class="paragraph"><p>An HTTP request and its associated response is called
a stream. A connection may have many streams. In HTTP/1.1
they are executed sequentially, while in HTTP/2 they are
executed concurrently.</p></div>
<div class="paragraph"><p>Cowboy calls the stream handler for nearly all events
related to a stream. Exceptions vary depending on the
protocol.</p></div>
<div class="paragraph"><p>Extra care must be taken when implementing stream handlers
to ensure compatibility. While some modification of the
events and commands is allowed, it is generally not a good
idea to completely omit them.</p></div>
</div>
</div>
<div class="sect1">
<h2 id="_callbacks">Callbacks</h2>
<div class="sectionbody">
<div class="paragraph"><p>Stream handlers must implement the following interface:</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.8
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">StreamID</span>, <span style="color: #009900">Req</span>, <span style="color: #009900">Opts</span>) <span style="color: #990000">-&gt;</span> {<span style="color: #009900">Commands</span>, <span style="color: #009900">State</span>}
<span style="font-weight: bold"><span style="color: #000000">data</span></span>(<span style="color: #009900">StreamID</span>, <span style="color: #009900">IsFin</span>, <span style="color: #009900">Data</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-&gt;</span> {<span style="color: #009900">Commands</span>, <span style="color: #009900">State</span>}
<span style="font-weight: bold"><span style="color: #000000">info</span></span>(<span style="color: #009900">StreamID</span>, <span style="color: #009900">Info</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-&gt;</span> {<span style="color: #009900">Commands</span>, <span style="color: #009900">State</span>}
<span style="font-weight: bold"><span style="color: #000000">terminate</span></span>(<span style="color: #009900">StreamID</span>, <span style="color: #009900">Reason</span>, <span style="color: #009900">State</span>) <span style="color: #990000">-&gt;</span> <span style="font-weight: bold"><span style="color: #000000">any</span></span>()
<span style="font-weight: bold"><span style="color: #000000">early_error</span></span>(<span style="color: #009900">StreamID</span>, <span style="color: #009900">Reason</span>, <span style="color: #009900">PartialReq</span>, <span style="color: #009900">Resp</span>, <span style="color: #009900">Opts</span>) <span style="color: #990000">-&gt;</span> <span style="color: #009900">Resp</span>

<span style="color: #009900">StreamID</span>   <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">cowboy_stream:streamid</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">Opts</span>       <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">cowboy:opts</span></span>()
<span style="color: #009900">Commands</span>   <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">cowboy_stream:commands</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">IsFin</span>      <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">cowboy_stream:fin</span></span>()
<span style="color: #009900">Data</span>       <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000080">binary</span></span>()
<span style="color: #009900">Info</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: #000000">cowboy_stream:reason</span></span>()
<span style="color: #009900">PartialReq</span>  <span style="color: #990000">-</span> <span style="font-weight: bold"><span style="color: #000000">cowboy_req:req</span></span>(), <span style="color: #FF6600">except</span> <span style="color: #FF6600">all</span> <span style="color: #FF6600">fields</span> <span style="color: #FF6600">are</span> <span style="color: #FF6600">optional</span>
<span style="color: #009900">Resp</span>       <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">cowboy_stream:resp_command</span></span>()</tt></pre></div></div>
<div class="paragraph"><p>HTTP/1.1 will initialize a stream only when the request-line
and all headers have been received. When errors occur before
that point Cowboy will call the callback <code>early_error/5</code>
with a partial request, the error reason and the response
Cowboy intends to send. All other events go throuh the
stream handler using the normal callbacks.</p></div>
<div class="paragraph"><p>HTTP/2 will initialize the stream when the <code>HEADERS</code> block has
been fully received and decoded. Any protocol error occuring
before that will not result in a response being sent and
will therefore not go through the stream handler. In addition
Cowboy may terminate streams without sending an HTTP response
back.</p></div>
<div class="paragraph"><p>The stream is initialized by calling <code>init/3</code>. All streams
that are initialized will eventually be terminated by calling
<code>terminate/3</code>.</p></div>
<div class="paragraph"><p>When Cowboy receives data for the stream it will call <code>data/4</code>.
The data given is the request body after any transfer decoding
has been applied.</p></div>
<div class="paragraph"><p>When Cowboy receives a message addressed to a stream, or when
Cowboy needs to inform the stream handler that an internal
event has occurred, it will call <code>info/3</code>.</p></div>
</div>
</div>
<div class="sect1">
<h2 id="commands">Commands</h2>
<div class="sectionbody">
<div class="paragraph"><p>Stream handlers can return a list of commands to be executed
from the <code>init/3</code>, <code>data/4</code> and <code>info/3</code> callbacks. In addition,
the <code>early_error/5</code> callback must return a response command.</p></div>
<div class="paragraph"><p>The following commands are defined:</p></div>
<div class="sect2">
<h3 id="response_command">response</h3>
<div class="paragraph"><p>Send a response to the client.</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>{<span style="color: #FF6600">response</span>, <span style="font-weight: bold"><span style="color: #000000">cowboy:http_status</span></span>(), <span style="font-weight: bold"><span style="color: #000000">cowboy:http_headers</span></span>(),
    <span style="font-weight: bold"><span style="color: #000000">cowboy_req:resp_body</span></span>()}</tt></pre></div></div>
<div class="paragraph"><p>No more data can be sent after this command.</p></div>
</div>
<div class="sect2">
<h3 id="headers_command">headers</h3>
<div class="paragraph"><p>Initiate a response to the client.</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>{<span style="color: #FF6600">headers</span>, <span style="font-weight: bold"><span style="color: #000000">cowboy:http_status</span></span>(), <span style="font-weight: bold"><span style="color: #000000">cowboy:http_headers</span></span>()}</tt></pre></div></div>
<div class="paragraph"><p>This initiates a response to the client. The stream
will end when a data command with the <code>fin</code> flag is
returned.</p></div>
</div>
<div class="sect2">
<h3 id="data_command">data</h3>
<div class="paragraph"><p>Send data to the client.</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>{<span style="color: #FF6600">data</span>, <span style="font-weight: bold"><span style="color: #000000">fin</span></span>(), <span style="font-weight: bold"><span style="color: #000000">iodata</span></span>()}</tt></pre></div></div>
</div>
<div class="sect2">
<h3 id="push_command">push</h3>
<div class="paragraph"><p>Push a resource to the client.</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>{<span style="color: #FF6600">push</span>, <span style="color: #009900">Method</span>, <span style="color: #009900">Scheme</span>, <span style="color: #009900">Host</span>, <span style="font-weight: bold"><span style="color: #000000">inet:port_number</span></span>(),
    <span style="color: #009900">Path</span>, <span style="color: #009900">Qs</span>, <span style="font-weight: bold"><span style="color: #000000">cowboy:http_headers</span></span>()}

<span style="color: #009900">Method</span> <span style="color: #990000">=</span> <span style="color: #009900">Scheme</span> <span style="color: #990000">=</span> <span style="color: #009900">Host</span> <span style="color: #990000">=</span> <span style="color: #009900">Path</span> <span style="color: #990000">=</span> <span style="color: #009900">Qs</span> <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000080">binary</span></span>()</tt></pre></div></div>
<div class="paragraph"><p>The command will be ignored if the protocol does not provide
any server push mechanism.</p></div>
</div>
<div class="sect2">
<h3 id="_flow">flow</h3>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>{<span style="color: #FF6600">flow</span>, <span style="font-weight: bold"><span style="color: #000000">pos_integer</span></span>()}</tt></pre></div></div>
<div class="paragraph"><p>Request more data to be read from the request body. The
exact behavior depends on the protocol.</p></div>
</div>
<div class="sect2">
<h3 id="_spawn">spawn</h3>
<div class="paragraph"><p>Inform Cowboy that a process was spawned and should be
supervised.</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>{<span style="font-weight: bold"><span style="color: #000080">spawn</span></span>, <span style="font-weight: bold"><span style="color: #000080">pid</span></span>(), <span style="font-weight: bold"><span style="color: #000000">timeout</span></span>()}</tt></pre></div></div>
</div>
<div class="sect2">
<h3 id="_error_response">error_response</h3>
<div class="paragraph"><p>Send an error response if no response was sent previously.</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>{<span style="color: #FF6600">error_response</span>, <span style="font-weight: bold"><span style="color: #000000">cowboy:http_status</span></span>(), <span style="font-weight: bold"><span style="color: #000000">cowboy:http_headers</span></span>(), <span style="font-weight: bold"><span style="color: #000000">iodata</span></span>()}</tt></pre></div></div>
</div>
<div class="sect2">
<h3 id="switch_protocol_command">switch_protocol</h3>
<div class="paragraph"><p>Switch to a different protocol.</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>{<span style="color: #FF6600">switch_protocol</span>, <span style="font-weight: bold"><span style="color: #000000">cowboy:http_headers</span></span>(), <span style="font-weight: bold"><span style="color: #000000">module</span></span>(), <span style="font-weight: bold"><span style="color: #000000">state</span></span>()}</tt></pre></div></div>
<div class="paragraph"><p>Contains the headers that will be sent in the 101 response,
along with the module implementing the protocol we are
switching to and its initial state.</p></div>
</div>
<div class="sect2">
<h3 id="_stop">stop</h3>
<div class="paragraph"><p>Stop the stream.</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt><span style="color: #FF6600">stop</span></tt></pre></div></div>
<div class="paragraph"><p>While no more data can be sent after the <code>fin</code> flag was set,
the stream is still tracked by Cowboy until it is stopped by
the handler.</p></div>
<div class="paragraph"><p>The behavior when stopping a stream for which no response
has been sent will vary depending on the protocol. The stream
will end successfully as far as the client is concerned.</p></div>
<div class="paragraph"><p>To indicate that an error occurred, either use <code>error_response</code>
before stopping, or use <code>internal_error</code>.</p></div>
</div>
<div class="sect2">
<h3 id="_internal_error">internal_error</h3>
<div class="paragraph"><p>Stop the stream with an error.</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>{<span style="color: #FF6600">internal_error</span>, <span style="color: #009900">Reason</span>, <span style="color: #009900">HumanReadable</span>}

<span style="color: #009900">Reason</span>        <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000000">any</span></span>()
<span style="color: #009900">HumanReadable</span> <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000080">atom</span></span>()</tt></pre></div></div>
<div class="paragraph"><p>This command should be used when the stream cannot continue
because of an internal error. An <code>error_response</code> command
may be sent before that to advertise to the client why the
stream is dropped.</p></div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_predefined_events">Predefined events</h2>
<div class="sectionbody">
<div class="paragraph"><p>Cowboy will forward all messages sent to the stream to
the <code>info/3</code> callback. To send a message to a stream,
send a message to the connection process with the form
<code>{{Pid, StreamID}, Msg}</code>. The connection process will
then forward <code>Msg</code> to the stream handlers.</p></div>
<div class="paragraph"><p>Cowboy will also forward the exit signals for the
processes that the stream spawned.</p></div>
<div class="sect2">
<h3 id="_exit">EXIT</h3>
<div class="paragraph"><p>A process spawned by this stream has exited.</p></div>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.8
by Lorenzo Bettini
http://www.lorenzobettini.it
http://www.gnu.org/software/src-highlite -->
<pre><tt>{<span style="color: #000080">'EXIT'</span>, <span style="font-weight: bold"><span style="color: #000080">pid</span></span>(), <span style="font-weight: bold"><span style="color: #000000">any</span></span>()}</tt></pre></div></div>
<div class="paragraph"><p>This is the raw exit message without any modification.</p></div>
</div>
<div class="sect2">
<h3 id="_response">response</h3>
<div class="paragraph"><p>Same as the <a href="../response_command">response command</a>.</p></div>
<div class="paragraph"><p>Usually sent when the request process replies to the client.
May also be sent by Cowboy internally.</p></div>
</div>
<div class="sect2">
<h3 id="_headers">headers</h3>
<div class="paragraph"><p>Same as the <a href="../headers_command">headers command</a>.</p></div>
<div class="paragraph"><p>Sent when the request process starts replying to the client.</p></div>
</div>
<div class="sect2">
<h3 id="_data">data</h3>
<div class="paragraph"><p>Same as the <a href="../data_command">data command</a>.</p></div>
<div class="paragraph"><p>Sent when the request process streams data to the client.</p></div>
</div>
<div class="sect2">
<h3 id="_push">push</h3>
<div class="paragraph"><p>Same as the <a href="../push_command">push command</a>.</p></div>
<div class="paragraph"><p>Sent when the request process pushes a resource to the client.</p></div>
</div>
<div class="sect2">
<h3 id="_switch_protocol">switch_protocol</h3>
<div class="paragraph"><p>Same as the <a href="../switch_protocol_command">switch_protocol command</a>.</p></div>
<div class="paragraph"><p>Sent when switching to the HTTP/2 or Websocket protocol.</p></div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_exports">Exports</h2>
<div class="sectionbody">
<div class="paragraph"><p>The following function should be called by modules implementing
stream handlers to execute the next stream handler in the list:</p></div>
<div class="ulist"><ul>
<li>
<p>
<a href="../cowboy_stream.init">cowboy_stream:init(3)</a> - Initialize a stream
</p>
</li>
<li>
<p>
<a href="../cowboy_stream.data">cowboy_stream:data(3)</a> - Handle data for a stream
</p>
</li>
<li>
<p>
<a href="../cowboy_stream.info">cowboy_stream:info(3)</a> - Handle a message for a stream
</p>
</li>
<li>
<p>
<a href="../cowboy_stream.terminate">cowboy_stream:terminate(3)</a> - Terminate a stream
</p>
</li>
<li>
<p>
<a href="../cowboy_stream.early_error">cowboy_stream:early_error(3)</a> - Handle an early error for a stream
</p>
</li>
</ul></div>
</div>
</div>
<div class="sect1">
<h2 id="_types">Types</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_commands">commands()</h3>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.8
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">commands</span></span>() <span style="color: #990000">::</span> [<span style="color: #009900">Command</span>]</tt></pre></div></div>
<div class="paragraph"><p>See the <a href="../commands">list of commands</a> for details.</p></div>
</div>
<div class="sect2">
<h3 id="_fin">fin()</h3>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.8
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">fin</span></span>() <span style="color: #990000">::</span> <span style="color: #FF6600">fin</span> | <span style="color: #FF6600">nofin</span></tt></pre></div></div>
<div class="paragraph"><p>Used in commands and events to indicate that this is
the end of the stream.</p></div>
</div>
<div class="sect2">
<h3 id="_partial_req">partial_req()</h3>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.8
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">method</span>  <span style="color: #990000">=&gt;</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: #0000FF">version</span> <span style="color: #990000">=&gt;</span> <span style="font-weight: bold"><span style="color: #000000">cowboy:http_version</span></span>() | <span style="font-weight: bold"><span style="color: #000080">atom</span></span>(),
    <span style="color: #0000FF">scheme</span>  <span style="color: #990000">=&gt;</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: #0000FF">host</span>    <span style="color: #990000">=&gt;</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: #0000FF">port</span>    <span style="color: #990000">=&gt;</span> <span style="font-weight: bold"><span style="color: #000000">inet:port_number</span></span>(),
    <span style="color: #0000FF">path</span>    <span style="color: #990000">=&gt;</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: #0000FF">qs</span>      <span style="color: #990000">=&gt;</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: #0000FF">headers</span> <span style="color: #990000">=&gt;</span> <span style="font-weight: bold"><span style="color: #000000">cowboy:http_headers</span></span>(),
    <span style="color: #0000FF">peer</span>    <span style="color: #990000">=&gt;</span> {<span style="font-weight: bold"><span style="color: #000000">inet:ip_address</span></span>(), <span style="font-weight: bold"><span style="color: #000000">inet:port_number</span></span>()}
}</tt></pre></div></div>
<div class="paragraph"><p>Partial request information received when an early error is
detected.</p></div>
</div>
<div class="sect2">
<h3 id="_reason">reason()</h3>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.8
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">reason</span></span>() <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000080">normal</span></span> | <span style="color: #FF6600">switch_protocol</span>
    | {<span style="color: #FF6600">internal_error</span>, <span style="color: #FF6600">timeout</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">HumanReadable</span>}
    | {<span style="color: #FF6600">socket_error</span>, <span style="color: #FF6600">closed</span> | <span style="font-weight: bold"><span style="color: #000080">atom</span></span>(), <span style="color: #009900">HumanReadable</span>}
    | {<span style="color: #FF6600">stream_error</span>, <span style="color: #009900">Error</span>, <span style="color: #009900">HumanReadable</span>}
    | {<span style="color: #FF6600">connection_error</span>, <span style="color: #009900">Error</span>, <span style="color: #009900">HumanReadable</span>}
    | {<span style="color: #FF6600">stop</span>, <span style="font-weight: bold"><span style="color: #000000">cow_http2:frame</span></span>(), <span style="color: #009900">HumanReadable</span>}

<span style="color: #009900">Error</span>         <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000080">atom</span></span>()
<span style="color: #009900">HumanReadable</span> <span style="color: #990000">=</span> <span style="font-weight: bold"><span style="color: #000080">atom</span></span>()</tt></pre></div></div>
<div class="paragraph"><p>Reason for the stream termination.</p></div>
</div>
<div class="sect2">
<h3 id="_resp_command">resp_command()</h3>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.8
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">resp_command</span></span>() <span style="color: #990000">::</span> {<span style="color: #FF6600">response</span>, <span style="font-weight: bold"><span style="color: #000000">cowboy:http_status</span></span>(),
    <span style="font-weight: bold"><span style="color: #000000">cowboy:http_headers</span></span>(), <span style="font-weight: bold"><span style="color: #000000">cowboy_req:resp_body</span></span>()}</tt></pre></div></div>
<div class="paragraph"><p>See the <a href="../response_command">response command</a> for details.</p></div>
</div>
<div class="sect2">
<h3 id="_streamid">streamid()</h3>
<div class="listingblock">
<div class="content"><!-- Generator: GNU source-highlight 3.1.8
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">streamid</span></span>() <span style="color: #990000">::</span> <span style="font-weight: bold"><span style="color: #000000">any</span></span>()</tt></pre></div></div>
<div class="paragraph"><p>The identifier for this stream.</p></div>
<div class="paragraph"><p>The identifier is unique over the connection process.
It is possible to form a unique identifier node-wide and
cluster-wide by wrapping it in a <code>{self(), StreamID}</code>
tuple.</p></div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_changelog">Changelog</h2>
<div class="sectionbody">
<div class="ulist"><ul>
<li>
<p>
<strong>2.0</strong>: Module introduced.
</p>
</li>
</ul></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_http">cowboy_http(3)</a>,
<a href="../cowboy_http2">cowboy_http2(3)</a></p></div>
</div>
</div>





</div>

<div class="span3 sidecol">


<h3>
	Cowboy
	2.1
	Function Reference
	
</h3>

<ul>
	
		<li><a href="/docs/en/cowboy/2.1/guide">User Guide</a></li>
	
	
		<li><a href="/docs/en/cowboy/2.1/manual">Function Reference</a></li>
	
	
</ul>

<h4 id="docs-nav">Navigation</h4>

<h4>Version select</h4>
<ul>
	
	
	
		<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 &copy; Loïc Hoguin 2012-2016</p>
            </div>
          </div>
        </div>
      </footer>

    
    <script src="/js/custom.js"></script>
  </body>
</html>