http_parser.rb 0.5.1 → 0.6.0.beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. data/.gitmodules +4 -4
  2. data/Gemfile +1 -1
  3. data/Gemfile.lock +11 -4
  4. data/LICENSE-MIT +20 -0
  5. data/README.md +51 -46
  6. data/bench/standalone.rb +23 -0
  7. data/bench/thin.rb +1 -0
  8. data/ext/ruby_http_parser/org/ruby_http_parser/RubyHttpParser.java +121 -56
  9. data/ext/ruby_http_parser/ruby_http_parser.c +89 -48
  10. data/ext/ruby_http_parser/vendor/http-parser/AUTHORS +32 -0
  11. data/ext/ruby_http_parser/vendor/http-parser/LICENSE-MIT +5 -1
  12. data/ext/ruby_http_parser/vendor/http-parser/Makefile +34 -17
  13. data/ext/ruby_http_parser/vendor/http-parser/README.md +9 -2
  14. data/ext/ruby_http_parser/vendor/http-parser/http_parser.c +1045 -589
  15. data/ext/ruby_http_parser/vendor/http-parser/http_parser.gyp +79 -0
  16. data/ext/ruby_http_parser/vendor/http-parser/http_parser.h +148 -17
  17. data/ext/ruby_http_parser/vendor/http-parser/test.c +1138 -128
  18. data/ext/ruby_http_parser/vendor/http-parser-java/AUTHORS +32 -0
  19. data/ext/ruby_http_parser/vendor/http-parser-java/LICENSE-MIT +30 -1
  20. data/ext/ruby_http_parser/vendor/http-parser-java/Makefile +34 -17
  21. data/ext/ruby_http_parser/vendor/http-parser-java/README.md +30 -18
  22. data/ext/ruby_http_parser/vendor/http-parser-java/TODO +9 -0
  23. data/ext/ruby_http_parser/vendor/http-parser-java/build.xml +74 -0
  24. data/ext/ruby_http_parser/vendor/http-parser-java/ext/primitives.jar +0 -0
  25. data/ext/ruby_http_parser/vendor/http-parser-java/http_parser.c +1075 -607
  26. data/ext/ruby_http_parser/vendor/http-parser-java/http_parser.gyp +79 -0
  27. data/ext/ruby_http_parser/vendor/http-parser-java/http_parser.h +190 -40
  28. data/ext/ruby_http_parser/vendor/http-parser-java/src/Http-parser.java.iml +22 -0
  29. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/FieldData.java +41 -0
  30. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPCallback.java +8 -0
  31. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPDataCallback.java +34 -0
  32. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPErrorCallback.java +12 -0
  33. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPException.java +4 -2
  34. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPHeadersCompleteCallback.java +13 -0
  35. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPMethod.java +67 -52
  36. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPParser.java +5 -0
  37. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/HTTPParserUrl.java +76 -0
  38. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/ParserSettings.java +323 -0
  39. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/{lolevel/Util.java → Util.java} +34 -35
  40. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/lolevel/HTTPHeadersCompleteCallback.java +12 -0
  41. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/lolevel/HTTPParser.java +839 -587
  42. data/ext/ruby_http_parser/vendor/http-parser-java/src/impl/http_parser/lolevel/ParserSettings.java +2 -1
  43. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Message.java +374 -0
  44. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/ParseUrl.java +51 -0
  45. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Requests.java +69 -0
  46. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Responses.java +52 -0
  47. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Test.java +16 -0
  48. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/TestHeaderOverflowError.java +48 -0
  49. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/TestLoaderNG.java +171 -446
  50. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/TestNoOverflowLongBody.java +62 -0
  51. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/UnitTest.java +3 -1
  52. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Upgrade.java +27 -0
  53. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Url.java +127 -0
  54. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/Util.java +236 -0
  55. data/ext/ruby_http_parser/vendor/http-parser-java/src/test/http_parser/lolevel/WrongContentLength.java +59 -0
  56. data/ext/ruby_http_parser/vendor/http-parser-java/test.c +1318 -184
  57. data/ext/ruby_http_parser/vendor/http-parser-java/tests.dumped +355 -49
  58. data/ext/ruby_http_parser/vendor/http-parser-java/tests.utf8 +17 -0
  59. data/http_parser.rb.gemspec +10 -2
  60. data/lib/http_parser.rb +17 -0
  61. data/spec/parser_spec.rb +157 -23
  62. data/spec/support/requests.json +236 -24
  63. data/spec/support/responses.json +182 -36
  64. data/tasks/compile.rake +5 -3
  65. data/tasks/fixtures.rake +8 -2
  66. metadata +209 -127
  67. data/ext/ruby_http_parser/vendor/http-parser-java/CONTRIBUTIONS +0 -4
  68. data/ext/ruby_http_parser/vendor/http-parser-java/compile +0 -1
  69. data/ext/ruby_http_parser/vendor/http-parser-java/test_permutations +0 -1
  70. data/ext/ruby_http_parser/vendor/http-parser-java/test_unit +0 -1
@@ -19,7 +19,8 @@
19
19
  "Server": "gws",
20
20
  "Content-Length": "219 "
21
21
  },
22
- "body": "<HTML><HEAD><meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">\n<TITLE>301 Moved</TITLE></HEAD><BODY>\n<H1>301 Moved</H1>\nThe document has moved\n<A HREF=\"http://www.google.com/\">here</A>.\r\n</BODY></HTML>\r\n"
22
+ "body": "<HTML><HEAD><meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">\n<TITLE>301 Moved</TITLE></HEAD><BODY>\n<H1>301 Moved</H1>\nThe document has moved\n<A HREF=\"http://www.google.com/\">here</A>.\r\n</BODY></HTML>\r\n",
23
+ "strict": true
23
24
  },
24
25
  {
25
26
  "name": "no content-length response",
@@ -38,14 +39,15 @@
38
39
  "Content-Type": "text/xml; charset=utf-8",
39
40
  "Connection": "close"
40
41
  },
41
- "body": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <SOAP-ENV:Body>\n <SOAP-ENV:Fault>\n <faultcode>SOAP-ENV:Client</faultcode>\n <faultstring>Client Error</faultstring>\n </SOAP-ENV:Fault>\n </SOAP-ENV:Body>\n</SOAP-ENV:Envelope>"
42
+ "body": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <SOAP-ENV:Body>\n <SOAP-ENV:Fault>\n <faultcode>SOAP-ENV:Client</faultcode>\n <faultstring>Client Error</faultstring>\n </SOAP-ENV:Fault>\n </SOAP-ENV:Body>\n</SOAP-ENV:Envelope>",
43
+ "strict": true
42
44
  },
43
45
  {
44
46
  "name": "404 no headers no body",
45
47
  "type": "HTTP_RESPONSE",
46
48
  "raw": "HTTP/1.1 404 Not Found\r\n\r\n",
47
- "should_keep_alive": true,
48
- "message_complete_on_eof": false,
49
+ "should_keep_alive": false,
50
+ "message_complete_on_eof": true,
49
51
  "http_major": 1,
50
52
  "http_minor": 1,
51
53
  "status_code": 404,
@@ -54,14 +56,15 @@
54
56
 
55
57
  },
56
58
  "body_size": 0,
57
- "body": ""
59
+ "body": "",
60
+ "strict": true
58
61
  },
59
62
  {
60
63
  "name": "301 no response phrase",
61
64
  "type": "HTTP_RESPONSE",
62
65
  "raw": "HTTP/1.1 301\r\n\r\n",
63
- "should_keep_alive": true,
64
- "message_complete_on_eof": false,
66
+ "should_keep_alive": false,
67
+ "message_complete_on_eof": true,
65
68
  "http_major": 1,
66
69
  "http_minor": 1,
67
70
  "status_code": 301,
@@ -69,7 +72,8 @@
69
72
  "headers": {
70
73
 
71
74
  },
72
- "body": ""
75
+ "body": "",
76
+ "strict": true
73
77
  },
74
78
  {
75
79
  "name": "200 trailing space on chunked body",
@@ -86,7 +90,8 @@
86
90
  "Transfer-Encoding": "chunked"
87
91
  },
88
92
  "body_size": 65,
89
- "body": "This is the data in the first chunk\r\nand this is the second one\r\n"
93
+ "body": "This is the data in the first chunk\r\nand this is the second one\r\n",
94
+ "strict": true
90
95
  },
91
96
  {
92
97
  "name": "no carriage ret",
@@ -102,7 +107,8 @@
102
107
  "Content-Type": "text/html; charset=utf-8",
103
108
  "Connection": "close"
104
109
  },
105
- "body": "these headers are from http://news.ycombinator.com/"
110
+ "body": "these headers are from http://news.ycombinator.com/",
111
+ "strict": true
106
112
  },
107
113
  {
108
114
  "name": "proxy connection",
@@ -120,7 +126,8 @@
120
126
  "Proxy-Connection": "close",
121
127
  "Date": "Thu, 31 Dec 2009 20:55:48 +0000"
122
128
  },
123
- "body": "hello world"
129
+ "body": "hello world",
130
+ "strict": true
124
131
  },
125
132
  {
126
133
  "name": "underscore header key",
@@ -138,7 +145,8 @@
138
145
  "Content-Length": "0",
139
146
  "DCLK_imp": "v7;x;114750856;0-0;0;17820020;0/0;21603567/21621457/1;;~okv=;dcmt=text/xml;;~cs=o"
140
147
  },
141
- "body": ""
148
+ "body": "",
149
+ "strict": true
142
150
  },
143
151
  {
144
152
  "name": "bonjourmadame.fr",
@@ -161,28 +169,8 @@
161
169
  "Content-Type": "text/html; charset=UTF-8",
162
170
  "Connection": "keep-alive"
163
171
  },
164
- "body": ""
165
- },
166
- {
167
- "name": "field space",
168
- "type": "HTTP_RESPONSE",
169
- "raw": "HTTP/1.1 200 OK\r\nServer: Microsoft-IIS/6.0\r\nX-Powered-By: ASP.NET\r\nen-US Content-Type: text/xml\r\nContent-Type: text/xml\r\nContent-Length: 16\r\nDate: Fri, 23 Jul 2010 18:45:38 GMT\r\nConnection: keep-alive\r\n\r\n<xml>hello</xml>",
170
- "should_keep_alive": true,
171
- "message_complete_on_eof": false,
172
- "http_major": 1,
173
- "http_minor": 1,
174
- "status_code": 200,
175
- "num_headers": 7,
176
- "headers": {
177
- "Server": "Microsoft-IIS/6.0",
178
- "X-Powered-By": "ASP.NET",
179
- "en-US Content-Type": "text/xml",
180
- "Content-Type": "text/xml",
181
- "Content-Length": "16",
182
- "Date": "Fri, 23 Jul 2010 18:45:38 GMT",
183
- "Connection": "keep-alive"
184
- },
185
- "body": "<xml>hello</xml>"
172
+ "body": "",
173
+ "strict": true
186
174
  },
187
175
  {
188
176
  "name": "field underscore",
@@ -207,7 +195,8 @@
207
195
  "Content-Type": "text/html",
208
196
  "Connection": "close"
209
197
  },
210
- "body": ""
198
+ "body": "",
199
+ "strict": true
211
200
  },
212
201
  {
213
202
  "name": "non-ASCII in status line",
@@ -224,6 +213,163 @@
224
213
  "Content-Length": "0",
225
214
  "Connection": "close"
226
215
  },
227
- "body": ""
216
+ "body": "",
217
+ "strict": true
218
+ },
219
+ {
220
+ "name": "http version 0.9",
221
+ "type": "HTTP_RESPONSE",
222
+ "raw": "HTTP/0.9 200 OK\r\n\r\n",
223
+ "should_keep_alive": false,
224
+ "message_complete_on_eof": true,
225
+ "http_major": 0,
226
+ "http_minor": 9,
227
+ "status_code": 200,
228
+ "num_headers": 0,
229
+ "headers": {
230
+
231
+ },
232
+ "body": "",
233
+ "strict": true
234
+ },
235
+ {
236
+ "name": "neither content-length nor transfer-encoding response",
237
+ "type": "HTTP_RESPONSE",
238
+ "raw": "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\nhello world",
239
+ "should_keep_alive": false,
240
+ "message_complete_on_eof": true,
241
+ "http_major": 1,
242
+ "http_minor": 1,
243
+ "status_code": 200,
244
+ "num_headers": 1,
245
+ "headers": {
246
+ "Content-Type": "text/plain"
247
+ },
248
+ "body": "hello world",
249
+ "strict": true
250
+ },
251
+ {
252
+ "name": "HTTP/1.0 with keep-alive and EOF-terminated 200 status",
253
+ "type": "HTTP_RESPONSE",
254
+ "raw": "HTTP/1.0 200 OK\r\nConnection: keep-alive\r\n\r\n",
255
+ "should_keep_alive": false,
256
+ "message_complete_on_eof": true,
257
+ "http_major": 1,
258
+ "http_minor": 0,
259
+ "status_code": 200,
260
+ "num_headers": 1,
261
+ "headers": {
262
+ "Connection": "keep-alive"
263
+ },
264
+ "body_size": 0,
265
+ "body": "",
266
+ "strict": true
267
+ },
268
+ {
269
+ "name": "HTTP/1.0 with keep-alive and a 204 status",
270
+ "type": "HTTP_RESPONSE",
271
+ "raw": "HTTP/1.0 204 No content\r\nConnection: keep-alive\r\n\r\n",
272
+ "should_keep_alive": true,
273
+ "message_complete_on_eof": false,
274
+ "http_major": 1,
275
+ "http_minor": 0,
276
+ "status_code": 204,
277
+ "num_headers": 1,
278
+ "headers": {
279
+ "Connection": "keep-alive"
280
+ },
281
+ "body_size": 0,
282
+ "body": "",
283
+ "strict": true
284
+ },
285
+ {
286
+ "name": "HTTP/1.1 with an EOF-terminated 200 status",
287
+ "type": "HTTP_RESPONSE",
288
+ "raw": "HTTP/1.1 200 OK\r\n\r\n",
289
+ "should_keep_alive": false,
290
+ "message_complete_on_eof": true,
291
+ "http_major": 1,
292
+ "http_minor": 1,
293
+ "status_code": 200,
294
+ "num_headers": 0,
295
+ "headers": {
296
+
297
+ },
298
+ "body_size": 0,
299
+ "body": "",
300
+ "strict": true
301
+ },
302
+ {
303
+ "name": "HTTP/1.1 with a 204 status",
304
+ "type": "HTTP_RESPONSE",
305
+ "raw": "HTTP/1.1 204 No content\r\n\r\n",
306
+ "should_keep_alive": true,
307
+ "message_complete_on_eof": false,
308
+ "http_major": 1,
309
+ "http_minor": 1,
310
+ "status_code": 204,
311
+ "num_headers": 0,
312
+ "headers": {
313
+
314
+ },
315
+ "body_size": 0,
316
+ "body": "",
317
+ "strict": true
318
+ },
319
+ {
320
+ "name": "HTTP/1.1 with a 204 status and keep-alive disabled",
321
+ "type": "HTTP_RESPONSE",
322
+ "raw": "HTTP/1.1 204 No content\r\nConnection: close\r\n\r\n",
323
+ "should_keep_alive": false,
324
+ "message_complete_on_eof": false,
325
+ "http_major": 1,
326
+ "http_minor": 1,
327
+ "status_code": 204,
328
+ "num_headers": 1,
329
+ "headers": {
330
+ "Connection": "close"
331
+ },
332
+ "body_size": 0,
333
+ "body": "",
334
+ "strict": true
335
+ },
336
+ {
337
+ "name": "HTTP/1.1 with chunked endocing and a 200 response",
338
+ "type": "HTTP_RESPONSE",
339
+ "raw": "HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n0\r\n\r\n",
340
+ "should_keep_alive": true,
341
+ "message_complete_on_eof": false,
342
+ "http_major": 1,
343
+ "http_minor": 1,
344
+ "status_code": 200,
345
+ "num_headers": 1,
346
+ "headers": {
347
+ "Transfer-Encoding": "chunked"
348
+ },
349
+ "body_size": 0,
350
+ "body": "",
351
+ "strict": true
352
+ },
353
+ {
354
+ "name": "field space",
355
+ "type": "HTTP_RESPONSE",
356
+ "strict": false,
357
+ "raw": "HTTP/1.1 200 OK\r\nServer: Microsoft-IIS/6.0\r\nX-Powered-By: ASP.NET\r\nen-US Content-Type: text/xml\r\nContent-Type: text/xml\r\nContent-Length: 16\r\nDate: Fri, 23 Jul 2010 18:45:38 GMT\r\nConnection: keep-alive\r\n\r\n<xml>hello</xml>",
358
+ "should_keep_alive": true,
359
+ "message_complete_on_eof": false,
360
+ "http_major": 1,
361
+ "http_minor": 1,
362
+ "status_code": 200,
363
+ "num_headers": 7,
364
+ "headers": {
365
+ "Server": "Microsoft-IIS/6.0",
366
+ "X-Powered-By": "ASP.NET",
367
+ "en-US Content-Type": "text/xml",
368
+ "Content-Type": "text/xml",
369
+ "Content-Length": "16",
370
+ "Date": "Fri, 23 Jul 2010 18:45:38 GMT",
371
+ "Connection": "keep-alive"
372
+ },
373
+ "body": "<xml>hello</xml>"
228
374
  }
229
375
  ]
data/tasks/compile.rake CHANGED
@@ -1,4 +1,4 @@
1
- require 'rake/gempackagetask'
1
+ require 'rubygems/package_task'
2
2
  require 'rake/extensiontask'
3
3
  require 'rake/javaextensiontask'
4
4
 
@@ -6,11 +6,13 @@ def gemspec
6
6
  @clean_gemspec ||= eval(File.read(File.expand_path('../../http_parser.rb.gemspec', __FILE__)))
7
7
  end
8
8
 
9
- Rake::GemPackageTask.new(gemspec) do |pkg|
9
+ Gem::PackageTask.new(gemspec) do |pkg|
10
10
  end
11
11
 
12
12
  if RUBY_PLATFORM =~ /java/
13
- Rake::JavaExtensionTask.new("ruby_http_parser", gemspec)
13
+ Rake::JavaExtensionTask.new("ruby_http_parser", gemspec) do |ext|
14
+ ext.classpath = File.expand_path('../../ext/ruby_http_parser/vendor/http-parser-java/ext/primitives.jar', __FILE__)
15
+ end
14
16
  else
15
17
  Rake::ExtensionTask.new("ruby_http_parser", gemspec) do |ext|
16
18
  unless RUBY_PLATFORM =~ /mswin|mingw/
data/tasks/fixtures.rake CHANGED
@@ -14,13 +14,18 @@ task :fixtures => :submodules do
14
14
  tmp.gsub!('TRUE', 'true')
15
15
  tmp.gsub!('FALSE', 'false')
16
16
 
17
+ # mark strict mode tests
18
+ tmp.gsub!(%r|#if\s+!HTTP_PARSER_STRICT(.+?)#endif\s*/\*\s*!HTTP_PARSER_STRICT.+\n|m){
19
+ $1.gsub(/^(.+,\.type= .+)$/, "\\1\n, .strict= false")
20
+ }
21
+
17
22
  # remove macros and comments
18
- tmp.gsub!(/^#define.+$/,'')
23
+ tmp.gsub!(/^#(if|elif|endif|define).+$/,'')
19
24
  tmp.gsub!(/\/\*(.+?)\*\/$/,'')
20
25
 
21
26
  # HTTP_* enums become strings
22
27
  tmp.gsub!(/(= )(HTTP_\w+)/){
23
- "#{$1}#{$2.dump}"
28
+ "#{$1}#{$2.sub('MSEARCH','M-SEARCH').dump}"
24
29
  }
25
30
 
26
31
  # join multiline strings for body and raw data
@@ -55,6 +60,7 @@ task :fixtures => :submodules do
55
60
  results.map{ |res|
56
61
  res[:headers] and res[:headers] = Hash[*res[:headers].flatten]
57
62
  res[:method] and res[:method].gsub!(/^HTTP_/, '')
63
+ res[:strict] = true unless res.has_key?(:strict)
58
64
  }
59
65
 
60
66
  # write to a file