summaryrefslogtreecommitdiffstats
path: root/docs/en/cowboy/2.3/manual/cowboy_stream/index.html
blob: 298fc18e65a4515cd0c656760e53058a752985e5 (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
<!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_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="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>

<h2 id="_name">Name</h2>
<p>cowboy_handler - Stream handlers</p>
<h2 id="_description">Description</h2>
<p>The module <code>cowboy_stream</code> defines a callback interface and a protocol for handling HTTP streams.</p>
<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>
<p>Cowboy calls the stream handler for nearly all events related to a stream. Exceptions vary depending on the protocol.</p>
<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>
<h2 id="_callbacks">Callbacks</h2>
<p>Stream handlers must implement the following interface:</p>
<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><b><font color="#000000">init</font></b>(<font color="#009900">StreamID</font>, <font color="#009900">Req</font>, <font color="#009900">Opts</font>) <font color="#990000">-&gt;</font> {<font color="#009900">Commands</font>, <font color="#009900">State</font>}
<b><font color="#000000">data</font></b>(<font color="#009900">StreamID</font>, <font color="#009900">IsFin</font>, <font color="#009900">Data</font>, <font color="#009900">State</font>) <font color="#990000">-&gt;</font> {<font color="#009900">Commands</font>, <font color="#009900">State</font>}
<b><font color="#000000">info</font></b>(<font color="#009900">StreamID</font>, <font color="#009900">Info</font>, <font color="#009900">State</font>) <font color="#990000">-&gt;</font> {<font color="#009900">Commands</font>, <font color="#009900">State</font>}
<b><font color="#000000">terminate</font></b>(<font color="#009900">StreamID</font>, <font color="#009900">Reason</font>, <font color="#009900">State</font>) <font color="#990000">-&gt;</font> <b><font color="#000000">any</font></b>()
<b><font color="#000000">early_error</font></b>(<font color="#009900">StreamID</font>, <font color="#009900">Reason</font>, <font color="#009900">PartialReq</font>, <font color="#009900">Resp</font>, <font color="#009900">Opts</font>) <font color="#990000">-&gt;</font> <font color="#009900">Resp</font>

<font color="#009900">StreamID</font>   <font color="#990000">::</font> <b><font color="#000000">cowboy_stream:streamid</font></b>()
<font color="#009900">Req</font>        <font color="#990000">::</font> <b><font color="#000000">cowboy_req:req</font></b>()
<font color="#009900">Opts</font>       <font color="#990000">::</font> <b><font color="#000000">cowboy:opts</font></b>()
<font color="#009900">Commands</font>   <font color="#990000">::</font> <b><font color="#000000">cowboy_stream:commands</font></b>()
<font color="#009900">State</font>      <font color="#990000">::</font> <b><font color="#000000">any</font></b>()
<font color="#009900">IsFin</font>      <font color="#990000">::</font> <b><font color="#000000">cowboy_stream:fin</font></b>()
<font color="#009900">Data</font>       <font color="#990000">::</font> <b><font color="#000080">binary</font></b>()
<font color="#009900">Info</font>       <font color="#990000">::</font> <b><font color="#000000">any</font></b>()
<font color="#009900">Reason</font>     <font color="#990000">::</font> <b><font color="#000000">cowboy_stream:reason</font></b>()
<font color="#009900">PartialReq</font>  <font color="#990000">-</font> <b><font color="#000000">cowboy_req:req</font></b>(), <font color="#FF6600">except</font> <font color="#FF6600">all</font> <font color="#FF6600">fields</font> <font color="#FF6600">are</font> <font color="#FF6600">optional</font>
<font color="#009900">Resp</font>       <font color="#990000">::</font> <b><font color="#000000">cowboy_stream:resp_command</font></b>()</tt></pre>
</div></div>
<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>
<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>
<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>
<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>
<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>
<h2 id="commands">Commands</h2>
<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>
<!-- @todo We need a &apos;log&apos; command that would call error_logger.-->
<!-- It&apos;s better than doing in the handlers directly because-->
<!-- then we can have other stream handlers manipulate those logs.-->
<!-- @todo We need a command to send a message so that other-->
<!-- stream handlers can manipulate these messages if necessary.-->
<p>The following commands are defined:</p>
<h3 id="inform_command">inform</h3>
<p>Send an informational response to the client.</p>
<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>{<font color="#FF6600">inform</font>, <b><font color="#000000">cowboy:http_status</font></b>(), <b><font color="#000000">cowboy:http_headers</font></b>()}</tt></pre>
</div></div>
<p>Any number of informational responses may be sent, but only until the final response is sent.</p>
<h3 id="response_command">response</h3>
<p>Send a response to the client.</p>
<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>{<font color="#FF6600">response</font>, <b><font color="#000000">cowboy:http_status</font></b>(), <b><font color="#000000">cowboy:http_headers</font></b>(),
    <b><font color="#000000">cowboy_req:resp_body</font></b>()}</tt></pre>
</div></div>
<p>No more data can be sent after this command.</p>
<h3 id="headers_command">headers</h3>
<p>Initiate a response to the client.</p>
<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>{<font color="#FF6600">headers</font>, <b><font color="#000000">cowboy:http_status</font></b>(), <b><font color="#000000">cowboy:http_headers</font></b>()}</tt></pre>
</div></div>
<p>This initiates a response to the client. The stream will end when a data command with the <code>fin</code> flag or a trailer command is returned.</p>
<h3 id="data_command">data</h3>
<p>Send data to the client.</p>
<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>{<font color="#FF6600">data</font>, <b><font color="#000000">fin</font></b>(), <b><font color="#000000">iodata</font></b>()}</tt></pre>
</div></div>
<h3 id="trailers_command">trailers</h3>
<p>Send response trailers to the client.</p>
<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>{<font color="#FF6600">trailers</font>, <b><font color="#000000">cowboy:http_headers</font></b>()}</tt></pre>
</div></div>
<h3 id="push_command">push</h3>
<p>Push a resource to the client.</p>
<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>{<font color="#FF6600">push</font>, <font color="#009900">Method</font>, <font color="#009900">Scheme</font>, <font color="#009900">Host</font>, <b><font color="#000000">inet:port_number</font></b>(),
    <font color="#009900">Path</font>, <font color="#009900">Qs</font>, <b><font color="#000000">cowboy:http_headers</font></b>()}

<font color="#009900">Method</font> <font color="#990000">=</font> <font color="#009900">Scheme</font> <font color="#990000">=</font> <font color="#009900">Host</font> <font color="#990000">=</font> <font color="#009900">Path</font> <font color="#990000">=</font> <font color="#009900">Qs</font> <font color="#990000">=</font> <b><font color="#000080">binary</font></b>()</tt></pre>
</div></div>
<p>The command will be ignored if the protocol does not provide any server push mechanism.</p>
<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>{<font color="#FF6600">flow</font>, <b><font color="#000000">pos_integer</font></b>()}</tt></pre>
</div></div>
<p>Request more data to be read from the request body. The exact behavior depends on the protocol.</p>
<h3 id="_spawn">spawn</h3>
<p>Inform Cowboy that a process was spawned and should be supervised.</p>
<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>{<b><font color="#000080">spawn</font></b>, <b><font color="#000080">pid</font></b>(), <b><font color="#000000">timeout</font></b>()}</tt></pre>
</div></div>
<h3 id="_error_response">error_response</h3>
<p>Send an error response if no response was sent previously.</p>
<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>{<font color="#FF6600">error_response</font>, <b><font color="#000000">cowboy:http_status</font></b>(), <b><font color="#000000">cowboy:http_headers</font></b>(), <b><font color="#000000">iodata</font></b>()}</tt></pre>
</div></div>
<h3 id="switch_protocol_command">switch_protocol</h3>
<p>Switch to a different protocol.</p>
<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>{<font color="#FF6600">switch_protocol</font>, <b><font color="#000000">cowboy:http_headers</font></b>(), <b><font color="#000000">module</font></b>(), <b><font color="#000000">state</font></b>()}</tt></pre>
</div></div>
<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>
<h3 id="_stop">stop</h3>
<p>Stop the stream.</p>
<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><font color="#FF6600">stop</font></tt></pre>
</div></div>
<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>
<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>
<p>To indicate that an error occurred, either use <code>error_response</code> before stopping, or use <code>internal_error</code>.</p>
<h3 id="_internal_error">internal_error</h3>
<p>Stop the stream with an error.</p>
<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>{<font color="#FF6600">internal_error</font>, <font color="#009900">Reason</font>, <font color="#009900">HumanReadable</font>}

<font color="#009900">Reason</font>        <font color="#990000">=</font> <b><font color="#000000">any</font></b>()
<font color="#009900">HumanReadable</font> <font color="#990000">=</font> <b><font color="#000080">atom</font></b>()</tt></pre>
</div></div>
<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>
<h2 id="_predefined_events">Predefined events</h2>
<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>
<p>Cowboy will also forward the exit signals for the processes that the stream spawned.</p>
<h3 id="_exit">EXIT</h3>
<!-- info(_StreamID, {&apos;EXIT&apos;, Pid, normal}, State=#state{pid=Pid}) -&gt;-->
<!-- info(_StreamID, {&apos;EXIT&apos;, Pid, {_Reason, [_, {cow_http_hd, _, _, _}|_]}}, State=#state{pid=Pid}) -&gt;-->
<!-- info(StreamID, Exit = {&apos;EXIT&apos;, Pid, {Reason, Stacktrace}}, State=#state{ref=Ref, pid=Pid}) -&gt;-->
<p>A process spawned by this stream has exited.</p>
<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>{<font color="#000080">'EXIT'</font>, <b><font color="#000080">pid</font></b>(), <b><font color="#000000">any</font></b>()}</tt></pre>
</div></div>
<p>This is the raw exit message without any modification.</p>
<!-- === read_body-->
<!-- -->
<!-- //info(_StreamID, {read_body, Ref, Length, _},-->
<!-- //info(StreamID, {read_body, Ref, Length, Period}, State) -&gt;-->
<!-- -->
<!-- TODO yeah I am not actually sure this one should be public just yet-->
<!-- TODO if it is, then we probably shouldn&apos;t send a message directly,-->
<!-- TODO but rather return a command that will end up sending the message-->
<!-- -->
<!-- TODO The problem being that no stream handler has access to that-->
<!-- TODO message if we send it directly. So we should have a command-->
<!-- TODO send_message or something that can be seen from all handlers.-->
<!-- -->
<!-- TODO The thing is that stream handlers can have 0 to N processes-->
<!-- TODO so we have to make it easy to say which process should-->
<!-- TODO receive the message, and perhaps *identify* which process-->
<!-- TODO gets it?-->
<h3 id="_inform">inform</h3>
<p>Same as the <a href="../inform_command">inform command</a>.</p>
<p>Sent when the request process reads the body and an expect: 100-continue header was present in the request, or when the request process sends an informational response on its own.</p>
<h3 id="_response">response</h3>
<p>Same as the <a href="../response_command">response command</a>.</p>
<p>Usually sent when the request process replies to the client. May also be sent by Cowboy internally.</p>
<h3 id="_headers">headers</h3>
<p>Same as the <a href="../headers_command">headers command</a>.</p>
<p>Sent when the request process starts replying to the client.</p>
<h3 id="_data">data</h3>
<p>Same as the <a href="../data_command">data command</a>.</p>
<p>Sent when the request process streams data to the client.</p>
<h3 id="_trailers">trailers</h3>
<p>Same as the <a href="../trailers_command">trailers command</a>.</p>
<p>Sent when the request process sends the trailer field values to the client.</p>
<h3 id="_push">push</h3>
<p>Same as the <a href="../push_command">push command</a>.</p>
<p>Sent when the request process pushes a resource to the client.</p>
<h3 id="_switch_protocol">switch_protocol</h3>
<p>Same as the <a href="../switch_protocol_command">switch_protocol command</a>.</p>
<!-- @todo Not done for HTTP/2 yet.-->
<p>Sent when switching to the HTTP/2 or Websocket protocol.</p>
<h2 id="_exports">Exports</h2>
<p>The following function should be called by modules implementing stream handlers to execute the next stream handler in the list:</p>
<ul><li><a href="../cowboy_stream.init">cowboy_stream:init(3)</a> - Initialize a stream
</li>
<li><a href="../cowboy_stream.data">cowboy_stream:data(3)</a> - Handle data for a stream
</li>
<li><a href="../cowboy_stream.info">cowboy_stream:info(3)</a> - Handle a message for a stream
</li>
<li><a href="../cowboy_stream.terminate">cowboy_stream:terminate(3)</a> - Terminate a stream
</li>
<li><a href="../cowboy_stream.early_error">cowboy_stream:early_error(3)</a> - Handle an early error for a stream
</li>
</ul>
<h2 id="_types">Types</h2>
<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><b><font color="#000000">commands</font></b>() <font color="#990000">::</font> [<font color="#009900">Command</font>]</tt></pre>
</div></div>
<p>See the <a href="../commands">list of commands</a> for details.</p>
<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><b><font color="#000000">fin</font></b>() <font color="#990000">::</font> <font color="#FF6600">fin</font> | <font color="#FF6600">nofin</font></tt></pre>
</div></div>
<p>Used in commands and events to indicate that this is the end of the stream.</p>
<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><b><font color="#000000">req</font></b>() <font color="#990000">::</font> #{
    <font color="#0000FF">method</font>  <font color="#990000">=&gt;</font> <b><font color="#000080">binary</font></b>(),               <i><font color="#9A1900">%% case sensitive</font></i>
    <font color="#0000FF">version</font> <font color="#990000">=&gt;</font> <b><font color="#000000">cowboy:http_version</font></b>() | <b><font color="#000080">atom</font></b>(),
    <font color="#0000FF">scheme</font>  <font color="#990000">=&gt;</font> <b><font color="#000080">binary</font></b>(),               <i><font color="#9A1900">%% lowercase; case insensitive</font></i>
    <font color="#0000FF">host</font>    <font color="#990000">=&gt;</font> <b><font color="#000080">binary</font></b>(),               <i><font color="#9A1900">%% lowercase; case insensitive</font></i>
    <font color="#0000FF">port</font>    <font color="#990000">=&gt;</font> <b><font color="#000000">inet:port_number</font></b>(),
    <font color="#0000FF">path</font>    <font color="#990000">=&gt;</font> <b><font color="#000080">binary</font></b>(),               <i><font color="#9A1900">%% case sensitive</font></i>
    <font color="#0000FF">qs</font>      <font color="#990000">=&gt;</font> <b><font color="#000080">binary</font></b>(),               <i><font color="#9A1900">%% case sensitive</font></i>
    <font color="#0000FF">headers</font> <font color="#990000">=&gt;</font> <b><font color="#000000">cowboy:http_headers</font></b>(),
    <font color="#0000FF">peer</font>    <font color="#990000">=&gt;</font> {<b><font color="#000000">inet:ip_address</font></b>(), <b><font color="#000000">inet:port_number</font></b>()}
}</tt></pre>
</div></div>
<p>Partial request information received when an early error is detected.</p>
<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><b><font color="#000000">reason</font></b>() <font color="#990000">::</font> <b><font color="#000080">normal</font></b> | <font color="#FF6600">switch_protocol</font>
    | {<font color="#FF6600">internal_error</font>, <font color="#FF6600">timeout</font> | {<font color="#FF6600">error</font> | <b><font color="#000080">exit</font></b> | <b><font color="#000080">throw</font></b>, <b><font color="#000000">any</font></b>()}, <font color="#009900">HumanReadable</font>}
    | {<font color="#FF6600">socket_error</font>, <font color="#FF6600">closed</font> | <b><font color="#000080">atom</font></b>(), <font color="#009900">HumanReadable</font>}
    | {<font color="#FF6600">stream_error</font>, <font color="#009900">Error</font>, <font color="#009900">HumanReadable</font>}
    | {<font color="#FF6600">connection_error</font>, <font color="#009900">Error</font>, <font color="#009900">HumanReadable</font>}
    | {<font color="#FF6600">stop</font>, <b><font color="#000000">cow_http2:frame</font></b>(), <font color="#009900">HumanReadable</font>}

<font color="#009900">Error</font>         <font color="#990000">=</font> <b><font color="#000080">atom</font></b>()
<font color="#009900">HumanReadable</font> <font color="#990000">=</font> <b><font color="#000080">atom</font></b>()</tt></pre>
</div></div>
<p>Reason for the stream termination.</p>
<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><b><font color="#000000">resp_command</font></b>() <font color="#990000">::</font> {<font color="#FF6600">response</font>, <b><font color="#000000">cowboy:http_status</font></b>(),
    <b><font color="#000000">cowboy:http_headers</font></b>(), <b><font color="#000000">cowboy_req:resp_body</font></b>()}</tt></pre>
</div></div>
<p>See the <a href="../response_command">response command</a> for details.</p>
<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><b><font color="#000000">streamid</font></b>() <font color="#990000">::</font> <b><font color="#000000">any</font></b>()</tt></pre>
</div></div>
<p>The identifier for this stream.</p>
<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>
<h2 id="_changelog">Changelog</h2>
<ul><li><strong>2.2</strong>: The trailers command was introduced.
</li>
<li><strong>2.0</strong>: Module introduced.
</li>
</ul>
<h2 id="_see_also">See also</h2>
<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 class="span3 sidecol">


<h3>
	Cowboy
	2.3
	Function Reference
	
</h3>

<ul>
	
		<li><a href="/docs/en/cowboy/2.3/guide">User Guide</a></li>
	
	
		<li><a href="/docs/en/cowboy/2.3/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 &copy; Loïc Hoguin 2012-2018</p>
            </div>
          </div>
        </div>
      </footer>

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