<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: Rev::HttpClient</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">Rev::HttpClient</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../files/lib/rev/http_client_rb.html">
                lib/rev/http_client.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                <a href="TCPSocket.html">
                TCPSocket
               </a>
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
HTTP client class implemented as a subclass of <a
href="TCPSocket.html">Rev::TCPSocket</a>. Encodes requests and allows
streaming consumption of the response. Response is parsed with a
Ragel-generated whitelist parser which supports chunked HTTP encoding.
</p>
<h2>Example</h2>
<pre>
  loop = Rev::Loop.default
  client = Rev::HttpClient.connect(&quot;www.google.com&quot;).attach
  client.get('/search', query: {q: 'foobar'})
  loop.run
</pre>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000042">connect</a>&nbsp;&nbsp;
      <a href="#M000055">dispatch</a>&nbsp;&nbsp;
      <a href="#M000045">method_missing</a>&nbsp;&nbsp;
      <a href="#M000043">new</a>&nbsp;&nbsp;
      <a href="#M000047">on_body_data</a>&nbsp;&nbsp;
      <a href="#M000050">on_connect</a>&nbsp;&nbsp;
      <a href="#M000049">on_error</a>&nbsp;&nbsp;
      <a href="#M000051">on_read</a>&nbsp;&nbsp;
      <a href="#M000048">on_request_complete</a>&nbsp;&nbsp;
      <a href="#M000046">on_response_header</a>&nbsp;&nbsp;
      <a href="#M000044">request</a>&nbsp;&nbsp;
      <a href="#M000052">send_request</a>&nbsp;&nbsp;
      <a href="#M000054">send_request_body</a>&nbsp;&nbsp;
      <a href="#M000053">send_request_header</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->
    <div id="includes">
      <h3 class="section-bar">Included Modules</h3>

      <div id="includes-list">
        <span class="include-name"><a href="HttpEncoding.html">HttpEncoding</a></span>
      </div>
    </div>

    <div id="section">


    <div id="constants-list">
      <h3 class="section-bar">Constants</h3>

      <div class="name-list">
        <table summary="Constants">
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">ALLOWED_METHODS</td>
          <td>=</td>
          <td class="context-item-value">[:put, :get, :post, :delete, :head]</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">TRANSFER_ENCODING</td>
          <td>=</td>
          <td class="context-item-value">&quot;TRANSFER_ENCODING&quot;</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">CONTENT_LENGTH</td>
          <td>=</td>
          <td class="context-item-value">&quot;CONTENT_LENGTH&quot;</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">SET_COOKIE</td>
          <td>=</td>
          <td class="context-item-value">&quot;SET_COOKIE&quot;</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">LOCATION</td>
          <td>=</td>
          <td class="context-item-value">&quot;LOCATION&quot;</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">HOST</td>
          <td>=</td>
          <td class="context-item-value">&quot;HOST&quot;</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">CRLF</td>
          <td>=</td>
          <td class="context-item-value">&quot;\r\n&quot;</td>
        </tr>
        </table>
      </div>
    </div>



      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000042" class="method-detail">
        <a name="M000042"></a>

        <div class="method-heading">
          <a href="HttpClient.src/M000042.html" target="Code" class="method-signature"
            onclick="popupCode('HttpClient.src/M000042.html');return false;">
          <span class="method-name">connect</span><span class="method-args">(addr, port = 80, *args)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Connect to the given server, with port 80 as the default
</p>
        </div>
      </div>

      <div id="method-M000043" class="method-detail">
        <a name="M000043"></a>

        <div class="method-heading">
          <a href="HttpClient.src/M000043.html" target="Code" class="method-signature"
            onclick="popupCode('HttpClient.src/M000043.html');return false;">
          <span class="method-name">new</span><span class="method-args">(socket)</span>
          </a>
        </div>
      
        <div class="method-description">
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000045" class="method-detail">
        <a name="M000045"></a>

        <div class="method-heading">
          <a href="HttpClient.src/M000045.html" target="Code" class="method-signature"
            onclick="popupCode('HttpClient.src/M000045.html');return false;">
          <span class="method-name">method_missing</span><span class="method-args">(method, *args)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Requests can be made through method missing by invoking the HTTP method to
use, i.e.:
</p>
<pre>
  httpclient.get(path, options)
</pre>
<p>
Valid for: get, post, put, delete, head
</p>
<p>
To use other HTTP methods, invoke the <a
href="HttpClient.html#M000044">request</a> method directly
</p>
        </div>
      </div>

      <div id="method-M000047" class="method-detail">
        <a name="M000047"></a>

        <div class="method-heading">
          <a href="HttpClient.src/M000047.html" target="Code" class="method-signature"
            onclick="popupCode('HttpClient.src/M000047.html');return false;">
          <span class="method-name">on_body_data</span><span class="method-args">(data)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Called when part of the body has been read
</p>
        </div>
      </div>

      <div id="method-M000049" class="method-detail">
        <a name="M000049"></a>

        <div class="method-heading">
          <a href="HttpClient.src/M000049.html" target="Code" class="method-signature"
            onclick="popupCode('HttpClient.src/M000049.html');return false;">
          <span class="method-name">on_error</span><span class="method-args">(reason)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Called when an error occurs during the <a
href="HttpClient.html#M000044">request</a>
</p>
        </div>
      </div>

      <div id="method-M000048" class="method-detail">
        <a name="M000048"></a>

        <div class="method-heading">
          <a href="HttpClient.src/M000048.html" target="Code" class="method-signature"
            onclick="popupCode('HttpClient.src/M000048.html');return false;">
          <span class="method-name">on_request_complete</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Called when the <a href="HttpClient.html#M000044">request</a> has completed
</p>
        </div>
      </div>

      <div id="method-M000046" class="method-detail">
        <a name="M000046"></a>

        <div class="method-heading">
          <a href="HttpClient.src/M000046.html" target="Code" class="method-signature"
            onclick="popupCode('HttpClient.src/M000046.html');return false;">
          <span class="method-name">on_response_header</span><span class="method-args">(response_header)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Called when response header has been received
</p>
        </div>
      </div>

      <div id="method-M000044" class="method-detail">
        <a name="M000044"></a>

        <div class="method-heading">
          <a href="HttpClient.src/M000044.html" target="Code" class="method-signature"
            onclick="popupCode('HttpClient.src/M000044.html');return false;">
          <span class="method-name">request</span><span class="method-args">(method, uri, options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Send an HTTP <a href="HttpClient.html#M000044">request</a> and consume the
response. Supports the following options:
</p>
<pre>
  head: {Key: Value}
    Specify an HTTP header, e.g. {'Connection': 'close'}

  query: {Key: Value}
    Specify query string parameters (auto-escaped)

  cookies: {Key: Value}
    Specify hash of cookies (auto-escaped)

  body: String
    Specify the request body (you must encode it for now)
</pre>
        </div>
      </div>

      <h3 class="section-bar">Protected Instance methods</h3>

      <div id="method-M000055" class="method-detail">
        <a name="M000055"></a>

        <div class="method-heading">
          <a href="HttpClient.src/M000055.html" target="Code" class="method-signature"
            onclick="popupCode('HttpClient.src/M000055.html');return false;">
          <span class="method-name">dispatch</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Response processing
</p>
        </div>
      </div>

      <div id="method-M000050" class="method-detail">
        <a name="M000050"></a>

        <div class="method-heading">
          <a href="HttpClient.src/M000050.html" target="Code" class="method-signature"
            onclick="popupCode('HttpClient.src/M000050.html');return false;">
          <span class="method-name">on_connect</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
<a href="../Rev.html">Rev</a> callbacks
</p>
        </div>
      </div>

      <div id="method-M000051" class="method-detail">
        <a name="M000051"></a>

        <div class="method-heading">
          <a href="HttpClient.src/M000051.html" target="Code" class="method-signature"
            onclick="popupCode('HttpClient.src/M000051.html');return false;">
          <span class="method-name">on_read</span><span class="method-args">(data)</span>
          </a>
        </div>
      
        <div class="method-description">
        </div>
      </div>

      <div id="method-M000052" class="method-detail">
        <a name="M000052"></a>

        <div class="method-heading">
          <a href="HttpClient.src/M000052.html" target="Code" class="method-signature"
            onclick="popupCode('HttpClient.src/M000052.html');return false;">
          <span class="method-name">send_request</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Request sending
</p>
        </div>
      </div>

      <div id="method-M000054" class="method-detail">
        <a name="M000054"></a>

        <div class="method-heading">
          <a href="HttpClient.src/M000054.html" target="Code" class="method-signature"
            onclick="popupCode('HttpClient.src/M000054.html');return false;">
          <span class="method-name">send_request_body</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
        </div>
      </div>

      <div id="method-M000053" class="method-detail">
        <a name="M000053"></a>

        <div class="method-heading">
          <a href="HttpClient.src/M000053.html" target="Code" class="method-signature"
            onclick="popupCode('HttpClient.src/M000053.html');return false;">
          <span class="method-name">send_request_header</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>