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,123 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
5
+ <title>request.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>request.rb</h1></th>
44
+ <th class=code></th>
45
+ </tr>
46
+ </thead>
47
+ <tbody>
48
+ <tr id='section-1'>
49
+ <td class=docs>
50
+ <div class="pilwrap">
51
+ <a class="pilcrow" href="#section-1">&#182;</a>
52
+ </div>
53
+
54
+ </td>
55
+ <td class=code>
56
+ <div class='highlight'><pre><span class="k">module</span> <span class="nn">HTTPkit</span>
57
+ <span class="k">class</span> <span class="nc">Request</span>
58
+ <span class="kp">include</span> <span class="ss">Support</span><span class="p">:</span><span class="ss">:Message</span>
59
+ <span class="kp">include</span> <span class="no">Adamantium</span>
60
+
61
+ <span class="kp">attr_reader</span> <span class="ss">:http_method</span><span class="p">,</span> <span class="ss">:uri</span><span class="p">,</span> <span class="ss">:headers</span><span class="p">,</span> <span class="ss">:body</span><span class="p">,</span> <span class="ss">:http_version</span>
62
+
63
+ <span class="k">def</span> <span class="nf">initialize</span><span class="p">(</span><span class="n">http_method</span><span class="p">,</span> <span class="n">uri</span><span class="p">,</span> <span class="n">headers</span> <span class="o">=</span> <span class="p">{},</span> <span class="n">body</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="p">,</span>
64
+ <span class="n">http_version</span> <span class="o">=</span> <span class="mi">1</span><span class="o">.</span><span class="mi">1</span><span class="p">)</span>
65
+ <span class="vi">@http_method</span> <span class="o">=</span> <span class="n">http_method</span></pre></div>
66
+ </td>
67
+ </tr>
68
+ <tr id='section-2'>
69
+ <td class=docs>
70
+ <div class="pilwrap">
71
+ <a class="pilcrow" href="#section-2">&#182;</a>
72
+ </div>
73
+ <p>@uri = URI(&lsquo;http://&rsquo; + uri)</p>
74
+
75
+ </td>
76
+ <td class=code>
77
+ <div class='highlight'><pre> <span class="vi">@uri</span> <span class="o">=</span> <span class="no">URI</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="s1">&#39;http:///&#39;</span><span class="p">,</span> <span class="n">uri</span><span class="p">)</span><span class="o">.</span><span class="n">request_uri</span>
78
+ <span class="vi">@headers</span> <span class="o">=</span> <span class="n">headers</span>
79
+ <span class="vi">@body</span> <span class="o">=</span> <span class="no">Body</span><span class="o">.</span><span class="n">build</span><span class="p">(</span><span class="n">body</span><span class="p">)</span>
80
+ <span class="vi">@http_version</span> <span class="o">=</span> <span class="n">http_version</span>
81
+ <span class="vi">@sequences</span> <span class="o">=</span> <span class="no">SequenceHash</span><span class="o">.</span><span class="n">new</span>
82
+ <span class="k">end</span>
83
+
84
+ <span class="k">def</span> <span class="nf">with_headers</span><span class="p">(</span><span class="n">new_headers</span><span class="p">)</span>
85
+ <span class="n">with</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="n">headers</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">new_headers</span><span class="p">))</span>
86
+ <span class="k">end</span>
87
+
88
+ <span class="k">def</span> <span class="nf">with_body</span><span class="p">(</span><span class="n">new_body</span><span class="p">)</span>
89
+ <span class="n">with</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="no">Body</span><span class="o">.</span><span class="n">build</span><span class="p">(</span><span class="n">new_body</span><span class="p">))</span>
90
+ <span class="k">end</span>
91
+
92
+ <span class="k">def</span> <span class="nf">with</span><span class="p">(</span><span class="n">index</span><span class="p">,</span> <span class="n">argument</span><span class="p">)</span>
93
+ <span class="n">args</span> <span class="o">=</span> <span class="o">[</span><span class="n">http_method</span><span class="p">,</span> <span class="n">uri</span><span class="p">,</span> <span class="n">headers</span><span class="p">,</span> <span class="n">body</span><span class="p">,</span> <span class="n">http_version</span><span class="o">]</span>
94
+ <span class="n">args</span><span class="o">[</span><span class="n">index</span><span class="o">]</span> <span class="o">=</span> <span class="n">argument</span>
95
+ <span class="n">new_self</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>
96
+ <span class="k">end</span>
97
+
98
+ <span class="k">def</span> <span class="nf">new_self</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>
99
+ <span class="n">other</span> <span class="o">=</span> <span class="nb">self</span><span class="o">.</span><span class="n">class</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">)</span>
100
+ <span class="vi">@sequences</span><span class="o">.</span><span class="n">each</span> <span class="p">{</span> <span class="o">|</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="nb">id</span><span class="p">)</span><span class="o">|</span> <span class="n">other</span><span class="o">.</span><span class="n">sequence</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="nb">id</span><span class="p">)</span> <span class="p">}</span>
101
+ <span class="n">other</span>
102
+ <span class="k">end</span>
103
+
104
+ <span class="k">def</span> <span class="nf">sequence</span><span class="p">(</span><span class="n">obj</span><span class="p">,</span> <span class="nb">id</span> <span class="o">=</span> <span class="kp">nil</span><span class="p">)</span>
105
+ <span class="vi">@sequences</span><span class="o">[</span><span class="n">obj</span><span class="o">.</span><span class="n">object_id</span><span class="o">]</span> <span class="o">||=</span> <span class="nb">id</span>
106
+ <span class="k">end</span>
107
+
108
+ <span class="k">def</span> <span class="nf">body_included?</span>
109
+ <span class="n">body_present?</span>
110
+ <span class="k">end</span>
111
+
112
+ <span class="k">def</span> <span class="nf">body_present?</span>
113
+ <span class="o">!</span><span class="n">body</span><span class="o">.</span><span class="n">length_known?</span> <span class="o">||</span> <span class="o">!</span><span class="n">body</span><span class="o">.</span><span class="n">length</span><span class="o">.</span><span class="n">zero?</span>
114
+ <span class="k">end</span>
115
+
116
+ <span class="no">SequenceHash</span> <span class="o">=</span> <span class="no">Class</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="no">Hash</span><span class="p">)</span> <span class="p">{</span> <span class="kp">include</span> <span class="ss">Adamantium</span><span class="p">:</span><span class="ss">:Mutable</span> <span class="p">}</span>
117
+ <span class="k">end</span>
118
+ <span class="k">end</span></pre></div>
119
+ </td>
120
+ </tr>
121
+ </table>
122
+ </div>
123
+ </body>
@@ -0,0 +1,209 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
5
+ <title>response.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>response.rb</h1></th>
44
+ <th class=code></th>
45
+ </tr>
46
+ </thead>
47
+ <tbody>
48
+ <tr id='section-1'>
49
+ <td class=docs>
50
+ <div class="pilwrap">
51
+ <a class="pilcrow" href="#section-1">&#182;</a>
52
+ </div>
53
+
54
+ </td>
55
+ <td class=code>
56
+ <div class='highlight'><pre><span class="k">module</span> <span class="nn">HTTPkit</span>
57
+ <span class="k">class</span> <span class="nc">Response</span>
58
+ <span class="no">NOT_INCLUDED</span> <span class="o">=</span> <span class="o">[</span><span class="mi">204</span><span class="p">,</span> <span class="mi">304</span><span class="o">]</span>
59
+ <span class="no">NOT_PRESENT</span> <span class="o">=</span> <span class="o">[</span><span class="mi">205</span><span class="o">]</span>
60
+
61
+ <span class="kp">include</span> <span class="ss">Support</span><span class="p">:</span><span class="ss">:Message</span>
62
+ <span class="kp">include</span> <span class="no">Adamantium</span>
63
+
64
+ <span class="kp">attr_reader</span> <span class="ss">:status</span><span class="p">,</span> <span class="ss">:headers</span><span class="p">,</span> <span class="ss">:body</span><span class="p">,</span> <span class="ss">:http_version</span>
65
+
66
+ <span class="k">def</span> <span class="nf">initialize</span><span class="p">(</span><span class="n">status</span><span class="p">,</span> <span class="n">headers</span> <span class="o">=</span> <span class="p">{},</span> <span class="n">body</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="n">http_version</span> <span class="o">=</span> <span class="mi">1</span><span class="o">.</span><span class="mi">1</span><span class="p">)</span>
67
+ <span class="vi">@status</span> <span class="o">=</span> <span class="n">status</span>
68
+ <span class="vi">@headers</span> <span class="o">=</span> <span class="n">headers</span>
69
+ <span class="vi">@body</span> <span class="o">=</span> <span class="no">Body</span><span class="o">.</span><span class="n">build</span><span class="p">(</span><span class="n">body</span><span class="p">)</span>
70
+ <span class="vi">@http_version</span> <span class="o">=</span> <span class="n">http_version</span>
71
+ <span class="k">end</span>
72
+
73
+ <span class="k">def</span> <span class="nf">with_headers</span><span class="p">(</span><span class="n">new_headers</span><span class="p">)</span>
74
+ <span class="n">with</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">headers</span><span class="o">.</span><span class="n">merge</span><span class="p">(</span><span class="n">new_headers</span><span class="p">))</span>
75
+ <span class="k">end</span>
76
+
77
+ <span class="k">def</span> <span class="nf">with_body</span><span class="p">(</span><span class="n">new_body</span><span class="p">)</span>
78
+ <span class="n">with</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="no">Body</span><span class="o">.</span><span class="n">build</span><span class="p">(</span><span class="n">new_body</span><span class="p">))</span>
79
+ <span class="k">end</span>
80
+
81
+ <span class="k">def</span> <span class="nf">with</span><span class="p">(</span><span class="n">index</span><span class="p">,</span> <span class="n">argument</span><span class="p">)</span>
82
+ <span class="n">args</span> <span class="o">=</span> <span class="o">[</span><span class="n">status</span><span class="p">,</span> <span class="n">headers</span><span class="p">,</span> <span class="n">body</span><span class="p">,</span> <span class="n">http_version</span><span class="o">]</span>
83
+ <span class="n">args</span><span class="o">[</span><span class="n">index</span><span class="o">]</span> <span class="o">=</span> <span class="n">argument</span>
84
+ <span class="n">new_self</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>
85
+ <span class="k">end</span>
86
+
87
+ <span class="k">def</span> <span class="nf">new_self</span><span class="p">(</span><span class="n">args</span><span class="p">)</span>
88
+ <span class="nb">self</span><span class="o">.</span><span class="n">class</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">)</span>
89
+ <span class="k">end</span>
90
+
91
+ <span class="k">def</span> <span class="nf">body_included?</span>
92
+ <span class="o">!</span><span class="n">informational?</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="no">NOT_INCLUDED</span><span class="o">.</span><span class="n">include?</span><span class="p">(</span><span class="n">status</span><span class="p">)</span>
93
+ <span class="k">end</span>
94
+
95
+ <span class="k">def</span> <span class="nf">body_present?</span>
96
+ <span class="o">!</span><span class="n">informational?</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="no">NOT_PRESENT</span><span class="o">.</span><span class="n">include?</span><span class="p">(</span><span class="n">status</span><span class="p">)</span>
97
+ <span class="k">end</span>
98
+
99
+ <span class="k">def</span> <span class="nf">status_name</span>
100
+ <span class="no">STATUS_NAMES</span><span class="o">[</span><span class="n">status</span><span class="o">.</span><span class="n">to_i</span><span class="o">]</span> <span class="o">||</span> <span class="no">UNKNOWN_STATUS</span>
101
+ <span class="k">end</span>
102
+
103
+ <span class="k">def</span> <span class="nf">status_class</span>
104
+ <span class="n">status</span> <span class="o">/</span> <span class="mi">100</span>
105
+ <span class="k">end</span>
106
+
107
+ <span class="k">def</span> <span class="nf">informational?</span>
108
+ <span class="n">status_class</span> <span class="o">==</span> <span class="mi">1</span>
109
+ <span class="k">end</span>
110
+
111
+ <span class="k">def</span> <span class="nf">successful?</span>
112
+ <span class="n">status_class</span> <span class="o">==</span> <span class="mi">2</span>
113
+ <span class="k">end</span>
114
+
115
+ <span class="k">def</span> <span class="nf">redirection?</span>
116
+ <span class="n">status_class</span> <span class="o">==</span> <span class="mi">3</span>
117
+ <span class="k">end</span>
118
+
119
+ <span class="k">def</span> <span class="nf">client_error?</span>
120
+ <span class="n">status_class</span> <span class="o">==</span> <span class="mi">4</span>
121
+ <span class="k">end</span>
122
+
123
+ <span class="k">def</span> <span class="nf">server_error?</span>
124
+ <span class="n">status_class</span> <span class="o">==</span> <span class="mi">5</span>
125
+ <span class="k">end</span>
126
+
127
+ <span class="no">UNKNOWN_STATUS</span> <span class="o">=</span> <span class="s1">&#39;Unknown Status&#39;</span><span class="o">.</span><span class="n">freeze</span></pre></div>
128
+ </td>
129
+ </tr>
130
+ <tr id='section-2'>
131
+ <td class=docs>
132
+ <div class="pilwrap">
133
+ <a class="pilcrow" href="#section-2">&#182;</a>
134
+ </div>
135
+ <p>TODO: double-check with RFC7230</p>
136
+
137
+ </td>
138
+ <td class=code>
139
+ <div class='highlight'><pre> <span class="no">STATUS_NAMES</span> <span class="o">=</span>
140
+ <span class="p">{</span> <span class="mi">100</span> <span class="o">=&gt;</span> <span class="s1">&#39;Continue&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
141
+ <span class="mi">101</span> <span class="o">=&gt;</span> <span class="s1">&#39;Switching Protocols&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
142
+ <span class="mi">102</span> <span class="o">=&gt;</span> <span class="s1">&#39;Processing&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
143
+ <span class="mi">200</span> <span class="o">=&gt;</span> <span class="s1">&#39;OK&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
144
+ <span class="mi">201</span> <span class="o">=&gt;</span> <span class="s1">&#39;Created&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
145
+ <span class="mi">202</span> <span class="o">=&gt;</span> <span class="s1">&#39;Accepted&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
146
+ <span class="mi">203</span> <span class="o">=&gt;</span> <span class="s1">&#39;Non-Authoritative Information&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
147
+ <span class="mi">204</span> <span class="o">=&gt;</span> <span class="s1">&#39;No Content&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
148
+ <span class="mi">205</span> <span class="o">=&gt;</span> <span class="s1">&#39;Reset Content&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
149
+ <span class="mi">206</span> <span class="o">=&gt;</span> <span class="s1">&#39;Partial Content&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
150
+ <span class="mi">207</span> <span class="o">=&gt;</span> <span class="s1">&#39;Multi-Status&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
151
+ <span class="mi">208</span> <span class="o">=&gt;</span> <span class="s1">&#39;Already Reported&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
152
+ <span class="mi">226</span> <span class="o">=&gt;</span> <span class="s1">&#39;IM Used&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
153
+ <span class="mi">300</span> <span class="o">=&gt;</span> <span class="s1">&#39;Multiple Choices&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
154
+ <span class="mi">301</span> <span class="o">=&gt;</span> <span class="s1">&#39;Moved Permanently&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
155
+ <span class="mi">302</span> <span class="o">=&gt;</span> <span class="s1">&#39;Found&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
156
+ <span class="mi">303</span> <span class="o">=&gt;</span> <span class="s1">&#39;See Other&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
157
+ <span class="mi">304</span> <span class="o">=&gt;</span> <span class="s1">&#39;Not Modified&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
158
+ <span class="mi">305</span> <span class="o">=&gt;</span> <span class="s1">&#39;Use Proxy&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
159
+ <span class="mi">306</span> <span class="o">=&gt;</span> <span class="s1">&#39;Reserved&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
160
+ <span class="mi">307</span> <span class="o">=&gt;</span> <span class="s1">&#39;Temporary Redirect&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
161
+ <span class="mi">308</span> <span class="o">=&gt;</span> <span class="s1">&#39;Permanent Redirect&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
162
+ <span class="mi">400</span> <span class="o">=&gt;</span> <span class="s1">&#39;Bad Request&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
163
+ <span class="mi">401</span> <span class="o">=&gt;</span> <span class="s1">&#39;Unauthorized&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
164
+ <span class="mi">402</span> <span class="o">=&gt;</span> <span class="s1">&#39;Payment Required&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
165
+ <span class="mi">403</span> <span class="o">=&gt;</span> <span class="s1">&#39;Forbidden&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
166
+ <span class="mi">404</span> <span class="o">=&gt;</span> <span class="s1">&#39;Not Found&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
167
+ <span class="mi">405</span> <span class="o">=&gt;</span> <span class="s1">&#39;Method Not Allowed&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
168
+ <span class="mi">406</span> <span class="o">=&gt;</span> <span class="s1">&#39;Not Acceptable&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
169
+ <span class="mi">407</span> <span class="o">=&gt;</span> <span class="s1">&#39;Proxy Authentication Required&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
170
+ <span class="mi">408</span> <span class="o">=&gt;</span> <span class="s1">&#39;Request Timeout&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
171
+ <span class="mi">409</span> <span class="o">=&gt;</span> <span class="s1">&#39;Conflict&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
172
+ <span class="mi">410</span> <span class="o">=&gt;</span> <span class="s1">&#39;Gone&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
173
+ <span class="mi">411</span> <span class="o">=&gt;</span> <span class="s1">&#39;Length Required&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
174
+ <span class="mi">412</span> <span class="o">=&gt;</span> <span class="s1">&#39;Precondition Failed&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
175
+ <span class="mi">413</span> <span class="o">=&gt;</span> <span class="s1">&#39;Request Entity Too Large&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
176
+ <span class="mi">414</span> <span class="o">=&gt;</span> <span class="s1">&#39;Request-URI Too Long&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
177
+ <span class="mi">415</span> <span class="o">=&gt;</span> <span class="s1">&#39;Unsupported Media Type&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
178
+ <span class="mi">416</span> <span class="o">=&gt;</span> <span class="s1">&#39;Requested Range Not Satisfiable&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
179
+ <span class="mi">417</span> <span class="o">=&gt;</span> <span class="s1">&#39;Expectation Failed&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
180
+ <span class="mi">422</span> <span class="o">=&gt;</span> <span class="s1">&#39;Unprocessable Entity&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
181
+ <span class="mi">423</span> <span class="o">=&gt;</span> <span class="s1">&#39;Locked&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
182
+ <span class="mi">424</span> <span class="o">=&gt;</span> <span class="s1">&#39;Failed Dependency&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
183
+ <span class="mi">425</span> <span class="o">=&gt;</span>
184
+ <span class="s1">&#39;Reserved for WebDAV advanced collections expired proposal&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
185
+ <span class="mi">426</span> <span class="o">=&gt;</span> <span class="s1">&#39;Upgrade Required&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
186
+ <span class="mi">427</span> <span class="o">=&gt;</span> <span class="s1">&#39;Unassigned&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
187
+ <span class="mi">428</span> <span class="o">=&gt;</span> <span class="s1">&#39;Precondition Required&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
188
+ <span class="mi">429</span> <span class="o">=&gt;</span> <span class="s1">&#39;Too Many Requests&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
189
+ <span class="mi">430</span> <span class="o">=&gt;</span> <span class="s1">&#39;Unassigned&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
190
+ <span class="mi">431</span> <span class="o">=&gt;</span> <span class="s1">&#39;Request Header Fields Too Large&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
191
+ <span class="mi">500</span> <span class="o">=&gt;</span> <span class="s1">&#39;Internal Server Error&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
192
+ <span class="mi">501</span> <span class="o">=&gt;</span> <span class="s1">&#39;Not Implemented&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
193
+ <span class="mi">502</span> <span class="o">=&gt;</span> <span class="s1">&#39;Bad Gateway&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
194
+ <span class="mi">503</span> <span class="o">=&gt;</span> <span class="s1">&#39;Service Unavailable&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
195
+ <span class="mi">504</span> <span class="o">=&gt;</span> <span class="s1">&#39;Gateway Timeout&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
196
+ <span class="mi">505</span> <span class="o">=&gt;</span> <span class="s1">&#39;HTTP Version Not Supported&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
197
+ <span class="mi">506</span> <span class="o">=&gt;</span> <span class="s1">&#39;Variant Also Negotiates (Experimental)&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
198
+ <span class="mi">507</span> <span class="o">=&gt;</span> <span class="s1">&#39;Insufficient Storage&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
199
+ <span class="mi">508</span> <span class="o">=&gt;</span> <span class="s1">&#39;Loop Detected&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
200
+ <span class="mi">509</span> <span class="o">=&gt;</span> <span class="s1">&#39;Unassigned&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
201
+ <span class="mi">510</span> <span class="o">=&gt;</span> <span class="s1">&#39;Not Extended&#39;</span><span class="o">.</span><span class="n">freeze</span><span class="p">,</span>
202
+ <span class="mi">511</span> <span class="o">=&gt;</span> <span class="s1">&#39;Network Authentication Required&#39;</span><span class="o">.</span><span class="n">freeze</span> <span class="p">}</span>
203
+ <span class="k">end</span>
204
+ <span class="k">end</span></pre></div>
205
+ </td>
206
+ </tr>
207
+ </table>
208
+ </div>
209
+ </body>
@@ -0,0 +1,150 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html;charset=utf-8">
5
+ <title>serializer.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>serializer.rb</h1></th>
44
+ <th class=code></th>
45
+ </tr>
46
+ </thead>
47
+ <tbody>
48
+ <tr id='section-1'>
49
+ <td class=docs>
50
+ <div class="pilwrap">
51
+ <a class="pilcrow" href="#section-1">&#182;</a>
52
+ </div>
53
+
54
+ </td>
55
+ <td class=code>
56
+ <div class='highlight'><pre><span class="k">module</span> <span class="nn">HTTPkit</span></pre></div>
57
+ </td>
58
+ </tr>
59
+ <tr id='section-2'>
60
+ <td class=docs>
61
+ <div class="pilwrap">
62
+ <a class="pilcrow" href="#section-2">&#182;</a>
63
+ </div>
64
+ <p>Streaming HTTP message serializer.</p>
65
+
66
+ <p>@api public</p>
67
+
68
+ </td>
69
+ <td class=code>
70
+ <div class='highlight'><pre> <span class="k">class</span> <span class="nc">Serializer</span>
71
+ <span class="no">REQUEST_LINE</span> <span class="o">=</span> <span class="s2">&quot;%s %s HTTP/%.1f</span><span class="se">\r\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">freeze</span>
72
+ <span class="no">RESPONSE_LINE</span> <span class="o">=</span> <span class="s2">&quot;HTTP/%.1f %d %s</span><span class="se">\r\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">freeze</span>
73
+ <span class="no">HEADER</span> <span class="o">=</span> <span class="s2">&quot;%s: %s</span><span class="se">\r\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">freeze</span>
74
+ <span class="no">TRANSFER_ENCODING</span> <span class="o">=</span> <span class="s1">&#39;Transfer-Encoding&#39;</span><span class="o">.</span><span class="n">freeze</span>
75
+ <span class="no">CHUNKED</span> <span class="o">=</span> <span class="s1">&#39;chunked&#39;</span><span class="o">.</span><span class="n">freeze</span>
76
+ <span class="no">CONTENT_LENGTH</span> <span class="o">=</span> <span class="s1">&#39;Content-Length&#39;</span><span class="o">.</span><span class="n">freeze</span>
77
+ <span class="no">CRLF</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="se">\r\n</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">freeze</span>
78
+
79
+ <span class="k">def</span> <span class="nf">initialize</span><span class="p">(</span><span class="n">message</span><span class="p">,</span> <span class="n">writer</span><span class="p">)</span>
80
+ <span class="vi">@message</span><span class="p">,</span> <span class="vi">@writer</span> <span class="o">=</span> <span class="n">message</span><span class="p">,</span> <span class="n">writer</span>
81
+ <span class="k">end</span>
82
+
83
+ <span class="k">def</span> <span class="nf">serialize</span>
84
+ <span class="n">write</span><span class="p">(</span><span class="n">first_line</span><span class="p">)</span>
85
+ <span class="n">write</span><span class="p">(</span><span class="n">header_block</span><span class="p">)</span>
86
+ <span class="n">write_body</span>
87
+ <span class="k">end</span>
88
+
89
+ <span class="kp">private</span>
90
+
91
+ <span class="k">def</span> <span class="nf">write</span><span class="p">(</span><span class="o">*</span><span class="n">data</span><span class="p">)</span>
92
+ <span class="vi">@writer</span><span class="o">.</span><span class="n">call</span><span class="p">(</span><span class="n">data</span><span class="o">.</span><span class="n">join</span><span class="p">)</span>
93
+ <span class="k">end</span>
94
+
95
+ <span class="k">def</span> <span class="nf">first_line</span>
96
+ <span class="k">if</span> <span class="no">Request</span> <span class="o">===</span> <span class="vi">@message</span>
97
+ <span class="n">request_line</span>
98
+ <span class="k">else</span>
99
+ <span class="n">response_line</span>
100
+ <span class="k">end</span>
101
+ <span class="k">end</span>
102
+
103
+ <span class="k">def</span> <span class="nf">request_line</span>
104
+ <span class="nb">sprintf</span><span class="p">(</span><span class="no">REQUEST_LINE</span><span class="p">,</span>
105
+ <span class="vi">@message</span><span class="o">.</span><span class="n">http_method</span><span class="o">.</span><span class="n">upcase</span><span class="p">,</span> <span class="vi">@message</span><span class="o">.</span><span class="n">uri</span><span class="p">,</span> <span class="vi">@message</span><span class="o">.</span><span class="n">http_version</span><span class="p">)</span>
106
+ <span class="k">end</span>
107
+
108
+ <span class="k">def</span> <span class="nf">response_line</span>
109
+ <span class="nb">sprintf</span><span class="p">(</span><span class="no">RESPONSE_LINE</span><span class="p">,</span>
110
+ <span class="vi">@message</span><span class="o">.</span><span class="n">http_version</span><span class="p">,</span> <span class="vi">@message</span><span class="o">.</span><span class="n">status</span><span class="p">,</span> <span class="vi">@message</span><span class="o">.</span><span class="n">status_name</span><span class="p">)</span>
111
+ <span class="k">end</span>
112
+
113
+ <span class="k">def</span> <span class="nf">header_block</span>
114
+ <span class="vi">@message</span><span class="o">.</span><span class="n">headers</span>
115
+ <span class="o">.</span><span class="n">reduce</span><span class="p">(</span><span class="s1">&#39;&#39;</span><span class="p">)</span> <span class="p">{</span> <span class="o">|</span><span class="n">a</span><span class="p">,</span> <span class="n">e</span><span class="o">|</span> <span class="n">a</span> <span class="o">&lt;&lt;</span> <span class="n">header_line</span><span class="p">(</span><span class="o">*</span><span class="n">e</span><span class="p">)</span> <span class="p">}</span> <span class="o">+</span> <span class="no">CRLF</span>
116
+ <span class="k">end</span>
117
+
118
+ <span class="k">def</span> <span class="nf">header_line</span><span class="p">(</span><span class="n">key</span><span class="p">,</span> <span class="n">value</span><span class="p">)</span>
119
+ <span class="k">if</span> <span class="n">value</span><span class="o">.</span><span class="n">to_s</span><span class="o">.</span><span class="n">empty?</span>
120
+ <span class="s1">&#39;&#39;</span>
121
+ <span class="k">else</span>
122
+ <span class="nb">sprintf</span><span class="p">(</span><span class="no">HEADER</span><span class="p">,</span> <span class="n">key</span><span class="p">,</span>
123
+ <span class="n">value</span><span class="o">.</span><span class="n">respond_to?</span><span class="p">(</span><span class="ss">:join</span><span class="p">)</span> <span class="p">?</span> <span class="n">value</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="s1">&#39;, &#39;</span><span class="p">)</span> <span class="p">:</span> <span class="n">value</span><span class="p">)</span>
124
+ <span class="k">end</span>
125
+ <span class="k">end</span>
126
+
127
+ <span class="k">def</span> <span class="nf">write_body</span>
128
+ <span class="n">body</span> <span class="o">=</span> <span class="vi">@message</span><span class="o">.</span><span class="n">body</span>
129
+ <span class="k">if</span> <span class="o">!</span><span class="n">body</span><span class="o">.</span><span class="n">length_known?</span>
130
+ <span class="n">body</span><span class="o">.</span><span class="n">each</span> <span class="p">{</span> <span class="o">|</span><span class="n">chunk</span><span class="o">|</span> <span class="n">write_chunk</span><span class="p">(</span><span class="n">chunk</span><span class="p">)</span> <span class="p">}</span>
131
+ <span class="n">write_chunk!</span><span class="p">(</span><span class="s1">&#39;&#39;</span><span class="p">)</span>
132
+ <span class="k">else</span>
133
+ <span class="n">write</span><span class="p">(</span><span class="n">body</span><span class="p">)</span>
134
+ <span class="k">end</span>
135
+ <span class="k">end</span>
136
+
137
+ <span class="k">def</span> <span class="nf">write_chunk</span><span class="p">(</span><span class="n">chunk</span><span class="p">)</span>
138
+ <span class="n">write_chunk!</span><span class="p">(</span><span class="n">chunk</span><span class="p">)</span> <span class="k">unless</span> <span class="n">chunk</span><span class="o">.</span><span class="n">empty?</span>
139
+ <span class="k">end</span>
140
+
141
+ <span class="k">def</span> <span class="nf">write_chunk!</span><span class="p">(</span><span class="n">chunk</span><span class="p">)</span>
142
+ <span class="n">write</span><span class="p">(</span><span class="n">chunk</span><span class="o">.</span><span class="n">bytesize</span><span class="o">.</span><span class="n">to_s</span><span class="p">(</span><span class="mi">16</span><span class="p">),</span> <span class="no">CRLF</span><span class="p">,</span> <span class="n">chunk</span><span class="p">,</span> <span class="no">CRLF</span><span class="p">)</span>
143
+ <span class="k">end</span>
144
+ <span class="k">end</span>
145
+ <span class="k">end</span></pre></div>
146
+ </td>
147
+ </tr>
148
+ </table>
149
+ </div>
150
+ </body>