summaryrefslogblamecommitdiffstats
path: root/docs/en/cowboy/2.4/manual/cowboy_stream/index.html
blob: 8fac7f3451ad24261fb9cbbf44f124ae3f6059c5 (plain) (tree)
1
2
3
4
5
6
7
8
9








                                                                                           


                                                                                                                      
                                                   


















































                                                                                                                                                                                   
                        
                                       
                                      



                                                                                                                                                                                                                  
                                  

                                                                                         


                                            




                                                                                                                                                                                                                                                                                                               
 
















                                                                                                                                                                                                                                                                                                                                                                
                               






                                                                                                                                                                                                                                             
                                   

                                                                                         


                                            


                                                                                                                                                                              
                                       

                                                                                         


                                            



                                                                                                                                                                     
                                     

                                                                                         


                                            


                                                                                                                                                                               
                               

                                                                                         


                                            

                                                                                                                                                
                                       

                                                                                         


                                            

                                                                                                                      
                               

                                                                                         


                                            

                                                                                                                                                                                                                 
 


                                                                                                                                                                                                                                                                                                                                                                                              
                        
                                                                                         


                                            


                                                                                                          
                          

                                                                                         


                                            

                                                                                                                                                         
                                            

                                                                                         


                                            

                                                                                                                                                                                                                                    
                                                     

                                                                                         


                                            


                                                                                                                                                                                                                        
                        

                                                                                         


                                            




                                                                                                                                                                                       
                                            

                                                                                         


                                            
                                                                                                                                       
 



                                                                                                                                                                                                                     
                                                  

                                                                                                                                                                                                                                                                                                            
                        




                                                                                                                       


                                            



















                                                                                                                                               
                            

                                                                                                                                                                                          
                                

                                                                                                          
                              

                                                                    
                        

                                                                
                                

                                                                                  
                        

                                                                     
                                              

                                                                                    
                              

                                                                                                                                      
     
                                                                                        
     
                                                                                             
     
                                                                                            
     
                                                                                                                
     
     
                          
                                  
                                                                                         


                                            


                                                                                                                                         
                        
                                                                                         


                                            


                                                                                                                                                                   
                                        
                                                                                         


                                            












                                                                                                                                                                                                          
                              
                                                                                         


                                            





                                                                                                                                                                                                                                                                                                              
 



                                                                                                                               
                                          
                                                                                         


                                            



                                                                                                                                                                                             
                                  
                                                                                         


                                            



                                                                                                                                                                                             
                                  
                                                                  
     
                                            
     
     
                                

                                                                                                                             

































                                                                                    

                                                                     

                                                                     





                                                                     

     















                                                                                                                                                                                                                                     





























                                                                                                                                                                                                                           
<!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=6" 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>
<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.4
	Function Reference
	
</h3>

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

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

<h4>Version select</h4>
<ul>
	
	
	
		<li><a href="/docs/en/cowboy/2.6/manual">2.6</a></li>
	
		<li><a href="/docs/en/cowboy/2.5/manual">2.5</a></li>
	
		<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>
	
</ul>

<h3 id="_like_my_work__donate">Like my work? Donate!</h3>
<p>Donate to Loïc Hoguin because his work on Cowboy, Ranch, Gun and Erlang.mk is fantastic:</p>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" style="display:inline">
<input type="hidden" name="cmd" value="_donations">
<input type="hidden" name="business" value="[email protected]">
<input type="hidden" name="lc" value="FR">
<input type="hidden" name="item_name" value="Loic Hoguin">
<input type="hidden" name="item_number" value="99s">
<input type="hidden" name="currency_code" value="EUR">
<input type="hidden" name="bn" value="PP-DonationsBF:btn_donate_LG.gif:NonHosted">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/fr_FR/i/scr/pixel.gif" width="1" height="1">
</form><p>Recurring payment options are also available via <a href="https://salt.bountysource.com/teams/ninenines">BountySource</a>. These funds are used to cover the recurring expenses like dedicated servers or domain names.</p>



</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>