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
@@ -13,7 +13,6 @@ header_0 :{ "User-Agent": "curl/7.18.0 (i486-pc-linux-gnu) libcurl/7.18.0 OpenSS
13
13
  header_1 :{ "Host": "0.0.0.0=5000"}
14
14
  header_2 :{ "Accept": "*/*"}
15
15
  should_keep_alive :1
16
- upgrade :0
17
16
  http_major :1
18
17
  http_minor :1
19
18
 
@@ -37,7 +36,6 @@ header_5 :{ "Accept-Charset": "ISO-8859-1,utf-8;q=0.7,*;q=0.7"}
37
36
  header_6 :{ "Keep-Alive": "300"}
38
37
  header_7 :{ "Connection": "keep-alive"}
39
38
  should_keep_alive :1
40
- upgrade :0
41
39
  http_major :1
42
40
  http_minor :1
43
41
 
@@ -54,7 +52,6 @@ body :""
54
52
  body_size :0
55
53
  header_0 :{ "aaaaaaaaaaaaa": "++++++++++"}
56
54
  should_keep_alive :1
57
- upgrade :0
58
55
  http_major :1
59
56
  http_minor :1
60
57
 
@@ -70,7 +67,6 @@ query_string:page=1
70
67
  body :""
71
68
  body_size :0
72
69
  should_keep_alive :1
73
- upgrade :0
74
70
  http_major :1
75
71
  http_minor :1
76
72
 
@@ -86,7 +82,6 @@ query_string:
86
82
  body :""
87
83
  body_size :0
88
84
  should_keep_alive :1
89
- upgrade :0
90
85
  http_major :1
91
86
  http_minor :1
92
87
 
@@ -103,7 +98,6 @@ body :""
103
98
  body_size :0
104
99
  header_0 :{ "Accept": "*/*"}
105
100
  should_keep_alive :1
106
- upgrade :0
107
101
  http_major :1
108
102
  http_minor :1
109
103
 
@@ -120,7 +114,6 @@ body :"HELLO"
120
114
  body_size :0
121
115
  header_0 :{ "conTENT-Length": "5"}
122
116
  should_keep_alive :0
123
- upgrade :0
124
117
  http_major :1
125
118
  http_minor :0
126
119
 
@@ -139,7 +132,6 @@ header_0 :{ "Accept": "*/*"}
139
132
  header_1 :{ "Transfer-Encoding": "identity"}
140
133
  header_2 :{ "Content-Length": "5"}
141
134
  should_keep_alive :1
142
- upgrade :0
143
135
  http_major :1
144
136
  http_minor :1
145
137
 
@@ -156,7 +148,6 @@ body :"all your base are belong to us"
156
148
  body_size :0
157
149
  header_0 :{ "Transfer-Encoding": "chunked"}
158
150
  should_keep_alive :1
159
- upgrade :0
160
151
  http_major :1
161
152
  http_minor :1
162
153
 
@@ -173,7 +164,6 @@ body :"hello world"
173
164
  body_size :0
174
165
  header_0 :{ "Transfer-Encoding": "chunked"}
175
166
  should_keep_alive :1
176
- upgrade :0
177
167
  http_major :1
178
168
  http_minor :1
179
169
 
@@ -192,7 +182,6 @@ header_0 :{ "Transfer-Encoding": "chunked"}
192
182
  header_1 :{ "Vary": "*"}
193
183
  header_2 :{ "Content-Type": "text/plain"}
194
184
  should_keep_alive :1
195
- upgrade :0
196
185
  http_major :1
197
186
  http_minor :1
198
187
 
@@ -209,7 +198,6 @@ body :"hello world"
209
198
  body_size :0
210
199
  header_0 :{ "Transfer-Encoding": "chunked"}
211
200
  should_keep_alive :1
212
- upgrade :0
213
201
  http_major :1
214
202
  http_minor :1
215
203
 
@@ -225,7 +213,6 @@ query_string:foo="bar"
225
213
  body :""
226
214
  body_size :0
227
215
  should_keep_alive :1
228
- upgrade :0
229
216
  http_major :1
230
217
  http_minor :1
231
218
 
@@ -244,7 +231,6 @@ header_0 :{ "Host": "0.0.0.0:5000"}
244
231
  header_1 :{ "User-Agent": "ApacheBench/2.3"}
245
232
  header_2 :{ "Accept": "*/*"}
246
233
  should_keep_alive :0
247
- upgrade :0
248
234
  http_major :1
249
235
  http_minor :0
250
236
 
@@ -260,7 +246,6 @@ query_string:foo=bar?baz
260
246
  body :""
261
247
  body_size :0
262
248
  should_keep_alive :1
263
- upgrade :0
264
249
  http_major :1
265
250
  http_minor :1
266
251
 
@@ -276,12 +261,11 @@ query_string:
276
261
  body :""
277
262
  body_size :0
278
263
  should_keep_alive :1
279
- upgrade :0
280
264
  http_major :1
281
265
  http_minor :1
282
266
 
283
267
  name :upgrade request
284
- raw :"GET /demo HTTP/1.1\r\nHost: example.com\r\nConnection: Upgrade\r\nSec-WebSocket-Key2: 12998 5 Y3 1 .P00\r\nSec-WebSocket-Protocol: sample\r\nUpgrade: WebSocket\r\nSec-WebSocket-Key1: 4 @1 46546xW%0l 1 5\r\nOrigin: http://example.com\r\n\r\n"
268
+ raw :"GET /demo HTTP/1.1\r\nHost: example.com\r\nConnection: Upgrade\r\nSec-WebSocket-Key2: 12998 5 Y3 1 .P00\r\nSec-WebSocket-Protocol: sample\r\nUpgrade: WebSocket\r\nSec-WebSocket-Key1: 4 @1 46546xW%0l 1 5\r\nOrigin: http://example.com\r\n\r\nHot diggity dogg"
285
269
  type :HTTP_REQUEST
286
270
  method: HTTP_GET
287
271
  status_code :0
@@ -299,17 +283,17 @@ header_4 :{ "Upgrade": "WebSocket"}
299
283
  header_5 :{ "Sec-WebSocket-Key1": "4 @1 46546xW%0l 1 5"}
300
284
  header_6 :{ "Origin": "http://example.com"}
301
285
  should_keep_alive :1
302
- upgrade :1
286
+ upgrade :"Hot diggity dogg"
303
287
  http_major :1
304
288
  http_minor :1
305
289
 
306
290
  name :connect request
307
- raw :"CONNECT home.netscape.com:443 HTTP/1.0\r\nUser-agent: Mozilla/1.1N\r\nProxy-authorization: basic aGVsbG86d29ybGQ=\r\n\r\n"
291
+ raw :"CONNECT 0-home0.netscape.com:443 HTTP/1.0\r\nUser-agent: Mozilla/1.1N\r\nProxy-authorization: basic aGVsbG86d29ybGQ=\r\n\r\nsome data\r\nand yet even more data"
308
292
  type :HTTP_REQUEST
309
293
  method: HTTP_CONNECT
310
294
  status_code :0
311
295
  request_path:
312
- request_url :home.netscape.com:443
296
+ request_url :0-home0.netscape.com:443
313
297
  fragment :
314
298
  query_string:
315
299
  body :""
@@ -317,14 +301,14 @@ body_size :0
317
301
  header_0 :{ "User-agent": "Mozilla/1.1N"}
318
302
  header_1 :{ "Proxy-authorization": "basic aGVsbG86d29ybGQ="}
319
303
  should_keep_alive :0
320
- upgrade :1
304
+ upgrade :"some data\r\nand yet even more data"
321
305
  http_major :1
322
306
  http_minor :0
323
307
 
324
308
  name :report request
325
309
  raw :"REPORT /test HTTP/1.1\r\n\r\n"
326
310
  type :HTTP_REQUEST
327
- method: REPORT
311
+ method: HTTP_REPORT
328
312
  status_code :0
329
313
  request_path:/test
330
314
  request_url :/test
@@ -333,12 +317,196 @@ query_string:
333
317
  body :""
334
318
  body_size :0
335
319
  should_keep_alive :1
336
- upgrade :0
320
+ http_major :1
321
+ http_minor :1
322
+
323
+ name :request with no http version
324
+ raw :"GET /\r\n\r\n"
325
+ type :HTTP_REQUEST
326
+ method: HTTP_GET
327
+ status_code :0
328
+ request_path:/
329
+ request_url :/
330
+ fragment :
331
+ query_string:
332
+ body :""
333
+ body_size :0
334
+ should_keep_alive :0
335
+ http_major :0
336
+ http_minor :9
337
+
338
+ name :m-search request
339
+ raw :"M-SEARCH * HTTP/1.1\r\nHOST: 239.255.255.250:1900\r\nMAN: \"ssdp:discover\"\r\nST: \"ssdp:all\"\r\n\r\n"
340
+ type :HTTP_REQUEST
341
+ method: HTTP_MSEARCH
342
+ status_code :0
343
+ request_path:*
344
+ request_url :*
345
+ fragment :
346
+ query_string:
347
+ body :""
348
+ body_size :0
349
+ header_0 :{ "HOST": "239.255.255.250:1900"}
350
+ header_1 :{ "MAN": ""ssdp:discover""}
351
+ header_2 :{ "ST": ""ssdp:all""}
352
+ should_keep_alive :1
353
+ http_major :1
354
+ http_minor :1
355
+
356
+ name :line folding in header value
357
+ raw :"GET / HTTP/1.1\r\nLine1: abc\r\n def\r\n ghi\r\n jkl\r\n mno \r\n qrs\r\nLine2: line2 \r\n\r\n"
358
+ type :HTTP_REQUEST
359
+ method: HTTP_GET
360
+ status_code :0
361
+ request_path:/
362
+ request_url :/
363
+ fragment :
364
+ query_string:
365
+ body :""
366
+ body_size :0
367
+ header_0 :{ "Line1": "abcdefghijklmno qrs"}
368
+ header_1 :{ "Line2": "line2 "}
369
+ should_keep_alive :1
370
+ http_major :1
371
+ http_minor :1
372
+
373
+ name :host terminated by a query string
374
+ raw :"GET http://hypnotoad.org?hail=all HTTP/1.1\r\n\r\n"
375
+ type :HTTP_REQUEST
376
+ method: HTTP_GET
377
+ status_code :0
378
+ request_path:
379
+ request_url :http://hypnotoad.org?hail=all
380
+ fragment :
381
+ query_string:hail=all
382
+ body :""
383
+ body_size :0
384
+ should_keep_alive :1
385
+ http_major :1
386
+ http_minor :1
387
+
388
+ name :host:port terminated by a query string
389
+ raw :"GET http://hypnotoad.org:1234?hail=all HTTP/1.1\r\n\r\n"
390
+ type :HTTP_REQUEST
391
+ method: HTTP_GET
392
+ status_code :0
393
+ request_path:
394
+ request_url :http://hypnotoad.org:1234?hail=all
395
+ fragment :
396
+ query_string:hail=all
397
+ body :""
398
+ body_size :0
399
+ should_keep_alive :1
400
+ http_major :1
401
+ http_minor :1
402
+
403
+ name :host:port terminated by a space
404
+ raw :"GET http://hypnotoad.org:1234 HTTP/1.1\r\n\r\n"
405
+ type :HTTP_REQUEST
406
+ method: HTTP_GET
407
+ status_code :0
408
+ request_path:
409
+ request_url :http://hypnotoad.org:1234
410
+ fragment :
411
+ query_string:
412
+ body :""
413
+ body_size :0
414
+ should_keep_alive :1
415
+ http_major :1
416
+ http_minor :1
417
+
418
+ name :PATCH request
419
+ raw :"PATCH /file.txt HTTP/1.1\r\nHost: www.example.com\r\nContent-Type: application/example\r\nIf-Match: \"e0023aa4e\"\r\nContent-Length: 10\r\n\r\ncccccccccc"
420
+ type :HTTP_REQUEST
421
+ method: UNKNOWN
422
+ status_code :0
423
+ request_path:/file.txt
424
+ request_url :/file.txt
425
+ fragment :
426
+ query_string:
427
+ body :"cccccccccc"
428
+ body_size :0
429
+ header_0 :{ "Host": "www.example.com"}
430
+ header_1 :{ "Content-Type": "application/example"}
431
+ header_2 :{ "If-Match": ""e0023aa4e""}
432
+ header_3 :{ "Content-Length": "10"}
433
+ should_keep_alive :1
434
+ http_major :1
435
+ http_minor :1
436
+
437
+ name :connect caps request
438
+ raw :"CONNECT HOME0.NETSCAPE.COM:443 HTTP/1.0\r\nUser-agent: Mozilla/1.1N\r\nProxy-authorization: basic aGVsbG86d29ybGQ=\r\n\r\n"
439
+ type :HTTP_REQUEST
440
+ method: HTTP_CONNECT
441
+ status_code :0
442
+ request_path:
443
+ request_url :HOME0.NETSCAPE.COM:443
444
+ fragment :
445
+ query_string:
446
+ body :""
447
+ body_size :0
448
+ header_0 :{ "User-agent": "Mozilla/1.1N"}
449
+ header_1 :{ "Proxy-authorization": "basic aGVsbG86d29ybGQ="}
450
+ should_keep_alive :0
451
+ upgrade :""
452
+ http_major :1
453
+ http_minor :0
454
+
455
+ name :eat CRLF between requests, no "Connection: close" header
456
+ raw :"POST / HTTP/1.1\r\nHost: www.example.com\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 4\r\n\r\nq=42\r\n"
457
+ type :HTTP_REQUEST
458
+ method: HTTP_POST
459
+ status_code :0
460
+ request_path:/
461
+ request_url :/
462
+ fragment :
463
+ query_string:
464
+ body :"q=42"
465
+ body_size :0
466
+ header_0 :{ "Host": "www.example.com"}
467
+ header_1 :{ "Content-Type": "application/x-www-form-urlencoded"}
468
+ header_2 :{ "Content-Length": "4"}
469
+ should_keep_alive :1
470
+ http_major :1
471
+ http_minor :1
472
+
473
+ name :eat CRLF between requests even if "Connection: close" is set
474
+ raw :"POST / HTTP/1.1\r\nHost: www.example.com\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: 4\r\nConnection: close\r\n\r\nq=42\r\n"
475
+ type :HTTP_REQUEST
476
+ method: HTTP_POST
477
+ status_code :0
478
+ request_path:/
479
+ request_url :/
480
+ fragment :
481
+ query_string:
482
+ body :"q=42"
483
+ body_size :0
484
+ header_0 :{ "Host": "www.example.com"}
485
+ header_1 :{ "Content-Type": "application/x-www-form-urlencoded"}
486
+ header_2 :{ "Content-Length": "4"}
487
+ header_3 :{ "Connection": "close"}
488
+ should_keep_alive :0
489
+ http_major :1
490
+ http_minor :1
491
+
492
+ name :PURGE request
493
+ raw :"PURGE /file.txt HTTP/1.1\r\nHost: www.example.com\r\n\r\n"
494
+ type :HTTP_REQUEST
495
+ method: UNKNOWN
496
+ status_code :0
497
+ request_path:/file.txt
498
+ request_url :/file.txt
499
+ fragment :
500
+ query_string:
501
+ body :""
502
+ body_size :0
503
+ header_0 :{ "Host": "www.example.com"}
504
+ should_keep_alive :1
337
505
  http_major :1
338
506
  http_minor :1
339
507
 
340
508
  name :google 301
341
- raw :"HTTP/1.1 301 Moved Permanently\r\nLocation: http://www.google.com/\r\nContent-Type: text/html; charset=UTF-8\r\nDate: Sun, 26 Apr 2009 11:11:49 GMT\r\nExpires: Tue, 26 May 2009 11:11:49 GMT\r\nCache-Control: public, max-age=2592000\r\nServer: gws\r\nContent-Length: 219\r\n\r\n<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"
509
+ raw :"HTTP/1.1 301 Moved Permanently\r\nLocation: http://www.google.com/\r\nContent-Type: text/html; charset=UTF-8\r\nDate: Sun, 26 Apr 2009 11:11:49 GMT\r\nExpires: Tue, 26 May 2009 11:11:49 GMT\r\nX-$PrototypeBI-Version: 1.6.0.3\r\nCache-Control: public, max-age=2592000\r\nServer: gws\r\nContent-Length: 219 \r\n\r\n<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"
342
510
  type :HTTP_RESPONSE
343
511
  method: HTTP_DELETE
344
512
  status_code :301
@@ -352,11 +520,11 @@ header_0 :{ "Location": "http://www.google.com/"}
352
520
  header_1 :{ "Content-Type": "text/html; charset=UTF-8"}
353
521
  header_2 :{ "Date": "Sun, 26 Apr 2009 11:11:49 GMT"}
354
522
  header_3 :{ "Expires": "Tue, 26 May 2009 11:11:49 GMT"}
355
- header_4 :{ "Cache-Control": "public, max-age=2592000"}
356
- header_5 :{ "Server": "gws"}
357
- header_6 :{ "Content-Length": "219"}
523
+ header_4 :{ "X-$PrototypeBI-Version": "1.6.0.3"}
524
+ header_5 :{ "Cache-Control": "public, max-age=2592000"}
525
+ header_6 :{ "Server": "gws"}
526
+ header_7 :{ "Content-Length": "219 "}
358
527
  should_keep_alive :1
359
- upgrade :0
360
528
  http_major :1
361
529
  http_minor :1
362
530
 
@@ -377,7 +545,6 @@ header_2 :{ "X-Powered-By": "Servlet/2.5 JSP/2.1"}
377
545
  header_3 :{ "Content-Type": "text/xml; charset=utf-8"}
378
546
  header_4 :{ "Connection": "close"}
379
547
  should_keep_alive :0
380
- upgrade :0
381
548
  http_major :1
382
549
  http_minor :1
383
550
 
@@ -392,8 +559,7 @@ fragment :
392
559
  query_string:
393
560
  body :""
394
561
  body_size :0
395
- should_keep_alive :1
396
- upgrade :0
562
+ should_keep_alive :0
397
563
  http_major :1
398
564
  http_minor :1
399
565
 
@@ -408,8 +574,7 @@ fragment :
408
574
  query_string:
409
575
  body :""
410
576
  body_size :0
411
- should_keep_alive :1
412
- upgrade :0
577
+ should_keep_alive :0
413
578
  http_major :1
414
579
  http_minor :1
415
580
 
@@ -427,7 +592,6 @@ body_size :65
427
592
  header_0 :{ "Content-Type": "text/plain"}
428
593
  header_1 :{ "Transfer-Encoding": "chunked"}
429
594
  should_keep_alive :1
430
- upgrade :0
431
595
  http_major :1
432
596
  http_minor :1
433
597
 
@@ -445,7 +609,6 @@ body_size :0
445
609
  header_0 :{ "Content-Type": "text/html; charset=utf-8"}
446
610
  header_1 :{ "Connection": "close"}
447
611
  should_keep_alive :0
448
- upgrade :0
449
612
  http_major :1
450
613
  http_minor :1
451
614
 
@@ -465,7 +628,6 @@ header_1 :{ "Content-Length": "11"}
465
628
  header_2 :{ "Proxy-Connection": "close"}
466
629
  header_3 :{ "Date": "Thu, 31 Dec 2009 20:55:48 +0000"}
467
630
  should_keep_alive :0
468
- upgrade :0
469
631
  http_major :1
470
632
  http_minor :1
471
633
 
@@ -485,7 +647,6 @@ header_1 :{ "Content-Type": "text/xml"}
485
647
  header_2 :{ "Content-Length": "0"}
486
648
  header_3 :{ "DCLK_imp": "v7;x;114750856;0-0;0;17820020;0/0;21603567/21621457/1;;~okv=;dcmt=text/xml;;~cs=o"}
487
649
  should_keep_alive :1
488
- upgrade :0
489
650
  http_major :1
490
651
  http_minor :1
491
652
 
@@ -510,12 +671,118 @@ header_6 :{ "Content-Length": "0"}
510
671
  header_7 :{ "Content-Type": "text/html; charset=UTF-8"}
511
672
  header_8 :{ "Connection": "keep-alive"}
512
673
  should_keep_alive :1
513
- upgrade :0
514
674
  http_major :1
515
675
  http_minor :0
516
676
 
517
- name :field space
518
- 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>"
677
+ name :field underscore
678
+ raw :"HTTP/1.1 200 OK\r\nDate: Tue, 28 Sep 2010 01:14:13 GMT\r\nServer: Apache\r\nCache-Control: no-cache, must-revalidate\r\nExpires: Mon, 26 Jul 1997 05:00:00 GMT\r\n.et-Cookie: PlaxoCS=1274804622353690521; path=/; domain=.plaxo.com\r\nVary: Accept-Encoding\r\n_eep-Alive: timeout=45\r\n_onnection: Keep-Alive\r\nTransfer-Encoding: chunked\r\nContent-Type: text/html\r\nConnection: close\r\n\r\n0\r\n\r\n"
679
+ type :HTTP_RESPONSE
680
+ method: HTTP_DELETE
681
+ status_code :200
682
+ request_path:
683
+ request_url :
684
+ fragment :
685
+ query_string:
686
+ body :""
687
+ body_size :0
688
+ header_0 :{ "Date": "Tue, 28 Sep 2010 01:14:13 GMT"}
689
+ header_1 :{ "Server": "Apache"}
690
+ header_2 :{ "Cache-Control": "no-cache, must-revalidate"}
691
+ header_3 :{ "Expires": "Mon, 26 Jul 1997 05:00:00 GMT"}
692
+ header_4 :{ ".et-Cookie": "PlaxoCS=1274804622353690521; path=/; domain=.plaxo.com"}
693
+ header_5 :{ "Vary": "Accept-Encoding"}
694
+ header_6 :{ "_eep-Alive": "timeout=45"}
695
+ header_7 :{ "_onnection": "Keep-Alive"}
696
+ header_8 :{ "Transfer-Encoding": "chunked"}
697
+ header_9 :{ "Content-Type": "text/html"}
698
+ header_10 :{ "Connection": "close"}
699
+ should_keep_alive :0
700
+ http_major :1
701
+ http_minor :1
702
+
703
+ name :non-ASCII in status line
704
+ raw :"HTTP/1.1 500 Oriëntatieprobleem\r\nDate: Fri, 5 Nov 2010 23:07:12 GMT+2\r\nContent-Length: 0\r\nConnection: close\r\n\r\n"
705
+ type :HTTP_RESPONSE
706
+ method: HTTP_DELETE
707
+ status_code :500
708
+ request_path:
709
+ request_url :
710
+ fragment :
711
+ query_string:
712
+ body :""
713
+ body_size :0
714
+ header_0 :{ "Date": "Fri, 5 Nov 2010 23:07:12 GMT+2"}
715
+ header_1 :{ "Content-Length": "0"}
716
+ header_2 :{ "Connection": "close"}
717
+ should_keep_alive :0
718
+ http_major :1
719
+ http_minor :1
720
+
721
+ name :http version 0.9
722
+ raw :"HTTP/0.9 200 OK\r\n\r\n"
723
+ type :HTTP_RESPONSE
724
+ method: HTTP_DELETE
725
+ status_code :200
726
+ request_path:
727
+ request_url :
728
+ fragment :
729
+ query_string:
730
+ body :""
731
+ body_size :0
732
+ should_keep_alive :0
733
+ http_major :0
734
+ http_minor :9
735
+
736
+ name :neither content-length nor transfer-encoding response
737
+ raw :"HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\n\r\nhello world"
738
+ type :HTTP_RESPONSE
739
+ method: HTTP_DELETE
740
+ status_code :200
741
+ request_path:
742
+ request_url :
743
+ fragment :
744
+ query_string:
745
+ body :"hello world"
746
+ body_size :0
747
+ header_0 :{ "Content-Type": "text/plain"}
748
+ should_keep_alive :0
749
+ http_major :1
750
+ http_minor :1
751
+
752
+ name :HTTP/1.0 with keep-alive and EOF-terminated 200 status
753
+ raw :"HTTP/1.0 200 OK\r\nConnection: keep-alive\r\n\r\n"
754
+ type :HTTP_RESPONSE
755
+ method: HTTP_DELETE
756
+ status_code :200
757
+ request_path:
758
+ request_url :
759
+ fragment :
760
+ query_string:
761
+ body :""
762
+ body_size :0
763
+ header_0 :{ "Connection": "keep-alive"}
764
+ should_keep_alive :0
765
+ http_major :1
766
+ http_minor :0
767
+
768
+ name :HTTP/1.0 with keep-alive and a 204 status
769
+ raw :"HTTP/1.0 204 No content\r\nConnection: keep-alive\r\n\r\n"
770
+ type :HTTP_RESPONSE
771
+ method: HTTP_DELETE
772
+ status_code :204
773
+ request_path:
774
+ request_url :
775
+ fragment :
776
+ query_string:
777
+ body :""
778
+ body_size :0
779
+ header_0 :{ "Connection": "keep-alive"}
780
+ should_keep_alive :1
781
+ http_major :1
782
+ http_minor :0
783
+
784
+ name :HTTP/1.1 with an EOF-terminated 200 status
785
+ raw :"HTTP/1.1 200 OK\r\n\r\n"
519
786
  type :HTTP_RESPONSE
520
787
  method: HTTP_DELETE
521
788
  status_code :200
@@ -523,17 +790,56 @@ request_path:
523
790
  request_url :
524
791
  fragment :
525
792
  query_string:
526
- body :"<xml>hello</xml>"
793
+ body :""
527
794
  body_size :0
528
- header_0 :{ "Server": "Microsoft-IIS/6.0"}
529
- header_1 :{ "X-Powered-By": "ASP.NET"}
530
- header_2 :{ "en-US Content-Type": "text/xml"}
531
- header_3 :{ "Content-Type": "text/xml"}
532
- header_4 :{ "Content-Length": "16"}
533
- header_5 :{ "Date": "Fri, 23 Jul 2010 18:45:38 GMT"}
534
- header_6 :{ "Connection": "keep-alive"}
795
+ should_keep_alive :0
796
+ http_major :1
797
+ http_minor :1
798
+
799
+ name :HTTP/1.1 with a 204 status
800
+ raw :"HTTP/1.1 204 No content\r\n\r\n"
801
+ type :HTTP_RESPONSE
802
+ method: HTTP_DELETE
803
+ status_code :204
804
+ request_path:
805
+ request_url :
806
+ fragment :
807
+ query_string:
808
+ body :""
809
+ body_size :0
810
+ should_keep_alive :1
811
+ http_major :1
812
+ http_minor :1
813
+
814
+ name :HTTP/1.1 with a 204 status and keep-alive disabled
815
+ raw :"HTTP/1.1 204 No content\r\nConnection: close\r\n\r\n"
816
+ type :HTTP_RESPONSE
817
+ method: HTTP_DELETE
818
+ status_code :204
819
+ request_path:
820
+ request_url :
821
+ fragment :
822
+ query_string:
823
+ body :""
824
+ body_size :0
825
+ header_0 :{ "Connection": "close"}
826
+ should_keep_alive :0
827
+ http_major :1
828
+ http_minor :1
829
+
830
+ name :HTTP/1.1 with chunked endocing and a 200 response
831
+ raw :"HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n0\r\n\r\n"
832
+ type :HTTP_RESPONSE
833
+ method: HTTP_DELETE
834
+ status_code :200
835
+ request_path:
836
+ request_url :
837
+ fragment :
838
+ query_string:
839
+ body :""
840
+ body_size :0
841
+ header_0 :{ "Transfer-Encoding": "chunked"}
535
842
  should_keep_alive :1
536
- upgrade :0
537
843
  http_major :1
538
844
  http_minor :1
539
845
 
@@ -0,0 +1,17 @@
1
+ name :utf-8 path request
2
+ raw :"GET /δ¶/δt/pope?q=1#narf HTTP/1.1\r\nHost: github.com\r\n\r\n"
3
+ type :HTTP_REQUEST
4
+ method: HTTP_GET
5
+ status_code :0
6
+ request_path:/δ¶/δt/pope
7
+ request_url :/δ¶/δt/pope?q=1#narf
8
+ fragment :narf
9
+ query_string:q=1
10
+ body :""
11
+ body_size :0
12
+ header_0 :{ "Host": "github.com"}
13
+ should_keep_alive :1
14
+ upgrade :0
15
+ http_major :1
16
+ http_minor :1
17
+
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "http_parser.rb"
3
- s.version = "0.5.1"
3
+ s.version = "0.6.0.beta.1"
4
4
  s.summary = "Simple callback-based HTTP request/response parser"
5
5
  s.description = "Ruby bindings to http://github.com/ry/http-parser and http://github.com/a2800276/http-parser.java"
6
6
 
@@ -13,7 +13,15 @@ Gem::Specification.new do |s|
13
13
  s.require_paths = ["lib"]
14
14
  s.extensions = ["ext/ruby_http_parser/extconf.rb"]
15
15
 
16
- s.add_development_dependency 'rake-compiler', '>= 0.7.5'
16
+ s.add_development_dependency 'rake-compiler', '>= 0.7.9'
17
17
  s.add_development_dependency 'rspec', '>= 2.0.1'
18
18
  s.add_development_dependency 'json', '>= 1.4.6'
19
+ s.add_development_dependency 'benchmark_suite'
20
+ s.add_development_dependency 'ffi'
21
+
22
+ if RUBY_PLATFORM =~ /java/
23
+ s.add_development_dependency 'jruby-openssl'
24
+ else
25
+ s.add_development_dependency 'yajl-ruby', '>= 0.8.1'
26
+ end
19
27
  end
data/lib/http_parser.rb CHANGED
@@ -2,3 +2,20 @@ $:.unshift File.expand_path('../', __FILE__)
2
2
  require 'ruby_http_parser'
3
3
 
4
4
  Http = HTTP
5
+
6
+ module HTTP
7
+ class Parser
8
+ class << self
9
+ attr_reader :default_header_value_type
10
+
11
+ def default_header_value_type=(val)
12
+ if (val != :mixed && val != :strings && val != :arrays)
13
+ raise ArgumentError, "Invalid header value type"
14
+ end
15
+ @default_header_value_type = val
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ HTTP::Parser.default_header_value_type = :mixed