httpkit 0.6.0.pre.5 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +8 -8
  2. data/.gitignore +0 -2
  3. data/.travis.yml +1 -1
  4. data/Gemfile +2 -0
  5. data/README.md +32 -25
  6. data/Rakefile +5 -0
  7. data/config/flay.yml +1 -1
  8. data/doc/api/httpkit.html +50 -0
  9. data/doc/api/httpkit/body.html +149 -0
  10. data/doc/api/httpkit/client.html +50 -0
  11. data/doc/api/httpkit/client/body_handler.html +50 -0
  12. data/doc/api/httpkit/client/keep_alive_handler.html +79 -0
  13. data/doc/api/httpkit/client/mandatory_handler.html +50 -0
  14. data/doc/api/httpkit/client/timeouts_handler.html +82 -0
  15. data/doc/api/httpkit/connection/eventmachine.html +157 -0
  16. data/doc/api/httpkit/connection/status.html +50 -0
  17. data/doc/api/httpkit/promise.html +50 -0
  18. data/doc/api/httpkit/request.html +123 -0
  19. data/doc/api/httpkit/response.html +209 -0
  20. data/doc/api/httpkit/serializer.html +150 -0
  21. data/doc/api/httpkit/server.html +50 -0
  22. data/doc/api/httpkit/server/block_handler.html +50 -0
  23. data/doc/api/httpkit/server/body_handler.html +50 -0
  24. data/doc/api/httpkit/server/keep_alive_handler.html +145 -0
  25. data/doc/api/httpkit/server/mandatory_handler.html +50 -0
  26. data/doc/api/httpkit/server/timeouts_handler.html +81 -0
  27. data/doc/api/httpkit/support/handler_manager.html +95 -0
  28. data/doc/api/httpkit/support/message.html +50 -0
  29. data/doc/api/httpkit/version.html +50 -0
  30. data/doc/examples/echo_server.html +101 -0
  31. data/doc/examples/error_handling.html +176 -0
  32. data/doc/examples/getting_started.html +161 -0
  33. data/doc/examples/streaming.html +108 -0
  34. data/doc/index.html +165 -0
  35. data/examples/echo_server.rb +14 -6
  36. data/examples/error_handling.rb +56 -0
  37. data/examples/getting_started.rb +10 -18
  38. data/examples/streaming.rb +41 -0
  39. data/lib/httpkit.rb +22 -0
  40. data/lib/httpkit/body.rb +4 -0
  41. data/lib/httpkit/client.rb +1 -9
  42. data/lib/httpkit/client/keep_alive_handler.rb +1 -0
  43. data/lib/httpkit/connection/eventmachine.rb +2 -1
  44. data/lib/httpkit/server/block_handler.rb +13 -0
  45. data/lib/httpkit/server/keep_alive_handler.rb +1 -0
  46. data/lib/httpkit/version.rb +1 -1
  47. data/spec/integration/timeouts_spec.rb +3 -2
  48. data/spec/support/helper.rb +1 -8
  49. data/spec/unit/client_spec.rb +2 -21
  50. data/spec/unit/server_spec.rb +11 -1
  51. metadata +34 -5
  52. data/Procfile +0 -1
@@ -0,0 +1,50 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
5
+ <title>message.rb</title>
6
+ <link rel="stylesheet" href="http://jashkenas.github.io/docco/resources/linear/docco.css">
7
+ </head>
8
+ <body>
9
+ <div id='container'>
10
+ <div id="background"></div>
11
+ <div id="jump_to">
12
+ Jump To &hellip;
13
+ <div id="jump_wrapper">
14
+ <div id="jump_page">
15
+ <a class="source" href="../../httpkit.html">httpkit.rb</a>
16
+ <a class="source" href="../body.html">body.rb</a>
17
+ <a class="source" href="../client.html">client.rb</a>
18
+ <a class="source" href="../client/body_handler.html">body_handler.rb</a>
19
+ <a class="source" href="../client/keep_alive_handler.html">keep_alive_handler.rb</a>
20
+ <a class="source" href="../client/mandatory_handler.html">mandatory_handler.rb</a>
21
+ <a class="source" href="../client/timeouts_handler.html">timeouts_handler.rb</a>
22
+ <a class="source" href="../connection/eventmachine.html">eventmachine.rb</a>
23
+ <a class="source" href="../connection/status.html">status.rb</a>
24
+ <a class="source" href="../promise.html">promise.rb</a>
25
+ <a class="source" href="../request.html">request.rb</a>
26
+ <a class="source" href="../response.html">response.rb</a>
27
+ <a class="source" href="../serializer.html">serializer.rb</a>
28
+ <a class="source" href="../server.html">server.rb</a>
29
+ <a class="source" href="../server/block_handler.html">block_handler.rb</a>
30
+ <a class="source" href="../server/body_handler.html">body_handler.rb</a>
31
+ <a class="source" href="../server/keep_alive_handler.html">keep_alive_handler.rb</a>
32
+ <a class="source" href="../server/mandatory_handler.html">mandatory_handler.rb</a>
33
+ <a class="source" href="../server/timeouts_handler.html">timeouts_handler.rb</a>
34
+ <a class="source" href="handler_manager.html">handler_manager.rb</a>
35
+ <a class="source" href="message.html">message.rb</a>
36
+ <a class="source" href="../version.html">version.rb</a>
37
+ </div>
38
+ </div>
39
+ </div>
40
+ <table cellspacing=0 cellpadding=0>
41
+ <thead>
42
+ <tr>
43
+ <th class=docs><h1>message.rb</h1></th>
44
+ <th class=code></th>
45
+ </tr>
46
+ </thead>
47
+ <tbody>
48
+ </table>
49
+ </div>
50
+ </body>
@@ -0,0 +1,50 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
5
+ <title>version.rb</title>
6
+ <link rel="stylesheet" href="http://jashkenas.github.io/docco/resources/linear/docco.css">
7
+ </head>
8
+ <body>
9
+ <div id='container'>
10
+ <div id="background"></div>
11
+ <div id="jump_to">
12
+ Jump To &hellip;
13
+ <div id="jump_wrapper">
14
+ <div id="jump_page">
15
+ <a class="source" href="../httpkit.html">httpkit.rb</a>
16
+ <a class="source" href="body.html">body.rb</a>
17
+ <a class="source" href="client.html">client.rb</a>
18
+ <a class="source" href="client/body_handler.html">body_handler.rb</a>
19
+ <a class="source" href="client/keep_alive_handler.html">keep_alive_handler.rb</a>
20
+ <a class="source" href="client/mandatory_handler.html">mandatory_handler.rb</a>
21
+ <a class="source" href="client/timeouts_handler.html">timeouts_handler.rb</a>
22
+ <a class="source" href="connection/eventmachine.html">eventmachine.rb</a>
23
+ <a class="source" href="connection/status.html">status.rb</a>
24
+ <a class="source" href="promise.html">promise.rb</a>
25
+ <a class="source" href="request.html">request.rb</a>
26
+ <a class="source" href="response.html">response.rb</a>
27
+ <a class="source" href="serializer.html">serializer.rb</a>
28
+ <a class="source" href="server.html">server.rb</a>
29
+ <a class="source" href="server/block_handler.html">block_handler.rb</a>
30
+ <a class="source" href="server/body_handler.html">body_handler.rb</a>
31
+ <a class="source" href="server/keep_alive_handler.html">keep_alive_handler.rb</a>
32
+ <a class="source" href="server/mandatory_handler.html">mandatory_handler.rb</a>
33
+ <a class="source" href="server/timeouts_handler.html">timeouts_handler.rb</a>
34
+ <a class="source" href="support/handler_manager.html">handler_manager.rb</a>
35
+ <a class="source" href="support/message.html">message.rb</a>
36
+ <a class="source" href="version.html">version.rb</a>
37
+ </div>
38
+ </div>
39
+ </div>
40
+ <table cellspacing=0 cellpadding=0>
41
+ <thead>
42
+ <tr>
43
+ <th class=docs><h1>version.rb</h1></th>
44
+ <th class=code></th>
45
+ </tr>
46
+ </thead>
47
+ <tbody>
48
+ </table>
49
+ </div>
50
+ </body>
@@ -0,0 +1,101 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
5
+ <title>echo_server.rb</title>
6
+ <link rel="stylesheet" href="http://jashkenas.github.io/docco/resources/linear/docco.css">
7
+ </head>
8
+ <body>
9
+ <div id='container'>
10
+ <div id="background"></div>
11
+ <div id="jump_to">
12
+ Jump To &hellip;
13
+ <div id="jump_wrapper">
14
+ <div id="jump_page">
15
+ <a class="source" href="echo_server.html">echo_server.rb</a>
16
+ <a class="source" href="error_handling.html">error_handling.rb</a>
17
+ <a class="source" href="getting_started.html">getting_started.rb</a>
18
+ <a class="source" href="streaming.html">streaming.rb</a>
19
+ </div>
20
+ </div>
21
+ </div>
22
+ <table cellspacing=0 cellpadding=0>
23
+ <thead>
24
+ <tr>
25
+ <th class=docs><h1>echo_server.rb</h1></th>
26
+ <th class=code></th>
27
+ </tr>
28
+ </thead>
29
+ <tbody>
30
+ <tr id='section-1'>
31
+ <td class=docs>
32
+ <div class="pilwrap">
33
+ <a class="pilcrow" href="#section-1">&#182;</a>
34
+ </div>
35
+
36
+ </td>
37
+ <td class=code>
38
+ <div class='highlight'><pre><span class="nb">require</span> <span class="s1">&#39;httpkit&#39;</span>
39
+
40
+ <span class="k">class</span> <span class="nc">EchoServer</span>
41
+ <span class="k">def</span> <span class="nf">serve</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">served</span><span class="p">)</span>
42
+ <span class="n">response</span> <span class="o">=</span> <span class="n">streaming_response</span></pre></div>
43
+ </td>
44
+ </tr>
45
+ <tr id='section-2'>
46
+ <td class=docs>
47
+ <div class="pilwrap">
48
+ <a class="pilcrow" href="#section-2">&#182;</a>
49
+ </div>
50
+ <p>We start sending the response even we started writing its body. This is
51
+ not mandatory, but it delivers the response to client as quickly as
52
+ possible.</p>
53
+ </td>
54
+ <td class=code>
55
+ <div class='highlight'><pre> <span class="n">served</span><span class="o">.</span><span class="n">fulfill</span><span class="p">(</span><span class="n">response</span><span class="p">)</span>
56
+
57
+ <span class="n">serialize</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">response</span><span class="p">)</span>
58
+ <span class="n">request</span><span class="o">.</span><span class="n">closed</span> <span class="p">{</span> <span class="n">response</span><span class="o">.</span><span class="n">close</span> <span class="p">}</span>
59
+ <span class="k">end</span>
60
+
61
+ <span class="kp">private</span>
62
+
63
+ <span class="k">def</span> <span class="nf">streaming_response</span>
64
+ <span class="ss">HTTPkit</span><span class="p">:</span><span class="ss">:Response</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="mi">200</span><span class="p">,</span>
65
+ <span class="p">{</span> <span class="s1">&#39;Content-Type&#39;</span> <span class="o">=&gt;</span> <span class="s1">&#39;application/octet-stream&#39;</span> <span class="p">},</span>
66
+ <span class="ss">HTTPkit</span><span class="p">:</span><span class="ss">:Body</span><span class="o">.</span><span class="n">new</span><span class="p">)</span>
67
+ <span class="k">end</span></pre></div>
68
+ </td>
69
+ </tr>
70
+ <tr id='section-3'>
71
+ <td class=docs>
72
+ <div class="pilwrap">
73
+ <a class="pilcrow" href="#section-3">&#182;</a>
74
+ </div>
75
+ <p>This re-serializes the whole request directly into the response body.</p>
76
+
77
+ </td>
78
+ <td class=code>
79
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">serialize</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">response</span><span class="p">)</span>
80
+ <span class="n">writer</span> <span class="o">=</span> <span class="n">response</span><span class="o">.</span><span class="n">body</span><span class="o">.</span><span class="n">method</span><span class="p">(</span><span class="ss">:write</span><span class="p">)</span>
81
+ <span class="n">serializer</span> <span class="o">=</span> <span class="ss">HTTPkit</span><span class="p">:</span><span class="ss">:Serializer</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">writer</span><span class="p">)</span>
82
+ <span class="n">serializer</span><span class="o">.</span><span class="n">serialize</span>
83
+ <span class="k">end</span>
84
+ <span class="k">end</span>
85
+
86
+ <span class="no">HTTPkit</span><span class="o">.</span><span class="n">run</span> <span class="k">do</span>
87
+ <span class="n">address</span> <span class="o">=</span> <span class="s1">&#39;127.0.0.1&#39;</span>
88
+ <span class="n">port</span> <span class="o">=</span> <span class="no">HTTPkit</span><span class="o">.</span><span class="n">random_port</span><span class="p">(</span><span class="n">address</span><span class="p">)</span>
89
+
90
+ <span class="ss">HTTPkit</span><span class="p">:</span><span class="ss">:Server</span><span class="o">.</span><span class="n">start</span><span class="p">(</span><span class="ss">address</span><span class="p">:</span> <span class="n">address</span><span class="p">,</span> <span class="ss">port</span><span class="p">:</span> <span class="n">port</span><span class="p">,</span>
91
+ <span class="ss">handlers</span><span class="p">:</span> <span class="o">[</span><span class="ss">HTTPkit</span><span class="p">:</span><span class="ss">:Server</span><span class="o">::</span><span class="no">KeepAliveHandler</span><span class="o">.</span><span class="n">new</span><span class="p">,</span>
92
+ <span class="no">EchoServer</span><span class="o">.</span><span class="n">new</span><span class="o">]</span><span class="p">)</span>
93
+
94
+ <span class="n">body</span> <span class="o">=</span> <span class="no">HTTPkit</span><span class="o">.</span><span class="n">request</span><span class="p">(</span><span class="ss">:get</span><span class="p">,</span> <span class="s2">&quot;http://</span><span class="si">#{</span><span class="n">address</span><span class="si">}</span><span class="s2">:</span><span class="si">#{</span><span class="n">port</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span><span class="o">.</span><span class="n">body</span>
95
+ <span class="n">body</span><span class="o">.</span><span class="n">to_s</span><span class="o">.</span><span class="n">each_line</span> <span class="p">{</span> <span class="o">|</span><span class="n">line</span><span class="o">|</span> <span class="nb">p</span> <span class="n">line</span> <span class="p">}</span>
96
+ <span class="k">end</span></pre></div>
97
+ </td>
98
+ </tr>
99
+ </table>
100
+ </div>
101
+ </body>
@@ -0,0 +1,176 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
5
+ <title>error_handling.rb</title>
6
+ <link rel="stylesheet" href="http://jashkenas.github.io/docco/resources/linear/docco.css">
7
+ </head>
8
+ <body>
9
+ <div id='container'>
10
+ <div id="background"></div>
11
+ <div id="jump_to">
12
+ Jump To &hellip;
13
+ <div id="jump_wrapper">
14
+ <div id="jump_page">
15
+ <a class="source" href="echo_server.html">echo_server.rb</a>
16
+ <a class="source" href="error_handling.html">error_handling.rb</a>
17
+ <a class="source" href="getting_started.html">getting_started.rb</a>
18
+ <a class="source" href="streaming.html">streaming.rb</a>
19
+ </div>
20
+ </div>
21
+ </div>
22
+ <table cellspacing=0 cellpadding=0>
23
+ <thead>
24
+ <tr>
25
+ <th class=docs><h1>error_handling.rb</h1></th>
26
+ <th class=code></th>
27
+ </tr>
28
+ </thead>
29
+ <tbody>
30
+ <tr id='section-1'>
31
+ <td class=docs>
32
+ <div class="pilwrap">
33
+ <a class="pilcrow" href="#section-1">&#182;</a>
34
+ </div>
35
+
36
+ </td>
37
+ <td class=code>
38
+ <div class='highlight'><pre><span class="nb">require</span> <span class="s1">&#39;httpkit&#39;</span>
39
+
40
+ <span class="k">class</span> <span class="nc">Failwhale</span></pre></div>
41
+ </td>
42
+ </tr>
43
+ <tr id='section-2'>
44
+ <td class=docs>
45
+ <div class="pilwrap">
46
+ <a class="pilcrow" href="#section-2">&#182;</a>
47
+ </div>
48
+ <p>TODO: Rejecting the served promise on the server side currently has no
49
+ effect, except for the response simply not being sent. This has the
50
+ potential of mixing up responses, so we should instead just send
51
+ a 500 response for every rejected served promise. The same should
52
+ happen for errors raised from handlers' #serve.</p>
53
+ </td>
54
+ <td class=code>
55
+ <div class='highlight'><pre> <span class="k">def</span> <span class="nf">serve</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="n">served</span><span class="p">)</span>
56
+ <span class="k">raise</span> <span class="k">if</span> <span class="n">request</span><span class="o">.</span><span class="n">uri</span> <span class="o">==</span> <span class="s1">&#39;/raise&#39;</span>
57
+
58
+ <span class="n">served</span><span class="o">.</span><span class="n">fulfill</span><span class="p">(</span><span class="ss">HTTPkit</span><span class="p">:</span><span class="ss">:Response</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="mi">500</span><span class="p">))</span>
59
+ <span class="k">end</span>
60
+ <span class="k">end</span>
61
+
62
+ <span class="no">HTTPkit</span><span class="o">.</span><span class="n">run</span> <span class="k">do</span>
63
+ <span class="n">address</span> <span class="o">=</span> <span class="s1">&#39;127.0.0.1&#39;</span>
64
+ <span class="n">port</span> <span class="o">=</span> <span class="no">HTTPkit</span><span class="o">.</span><span class="n">random_port</span><span class="p">(</span><span class="n">address</span><span class="p">)</span>
65
+ <span class="n">uri</span> <span class="o">=</span> <span class="s2">&quot;http://</span><span class="si">#{</span><span class="n">address</span><span class="si">}</span><span class="s2">:</span><span class="si">#{</span><span class="n">port</span><span class="si">}</span><span class="s2">&quot;</span>
66
+
67
+ <span class="no">HTTPkit</span><span class="o">.</span><span class="n">server</span><span class="p">(</span><span class="n">uri</span><span class="p">)</span> <span class="k">do</span> <span class="o">|</span><span class="n">request</span><span class="p">,</span> <span class="n">served</span><span class="o">|</span>
68
+ <span class="k">raise</span> <span class="k">if</span> <span class="n">request</span><span class="o">.</span><span class="n">uri</span> <span class="o">==</span> <span class="s1">&#39;/raise&#39;</span>
69
+ <span class="n">served</span><span class="o">.</span><span class="n">fulfill</span><span class="p">(</span><span class="ss">HTTPkit</span><span class="p">:</span><span class="ss">:Response</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="mi">500</span><span class="p">))</span>
70
+ <span class="k">end</span></pre></div>
71
+ </td>
72
+ </tr>
73
+ <tr id='section-3'>
74
+ <td class=docs>
75
+ <div class="pilwrap">
76
+ <a class="pilcrow" href="#section-3">&#182;</a>
77
+ </div>
78
+ <p>5xx responses are just normal responses.</p>
79
+ </td>
80
+ <td class=code>
81
+ <div class='highlight'><pre> <span class="n">response</span> <span class="o">=</span> <span class="no">HTTPkit</span><span class="o">.</span><span class="n">request</span><span class="p">(</span><span class="ss">:get</span><span class="p">,</span> <span class="n">uri</span><span class="p">)</span>
82
+ <span class="nb">p</span> <span class="n">response</span><span class="o">.</span><span class="n">status</span></pre></div>
83
+ </td>
84
+ </tr>
85
+ <tr id='section-4'>
86
+ <td class=docs>
87
+ <div class="pilwrap">
88
+ <a class="pilcrow" href="#section-4">&#182;</a>
89
+ </div>
90
+ <p>=&gt; 500</p>
91
+ </td>
92
+ <td class=code>
93
+ <div class='highlight'><pre></pre></div>
94
+ </td>
95
+ </tr>
96
+ <tr id='section-5'>
97
+ <td class=docs>
98
+ <div class="pilwrap">
99
+ <a class="pilcrow" href="#section-5">&#182;</a>
100
+ </div>
101
+ <p>Let&rsquo;s crash the server and make it close the connection.</p>
102
+ </td>
103
+ <td class=code>
104
+ <div class='highlight'><pre> <span class="k">begin</span>
105
+ <span class="no">HTTPkit</span><span class="o">.</span><span class="n">request</span><span class="p">(</span><span class="ss">:get</span><span class="p">,</span> <span class="n">uri</span> <span class="o">+</span> <span class="s1">&#39;/raise&#39;</span><span class="p">)</span>
106
+ <span class="k">rescue</span> <span class="ss">Promise</span><span class="p">:</span><span class="ss">:Error</span> <span class="o">=&gt;</span> <span class="n">ex</span>
107
+ <span class="nb">puts</span> <span class="n">ex</span><span class="o">.</span><span class="n">backtrace</span></pre></div>
108
+ </td>
109
+ </tr>
110
+ <tr id='section-6'>
111
+ <td class=docs>
112
+ <div class="pilwrap">
113
+ <a class="pilcrow" href="#section-6">&#182;</a>
114
+ </div>
115
+ <p>Connection error. Below we see how to find out more.</p>
116
+ </td>
117
+ <td class=code>
118
+ <div class='highlight'><pre> <span class="k">end</span>
119
+
120
+ <span class="n">client</span> <span class="o">=</span> <span class="ss">HTTPkit</span><span class="p">:</span><span class="ss">:Client</span><span class="o">.</span><span class="n">start</span><span class="p">(</span><span class="ss">address</span><span class="p">:</span> <span class="n">address</span><span class="p">,</span> <span class="ss">port</span><span class="p">:</span> <span class="n">port</span><span class="p">)</span>
121
+ <span class="n">request</span> <span class="o">=</span> <span class="ss">HTTPkit</span><span class="p">:</span><span class="ss">:Request</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="ss">:get</span><span class="p">,</span> <span class="s1">&#39;/raise&#39;</span><span class="p">)</span>
122
+ <span class="n">served</span> <span class="o">=</span> <span class="n">client</span><span class="o">.</span><span class="n">perform</span><span class="p">(</span><span class="n">request</span><span class="p">)</span></pre></div>
123
+ </td>
124
+ </tr>
125
+ <tr id='section-7'>
126
+ <td class=docs>
127
+ <div class="pilwrap">
128
+ <a class="pilcrow" href="#section-7">&#182;</a>
129
+ </div>
130
+ <p>Instead of getting fulfilled with a response, we see that the served
131
+ promise gets rejected. Calling #sync on served would raise the rejection
132
+ reason, in this case Promise::Error.</p>
133
+ </td>
134
+ <td class=code>
135
+ <div class='highlight'><pre> <span class="n">served</span><span class="o">.</span><span class="n">wait</span>
136
+ <span class="nb">p</span> <span class="n">served</span><span class="o">.</span><span class="n">state</span></pre></div>
137
+ </td>
138
+ </tr>
139
+ <tr id='section-8'>
140
+ <td class=docs>
141
+ <div class="pilwrap">
142
+ <a class="pilcrow" href="#section-8">&#182;</a>
143
+ </div>
144
+ <p>=&gt; :rejected</p>
145
+ </td>
146
+ <td class=code>
147
+ <div class='highlight'><pre> <span class="nb">p</span> <span class="n">served</span><span class="o">.</span><span class="n">reason</span></pre></div>
148
+ </td>
149
+ </tr>
150
+ <tr id='section-9'>
151
+ <td class=docs>
152
+ <div class="pilwrap">
153
+ <a class="pilcrow" href="#section-9">&#182;</a>
154
+ </div>
155
+ <p>=&gt; Promise::Error if the connection was closed properly (in the TCP sense),
156
+ otherwise one of the Errno:: constants.</p>
157
+ </td>
158
+ <td class=code>
159
+ <div class='highlight'><pre> <span class="nb">p</span> <span class="n">client</span><span class="o">.</span><span class="n">closed?</span></pre></div>
160
+ </td>
161
+ </tr>
162
+ <tr id='section-10'>
163
+ <td class=docs>
164
+ <div class="pilwrap">
165
+ <a class="pilcrow" href="#section-10">&#182;</a>
166
+ </div>
167
+ <p>=&gt; true</p>
168
+
169
+ </td>
170
+ <td class=code>
171
+ <div class='highlight'><pre><span class="k">end</span></pre></div>
172
+ </td>
173
+ </tr>
174
+ </table>
175
+ </div>
176
+ </body>
@@ -0,0 +1,161 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
5
+ <title>getting_started.rb</title>
6
+ <link rel="stylesheet" href="http://jashkenas.github.io/docco/resources/linear/docco.css">
7
+ </head>
8
+ <body>
9
+ <div id='container'>
10
+ <div id="background"></div>
11
+ <div id="jump_to">
12
+ Jump To &hellip;
13
+ <div id="jump_wrapper">
14
+ <div id="jump_page">
15
+ <a class="source" href="echo_server.html">echo_server.rb</a>
16
+ <a class="source" href="error_handling.html">error_handling.rb</a>
17
+ <a class="source" href="getting_started.html">getting_started.rb</a>
18
+ <a class="source" href="streaming.html">streaming.rb</a>
19
+ </div>
20
+ </div>
21
+ </div>
22
+ <table cellspacing=0 cellpadding=0>
23
+ <thead>
24
+ <tr>
25
+ <th class=docs><h1>getting_started.rb</h1></th>
26
+ <th class=code></th>
27
+ </tr>
28
+ </thead>
29
+ <tbody>
30
+ <tr id='section-1'>
31
+ <td class=docs>
32
+ <div class="pilwrap">
33
+ <a class="pilcrow" href="#section-1">&#182;</a>
34
+ </div>
35
+
36
+ </td>
37
+ <td class=code>
38
+ <div class='highlight'><pre><span class="nb">require</span> <span class="s1">&#39;httpkit&#39;</span>
39
+
40
+ <span class="no">HTTPkit</span><span class="o">.</span><span class="n">run</span> <span class="k">do</span></pre></div>
41
+ </td>
42
+ </tr>
43
+ <tr id='section-2'>
44
+ <td class=docs>
45
+ <div class="pilwrap">
46
+ <a class="pilcrow" href="#section-2">&#182;</a>
47
+ </div>
48
+ <p>This is short-hand for the HTTPkit::Server.start dance.</p>
49
+ </td>
50
+ <td class=code>
51
+ <div class='highlight'><pre> <span class="no">HTTPkit</span><span class="o">.</span><span class="n">server</span><span class="p">(</span><span class="s1">&#39;http://127.0.0.1:3000&#39;</span><span class="p">)</span> <span class="k">do</span> <span class="o">|</span><span class="n">request</span><span class="p">,</span> <span class="n">served</span><span class="o">|</span>
52
+ <span class="nb">p</span> <span class="n">request</span><span class="o">.</span><span class="n">http_method</span></pre></div>
53
+ </td>
54
+ </tr>
55
+ <tr id='section-3'>
56
+ <td class=docs>
57
+ <div class="pilwrap">
58
+ <a class="pilcrow" href="#section-3">&#182;</a>
59
+ </div>
60
+ <p>=&gt; :get</p>
61
+ </td>
62
+ <td class=code>
63
+ <div class='highlight'><pre> <span class="nb">p</span> <span class="n">request</span><span class="o">.</span><span class="n">uri</span></pre></div>
64
+ </td>
65
+ </tr>
66
+ <tr id='section-4'>
67
+ <td class=docs>
68
+ <div class="pilwrap">
69
+ <a class="pilcrow" href="#section-4">&#182;</a>
70
+ </div>
71
+ <p>=&gt; &ldquo;/&rdquo;</p>
72
+ </td>
73
+ <td class=code>
74
+ <div class='highlight'><pre> <span class="nb">p</span> <span class="n">request</span><span class="o">.</span><span class="n">headers</span></pre></div>
75
+ </td>
76
+ </tr>
77
+ <tr id='section-5'>
78
+ <td class=docs>
79
+ <div class="pilwrap">
80
+ <a class="pilcrow" href="#section-5">&#182;</a>
81
+ </div>
82
+ <p>=&gt; {&ldquo;User-Agent&rdquo;=&gt;&ldquo;httpkit/0.6.0.pre.5&rdquo;, &ldquo;Host&rdquo;=&gt;&ldquo;127.0.0.1:3000&rdquo;}</p>
83
+ </td>
84
+ <td class=code>
85
+ <div class='highlight'><pre> <span class="nb">p</span> <span class="n">request</span><span class="o">.</span><span class="n">body</span><span class="o">.</span><span class="n">to_s</span></pre></div>
86
+ </td>
87
+ </tr>
88
+ <tr id='section-6'>
89
+ <td class=docs>
90
+ <div class="pilwrap">
91
+ <a class="pilcrow" href="#section-6">&#182;</a>
92
+ </div>
93
+ <p>=&gt; &ldquo;&rdquo;</p>
94
+ </td>
95
+ <td class=code>
96
+ <div class='highlight'><pre> <span class="n">served</span><span class="o">.</span><span class="n">fulfill</span><span class="p">(</span><span class="ss">HTTPkit</span><span class="p">:</span><span class="ss">:Response</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="mi">200</span><span class="p">,</span> <span class="p">{},</span> <span class="s1">&#39;hello!&#39;</span><span class="p">))</span>
97
+ <span class="k">end</span></pre></div>
98
+ </td>
99
+ </tr>
100
+ <tr id='section-7'>
101
+ <td class=docs>
102
+ <div class="pilwrap">
103
+ <a class="pilcrow" href="#section-7">&#182;</a>
104
+ </div>
105
+ <p>Same here, but for HTTPkit::Client.start.</p>
106
+ </td>
107
+ <td class=code>
108
+ <div class='highlight'><pre> <span class="n">response</span> <span class="o">=</span> <span class="no">HTTPkit</span><span class="o">.</span><span class="n">request</span><span class="p">(</span><span class="ss">:get</span><span class="p">,</span> <span class="s1">&#39;http://127.0.0.1:3000&#39;</span><span class="p">)</span>
109
+
110
+ <span class="nb">p</span> <span class="n">response</span><span class="o">.</span><span class="n">status</span></pre></div>
111
+ </td>
112
+ </tr>
113
+ <tr id='section-8'>
114
+ <td class=docs>
115
+ <div class="pilwrap">
116
+ <a class="pilcrow" href="#section-8">&#182;</a>
117
+ </div>
118
+ <p>=&gt; 200</p>
119
+ </td>
120
+ <td class=code>
121
+ <div class='highlight'><pre> <span class="nb">p</span> <span class="n">response</span><span class="o">.</span><span class="n">status_name</span></pre></div>
122
+ </td>
123
+ </tr>
124
+ <tr id='section-9'>
125
+ <td class=docs>
126
+ <div class="pilwrap">
127
+ <a class="pilcrow" href="#section-9">&#182;</a>
128
+ </div>
129
+ <p>=&gt; &ldquo;OK&rdquo;</p>
130
+ </td>
131
+ <td class=code>
132
+ <div class='highlight'><pre> <span class="nb">p</span> <span class="n">response</span><span class="o">.</span><span class="n">headers</span></pre></div>
133
+ </td>
134
+ </tr>
135
+ <tr id='section-10'>
136
+ <td class=docs>
137
+ <div class="pilwrap">
138
+ <a class="pilcrow" href="#section-10">&#182;</a>
139
+ </div>
140
+ <p>=&gt; {&ldquo;Connection&rdquo;=&gt;&ldquo;keep-alive&rdquo;, &ldquo;Server&rdquo;=&gt;&ldquo;httpkit/0.6.0.pre.5&rdquo;,
141
+ &ldquo;Date&rdquo;=&gt;&ldquo;Sat, 19 Jul 2014 16:13:30 GMT&rdquo;, &ldquo;Content-Length&rdquo;=&gt;&ldquo;6&rdquo;}</p>
142
+ </td>
143
+ <td class=code>
144
+ <div class='highlight'><pre> <span class="nb">p</span> <span class="n">response</span><span class="o">.</span><span class="n">body</span><span class="o">.</span><span class="n">to_s</span></pre></div>
145
+ </td>
146
+ </tr>
147
+ <tr id='section-11'>
148
+ <td class=docs>
149
+ <div class="pilwrap">
150
+ <a class="pilcrow" href="#section-11">&#182;</a>
151
+ </div>
152
+ <p>=&gt; &ldquo;hello!&rdquo;</p>
153
+
154
+ </td>
155
+ <td class=code>
156
+ <div class='highlight'><pre><span class="k">end</span></pre></div>
157
+ </td>
158
+ </tr>
159
+ </table>
160
+ </div>
161
+ </body>