mongrel 0.3.12 → 0.3.12.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. data/Rakefile +1 -1
  2. data/bin/mongrel_rails +12 -6
  3. data/doc/rdoc/classes/Class.src/M000001.html +10 -10
  4. data/doc/rdoc/classes/Class.src/M000002.html +46 -46
  5. data/doc/rdoc/classes/Class.src/M000003.html +7 -7
  6. data/doc/rdoc/classes/Class.src/M000004.html +6 -6
  7. data/doc/rdoc/classes/IO.src/M000005.html +5 -5
  8. data/doc/rdoc/classes/IO.src/M000006.html +5 -5
  9. data/doc/rdoc/classes/Kernel.src/M000025.html +5 -5
  10. data/doc/rdoc/classes/Kernel.src/M000026.html +11 -11
  11. data/doc/rdoc/classes/Mongrel.html +1 -0
  12. data/doc/rdoc/classes/Mongrel/Command/Base.src/M000030.html +1 -1
  13. data/doc/rdoc/classes/Mongrel/Configurator.src/M000099.html +10 -10
  14. data/doc/rdoc/classes/Mongrel/Configurator.src/M000100.html +9 -9
  15. data/doc/rdoc/classes/Mongrel/Configurator.src/M000101.html +4 -4
  16. data/doc/rdoc/classes/Mongrel/Configurator.src/M000102.html +18 -18
  17. data/doc/rdoc/classes/Mongrel/Configurator.src/M000103.html +5 -5
  18. data/doc/rdoc/classes/Mongrel/Configurator.src/M000104.html +16 -16
  19. data/doc/rdoc/classes/Mongrel/Configurator.src/M000105.html +19 -19
  20. data/doc/rdoc/classes/Mongrel/Configurator.src/M000106.html +4 -4
  21. data/doc/rdoc/classes/Mongrel/Configurator.src/M000107.html +10 -11
  22. data/doc/rdoc/classes/Mongrel/Configurator.src/M000108.html +5 -5
  23. data/doc/rdoc/classes/Mongrel/Configurator.src/M000109.html +8 -8
  24. data/doc/rdoc/classes/Mongrel/Configurator.src/M000110.html +7 -7
  25. data/doc/rdoc/classes/Mongrel/Configurator.src/M000111.html +4 -4
  26. data/doc/rdoc/classes/Mongrel/Configurator.src/M000112.html +14 -13
  27. data/doc/rdoc/classes/Mongrel/Configurator.src/M000113.html +5 -33
  28. data/doc/rdoc/classes/Mongrel/Configurator.src/M000114.html +33 -5
  29. data/doc/rdoc/classes/Mongrel/Configurator.src/M000115.html +18 -0
  30. data/doc/rdoc/classes/Mongrel/Const.html +11 -1
  31. data/doc/rdoc/classes/Mongrel/Error404Handler.src/M000116.html +5 -5
  32. data/doc/rdoc/classes/Mongrel/Error404Handler.src/M000117.html +18 -0
  33. data/doc/rdoc/classes/Mongrel/HeaderOut.html +0 -185
  34. data/doc/rdoc/classes/Mongrel/HeaderOut.src/M000072.html +4 -4
  35. data/doc/rdoc/classes/Mongrel/HeaderOut.src/M000073.html +4 -4
  36. data/doc/rdoc/classes/Mongrel/HttpParser.src/M000054.html +3 -1
  37. data/doc/rdoc/classes/Mongrel/{StopServer.html → HttpParserError.html} +5 -11
  38. data/doc/rdoc/classes/Mongrel/HttpRequest.src/M000118.html +15 -7
  39. data/doc/rdoc/classes/Mongrel/HttpRequest.src/M000119.html +7 -7
  40. data/doc/rdoc/classes/Mongrel/HttpRequest.src/M000120.html +7 -19
  41. data/doc/rdoc/classes/Mongrel/HttpRequest.src/M000121.html +32 -0
  42. data/doc/rdoc/classes/Mongrel/HttpResponse.src/M000075.html +12 -12
  43. data/doc/rdoc/classes/Mongrel/HttpResponse.src/M000076.html +6 -6
  44. data/doc/rdoc/classes/Mongrel/HttpResponse.src/M000077.html +11 -11
  45. data/doc/rdoc/classes/Mongrel/HttpResponse.src/M000078.html +8 -8
  46. data/doc/rdoc/classes/Mongrel/HttpResponse.src/M000079.html +8 -8
  47. data/doc/rdoc/classes/Mongrel/HttpResponse.src/M000080.html +9 -9
  48. data/doc/rdoc/classes/Mongrel/HttpResponse.src/M000081.html +4 -4
  49. data/doc/rdoc/classes/Mongrel/HttpResponse.src/M000082.html +6 -6
  50. data/doc/rdoc/classes/Mongrel/HttpResponse.src/M000083.html +4 -4
  51. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000064.html +10 -10
  52. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000065.html +51 -50
  53. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000066.html +10 -10
  54. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000067.html +45 -45
  55. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000068.html +14 -14
  56. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000069.html +4 -4
  57. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000070.html +8 -8
  58. data/doc/rdoc/classes/Mongrel/HttpServer.src/M000071.html +4 -4
  59. data/doc/rdoc/classes/ObjectTracker.src/M000019.html +20 -22
  60. data/doc/rdoc/classes/RequestLog/Access.src/M000122.html +19 -0
  61. data/doc/rdoc/classes/RequestLog/Files.src/{M000121.html → M000123.html} +5 -5
  62. data/doc/rdoc/classes/RequestLog/Objects.src/{M000122.html → M000124.html} +5 -5
  63. data/doc/rdoc/classes/RequestLog/Params.src/{M000123.html → M000125.html} +5 -5
  64. data/doc/rdoc/classes/Stats.html +1 -1
  65. data/doc/rdoc/classes/Stats.src/M000012.html +2 -2
  66. data/doc/rdoc/created.rid +1 -1
  67. data/doc/rdoc/files/ext/http11/http11_c.html +1 -1
  68. data/doc/rdoc/files/lib/mongrel/command_rb.html +1 -1
  69. data/doc/rdoc/files/lib/mongrel/debug_rb.html +1 -1
  70. data/doc/rdoc/files/lib/mongrel/handlers_rb.html +1 -1
  71. data/doc/rdoc/files/lib/mongrel/stats_rb.html +1 -1
  72. data/doc/rdoc/files/lib/mongrel_rb.html +1 -1
  73. data/examples/random_thrash.rb +19 -0
  74. data/ext/http11/http11.c +57 -12
  75. data/ext/http11/http11_parser.c +58 -52
  76. data/lib/mongrel.rb +37 -10
  77. data/lib/mongrel/command.rb +1 -1
  78. data/lib/mongrel/debug.rb +39 -125
  79. data/lib/mongrel/handlers.rb +2 -2
  80. data/lib/mongrel/rails.rb +2 -1
  81. data/lib/mongrel/stats.rb +2 -2
  82. data/test/test_configurator.rb +2 -2
  83. data/test/test_debug.rb +2 -4
  84. data/test/test_http11.rb +76 -7
  85. data/test/test_stats.rb +6 -4
  86. data/test/test_uriclassifier.rb +0 -14
  87. metadata +12 -24
  88. data/doc/rdoc/classes/Mongrel/CGIWrapper.html +0 -383
  89. data/doc/rdoc/classes/Mongrel/Configurator.html +0 -563
  90. data/doc/rdoc/classes/Mongrel/Error404Handler.html +0 -171
  91. data/doc/rdoc/classes/Mongrel/Error404Handler.src/M000115.html +0 -18
  92. data/doc/rdoc/classes/Mongrel/HttpHandler.html +0 -152
  93. data/doc/rdoc/classes/Mongrel/HttpRequest.html +0 -222
  94. data/doc/rdoc/classes/Mongrel/HttpRequest.src/M000117.html +0 -28
  95. data/doc/rdoc/classes/Mongrel/HttpResponse.html +0 -371
  96. data/doc/rdoc/classes/Mongrel/URIClassifier.html +0 -301
  97. data/doc/rdoc/classes/RequestLog.html +0 -113
  98. data/doc/rdoc/classes/RequestLog/Files.html +0 -144
  99. data/doc/rdoc/classes/RequestLog/Objects.html +0 -144
  100. data/doc/rdoc/classes/RequestLog/Params.html +0 -144
  101. data/doc/rdoc/fr_class_index.html +0 -60
  102. data/doc/rdoc/fr_file_index.html +0 -40
  103. data/doc/rdoc/fr_method_index.html +0 -149
  104. data/doc/rdoc/index.html +0 -24
  105. data/lib/http11.bundle +0 -0
@@ -6,10 +6,10 @@
6
6
  #include <ctype.h>
7
7
  #include <string.h>
8
8
 
9
- #define MARK(S,F) assert((F) - (S)->mark >= 0); (S)->mark = (F);
9
+ #define MARK(S,F) (S)->mark = (F);
10
10
 
11
11
  /** machine **/
12
- #line 101 "ext/http11/http11_parser.rl"
12
+ #line 107 "ext/http11/http11_parser.rl"
13
13
 
14
14
 
15
15
  /** Data **/
@@ -21,7 +21,7 @@ static int http_parser_first_final = 53;
21
21
 
22
22
  static int http_parser_error = 1;
23
23
 
24
- #line 105 "ext/http11/http11_parser.rl"
24
+ #line 111 "ext/http11/http11_parser.rl"
25
25
 
26
26
  int http_parser_init(http_parser *parser) {
27
27
  int cs = 0;
@@ -30,7 +30,7 @@ int http_parser_init(http_parser *parser) {
30
30
  {
31
31
  cs = http_parser_start;
32
32
  }
33
- #line 109 "ext/http11/http11_parser.rl"
33
+ #line 115 "ext/http11/http11_parser.rl"
34
34
  parser->cs = cs;
35
35
  parser->body_start = NULL;
36
36
  parser->content_len = 0;
@@ -71,7 +71,7 @@ st1:
71
71
  goto _out1;
72
72
  tr13:
73
73
  #line 14 "ext/http11/http11_parser.rl"
74
- { MARK(parser, p); }
74
+ {MARK(parser, p); }
75
75
  goto st2;
76
76
  st2:
77
77
  if ( ++p == pe )
@@ -117,9 +117,10 @@ case 7:
117
117
  goto tr33;
118
118
  goto st1;
119
119
  tr33:
120
- #line 29 "ext/http11/http11_parser.rl"
120
+ #line 30 "ext/http11/http11_parser.rl"
121
121
  {
122
- if(parser->request_method != NULL)
122
+ assert(p - parser->mark >= 0 && "buffer overflow");
123
+ if(parser->request_method != NULL)
123
124
  parser->request_method(parser->data, parser->mark, p - parser->mark);
124
125
  }
125
126
  goto st8;
@@ -127,7 +128,7 @@ st8:
127
128
  if ( ++p == pe )
128
129
  goto _out8;
129
130
  case 8:
130
- #line 131 "ext/http11/http11_parser.c"
131
+ #line 132 "ext/http11/http11_parser.c"
131
132
  switch( (*p) ) {
132
133
  case 42: goto tr27;
133
134
  case 43: goto tr28;
@@ -145,26 +146,28 @@ case 8:
145
146
  goto st1;
146
147
  tr27:
147
148
  #line 14 "ext/http11/http11_parser.rl"
148
- { MARK(parser, p); }
149
+ {MARK(parser, p); }
149
150
  goto st9;
150
151
  st9:
151
152
  if ( ++p == pe )
152
153
  goto _out9;
153
154
  case 9:
154
- #line 155 "ext/http11/http11_parser.c"
155
+ #line 156 "ext/http11/http11_parser.c"
155
156
  if ( (*p) == 32 )
156
157
  goto tr34;
157
158
  goto st1;
158
159
  tr34:
159
- #line 33 "ext/http11/http11_parser.rl"
160
+ #line 35 "ext/http11/http11_parser.rl"
160
161
  {
162
+ assert(p - parser->mark >= 0 && "buffer overflow");
161
163
  if(parser->request_uri != NULL)
162
164
  parser->request_uri(parser->data, parser->mark, p - parser->mark);
163
165
  }
164
166
  goto st10;
165
167
  tr46:
166
- #line 37 "ext/http11/http11_parser.rl"
168
+ #line 40 "ext/http11/http11_parser.rl"
167
169
  {
170
+ assert(p - parser->mark >= 0 && "buffer overflow");
168
171
  if(parser->query_string != NULL)
169
172
  parser->query_string(parser->data, parser->mark, p - parser->mark);
170
173
  }
@@ -173,19 +176,19 @@ st10:
173
176
  if ( ++p == pe )
174
177
  goto _out10;
175
178
  case 10:
176
- #line 177 "ext/http11/http11_parser.c"
179
+ #line 180 "ext/http11/http11_parser.c"
177
180
  if ( (*p) == 72 )
178
181
  goto tr11;
179
182
  goto st1;
180
183
  tr11:
181
184
  #line 14 "ext/http11/http11_parser.rl"
182
- { MARK(parser, p); }
185
+ {MARK(parser, p); }
183
186
  goto st11;
184
187
  st11:
185
188
  if ( ++p == pe )
186
189
  goto _out11;
187
190
  case 11:
188
- #line 189 "ext/http11/http11_parser.c"
191
+ #line 192 "ext/http11/http11_parser.c"
189
192
  if ( (*p) == 84 )
190
193
  goto st12;
191
194
  goto st1;
@@ -243,8 +246,9 @@ case 18:
243
246
  goto st18;
244
247
  goto st1;
245
248
  tr37:
246
- #line 42 "ext/http11/http11_parser.rl"
249
+ #line 46 "ext/http11/http11_parser.rl"
247
250
  {
251
+ assert(p - parser->mark >= 0 && "buffer overflow");
248
252
  if(parser->http_version != NULL)
249
253
  parser->http_version(parser->data, parser->mark, p - parser->mark);
250
254
  }
@@ -252,6 +256,7 @@ tr37:
252
256
  tr49:
253
257
  #line 22 "ext/http11/http11_parser.rl"
254
258
  {
259
+ assert(p - (parser->mark - 1) >= 0 && "buffer overflow");
255
260
  if(parser->http_field != NULL) {
256
261
  parser->http_field(parser->data,
257
262
  parser->field_start, parser->field_len,
@@ -263,7 +268,7 @@ st19:
263
268
  if ( ++p == pe )
264
269
  goto _out19;
265
270
  case 19:
266
- #line 267 "ext/http11/http11_parser.c"
271
+ #line 272 "ext/http11/http11_parser.c"
267
272
  if ( (*p) == 10 )
268
273
  goto st20;
269
274
  goto st1;
@@ -303,7 +308,7 @@ case 21:
303
308
  goto tr40;
304
309
  goto st1;
305
310
  tr40:
306
- #line 46 "ext/http11/http11_parser.rl"
311
+ #line 52 "ext/http11/http11_parser.rl"
307
312
  {
308
313
  parser->body_start = p+1;
309
314
  if(parser->header_done != NULL)
@@ -315,7 +320,7 @@ st53:
315
320
  if ( ++p == pe )
316
321
  goto _out53;
317
322
  case 53:
318
- #line 319 "ext/http11/http11_parser.c"
323
+ #line 324 "ext/http11/http11_parser.c"
319
324
  goto st1;
320
325
  tr36:
321
326
  #line 16 "ext/http11/http11_parser.rl"
@@ -325,7 +330,7 @@ st22:
325
330
  if ( ++p == pe )
326
331
  goto _out22;
327
332
  case 22:
328
- #line 329 "ext/http11/http11_parser.c"
333
+ #line 334 "ext/http11/http11_parser.c"
329
334
  switch( (*p) ) {
330
335
  case 33: goto st22;
331
336
  case 58: goto tr32;
@@ -360,7 +365,7 @@ st23:
360
365
  if ( ++p == pe )
361
366
  goto _out23;
362
367
  case 23:
363
- #line 364 "ext/http11/http11_parser.c"
368
+ #line 369 "ext/http11/http11_parser.c"
364
369
  if ( (*p) == 13 )
365
370
  goto tr49;
366
371
  goto tr52;
@@ -372,19 +377,19 @@ st24:
372
377
  if ( ++p == pe )
373
378
  goto _out24;
374
379
  case 24:
375
- #line 376 "ext/http11/http11_parser.c"
380
+ #line 381 "ext/http11/http11_parser.c"
376
381
  if ( (*p) == 13 )
377
382
  goto tr49;
378
383
  goto st24;
379
384
  tr28:
380
385
  #line 14 "ext/http11/http11_parser.rl"
381
- { MARK(parser, p); }
386
+ {MARK(parser, p); }
382
387
  goto st25;
383
388
  st25:
384
389
  if ( ++p == pe )
385
390
  goto _out25;
386
391
  case 25:
387
- #line 388 "ext/http11/http11_parser.c"
392
+ #line 393 "ext/http11/http11_parser.c"
388
393
  switch( (*p) ) {
389
394
  case 43: goto st25;
390
395
  case 58: goto st26;
@@ -403,13 +408,13 @@ case 25:
403
408
  goto st1;
404
409
  tr30:
405
410
  #line 14 "ext/http11/http11_parser.rl"
406
- { MARK(parser, p); }
411
+ {MARK(parser, p); }
407
412
  goto st26;
408
413
  st26:
409
414
  if ( ++p == pe )
410
415
  goto _out26;
411
416
  case 26:
412
- #line 413 "ext/http11/http11_parser.c"
417
+ #line 418 "ext/http11/http11_parser.c"
413
418
  switch( (*p) ) {
414
419
  case 32: goto tr34;
415
420
  case 37: goto st27;
@@ -451,20 +456,20 @@ case 28:
451
456
  goto st1;
452
457
  tr29:
453
458
  #line 14 "ext/http11/http11_parser.rl"
454
- { MARK(parser, p); }
459
+ {MARK(parser, p); }
455
460
  goto st29;
456
461
  st29:
457
462
  if ( ++p == pe )
458
463
  goto _out29;
459
464
  case 29:
460
- #line 461 "ext/http11/http11_parser.c"
465
+ #line 466 "ext/http11/http11_parser.c"
461
466
  switch( (*p) ) {
462
467
  case 32: goto tr34;
463
468
  case 37: goto st31;
464
469
  case 47: goto st1;
465
470
  case 60: goto st1;
466
471
  case 62: goto st1;
467
- case 63: goto tr44;
472
+ case 63: goto tr43;
468
473
  case 127: goto st1;
469
474
  }
470
475
  if ( (*p) > 31 ) {
@@ -482,7 +487,7 @@ case 30:
482
487
  case 37: goto st31;
483
488
  case 60: goto st1;
484
489
  case 62: goto st1;
485
- case 63: goto tr44;
490
+ case 63: goto tr43;
486
491
  case 127: goto st1;
487
492
  }
488
493
  if ( (*p) > 31 ) {
@@ -517,9 +522,10 @@ case 32:
517
522
  } else
518
523
  goto st30;
519
524
  goto st1;
520
- tr44:
521
- #line 33 "ext/http11/http11_parser.rl"
525
+ tr43:
526
+ #line 35 "ext/http11/http11_parser.rl"
522
527
  {
528
+ assert(p - parser->mark >= 0 && "buffer overflow");
523
529
  if(parser->request_uri != NULL)
524
530
  parser->request_uri(parser->data, parser->mark, p - parser->mark);
525
531
  }
@@ -528,7 +534,7 @@ st33:
528
534
  if ( ++p == pe )
529
535
  goto _out33;
530
536
  case 33:
531
- #line 532 "ext/http11/http11_parser.c"
537
+ #line 538 "ext/http11/http11_parser.c"
532
538
  switch( (*p) ) {
533
539
  case 32: goto tr46;
534
540
  case 37: goto tr51;
@@ -544,13 +550,13 @@ case 33:
544
550
  goto tr50;
545
551
  tr50:
546
552
  #line 14 "ext/http11/http11_parser.rl"
547
- { MARK(parser, p); }
553
+ {MARK(parser, p); }
548
554
  goto st34;
549
555
  st34:
550
556
  if ( ++p == pe )
551
557
  goto _out34;
552
558
  case 34:
553
- #line 554 "ext/http11/http11_parser.c"
559
+ #line 560 "ext/http11/http11_parser.c"
554
560
  switch( (*p) ) {
555
561
  case 32: goto tr46;
556
562
  case 37: goto st35;
@@ -566,13 +572,13 @@ case 34:
566
572
  goto st34;
567
573
  tr51:
568
574
  #line 14 "ext/http11/http11_parser.rl"
569
- { MARK(parser, p); }
575
+ {MARK(parser, p); }
570
576
  goto st35;
571
577
  st35:
572
578
  if ( ++p == pe )
573
579
  goto _out35;
574
580
  case 35:
575
- #line 576 "ext/http11/http11_parser.c"
581
+ #line 582 "ext/http11/http11_parser.c"
576
582
  if ( (*p) < 65 ) {
577
583
  if ( 48 <= (*p) && (*p) <= 57 )
578
584
  goto st36;
@@ -597,13 +603,13 @@ case 36:
597
603
  goto st1;
598
604
  tr14:
599
605
  #line 14 "ext/http11/http11_parser.rl"
600
- { MARK(parser, p); }
606
+ {MARK(parser, p); }
601
607
  goto st37;
602
608
  st37:
603
609
  if ( ++p == pe )
604
610
  goto _out37;
605
611
  case 37:
606
- #line 607 "ext/http11/http11_parser.c"
612
+ #line 613 "ext/http11/http11_parser.c"
607
613
  if ( (*p) == 69 )
608
614
  goto st38;
609
615
  goto st1;
@@ -616,13 +622,13 @@ case 38:
616
622
  goto st1;
617
623
  tr15:
618
624
  #line 14 "ext/http11/http11_parser.rl"
619
- { MARK(parser, p); }
625
+ {MARK(parser, p); }
620
626
  goto st39;
621
627
  st39:
622
628
  if ( ++p == pe )
623
629
  goto _out39;
624
630
  case 39:
625
- #line 626 "ext/http11/http11_parser.c"
631
+ #line 632 "ext/http11/http11_parser.c"
626
632
  if ( (*p) == 69 )
627
633
  goto st40;
628
634
  goto st1;
@@ -642,13 +648,13 @@ case 41:
642
648
  goto st1;
643
649
  tr16:
644
650
  #line 14 "ext/http11/http11_parser.rl"
645
- { MARK(parser, p); }
651
+ {MARK(parser, p); }
646
652
  goto st42;
647
653
  st42:
648
654
  if ( ++p == pe )
649
655
  goto _out42;
650
656
  case 42:
651
- #line 652 "ext/http11/http11_parser.c"
657
+ #line 658 "ext/http11/http11_parser.c"
652
658
  if ( (*p) == 80 )
653
659
  goto st43;
654
660
  goto st1;
@@ -689,13 +695,13 @@ case 47:
689
695
  goto st1;
690
696
  tr17:
691
697
  #line 14 "ext/http11/http11_parser.rl"
692
- { MARK(parser, p); }
698
+ {MARK(parser, p); }
693
699
  goto st48;
694
700
  st48:
695
701
  if ( ++p == pe )
696
702
  goto _out48;
697
703
  case 48:
698
- #line 699 "ext/http11/http11_parser.c"
704
+ #line 705 "ext/http11/http11_parser.c"
699
705
  switch( (*p) ) {
700
706
  case 79: goto st49;
701
707
  case 85: goto st38;
@@ -710,13 +716,13 @@ case 49:
710
716
  goto st1;
711
717
  tr18:
712
718
  #line 14 "ext/http11/http11_parser.rl"
713
- { MARK(parser, p); }
719
+ {MARK(parser, p); }
714
720
  goto st50;
715
721
  st50:
716
722
  if ( ++p == pe )
717
723
  goto _out50;
718
724
  case 50:
719
- #line 720 "ext/http11/http11_parser.c"
725
+ #line 726 "ext/http11/http11_parser.c"
720
726
  if ( (*p) == 82 )
721
727
  goto st51;
722
728
  goto st1;
@@ -791,15 +797,15 @@ case 52:
791
797
 
792
798
  _out: {}
793
799
  }
794
- #line 128 "ext/http11/http11_parser.rl"
800
+ #line 134 "ext/http11/http11_parser.rl"
795
801
 
796
802
  parser->cs = cs;
797
803
  parser->nread = p - buffer;
798
804
  if(parser->body_start) {
799
805
  /* final \r\n combo encountered so stop right here */
800
806
 
801
- #line 802 "ext/http11/http11_parser.c"
802
- #line 134 "ext/http11/http11_parser.rl"
807
+ #line 808 "ext/http11/http11_parser.c"
808
+ #line 140 "ext/http11/http11_parser.rl"
803
809
  parser->nread++;
804
810
  }
805
811
 
@@ -811,8 +817,8 @@ int http_parser_finish(http_parser *parser)
811
817
  int cs = parser->cs;
812
818
 
813
819
 
814
- #line 815 "ext/http11/http11_parser.c"
815
- #line 145 "ext/http11/http11_parser.rl"
820
+ #line 821 "ext/http11/http11_parser.c"
821
+ #line 151 "ext/http11/http11_parser.rl"
816
822
 
817
823
  parser->cs = cs;
818
824
 
@@ -99,7 +99,7 @@ module Mongrel
99
99
  # The original URI requested by the client. Passed to URIClassifier to build PATH_INFO and SCRIPT_NAME.
100
100
  REQUEST_URI='REQUEST_URI'.freeze
101
101
 
102
- MONGREL_VERSION="0.3.12".freeze
102
+ MONGREL_VERSION="0.3.12.1".freeze
103
103
 
104
104
  # The standard empty 404 response for bad requests. Use Error4040Handler for custom stuff.
105
105
  ERROR_404_RESPONSE="HTTP/1.1 404 Not Found\r\nConnection: close\r\nServer: #{MONGREL_VERSION}\r\n\r\nNOT FOUND".freeze
@@ -110,7 +110,11 @@ module Mongrel
110
110
  ERROR_503_RESPONSE="HTTP/1.1 503 Service Unavailable\r\n\r\nBUSY".freeze
111
111
 
112
112
  # The basic max request size we'll try to read.
113
- CHUNK_SIZE=(16 * 1024)
113
+ CHUNK_SIZE=(4 * 1024)
114
+
115
+ # This is the maximum header that is allowed before a client is booted. The parser detects
116
+ # this, but we'd also like to do this as well.
117
+ MAX_HEADER=1024 * (80 + 32)
114
118
 
115
119
  # Format to generate a correct RFC 1123 date. rdoc for Time is wrong, there is no httpdate function.
116
120
  RFC_1123_DATE_FORMAT="%a, %d %B %Y %H:%M:%S GMT".freeze
@@ -128,6 +132,8 @@ module Mongrel
128
132
  ETAG_FORMAT="\"%x-%x-%x\"".freeze
129
133
  HEADER_FORMAT="%s: %s\r\n".freeze
130
134
  LINE_END="\r\n".freeze
135
+ REMOTE_ADDR="REMOTE_ADDR".freeze
136
+ HTTP_X_FORWARDED_FOR="HTTP_X_FORWARDED_FOR".freeze
131
137
  end
132
138
 
133
139
 
@@ -257,13 +263,12 @@ module Mongrel
257
263
  attr_reader :header_sent
258
264
  attr_reader :status_sent
259
265
 
260
- def initialize(socket, filter = nil)
266
+ def initialize(socket)
261
267
  @socket = socket
262
268
  @body = StringIO.new
263
269
  @status = 404
264
270
  @header = HeaderOut.new(StringIO.new)
265
271
  @header[Const::DATE] = HttpServer.httpdate(Time.now)
266
- @filter = filter
267
272
  @body_sent = false
268
273
  @header_sent = false
269
274
  @status_sent = false
@@ -341,6 +346,8 @@ module Mongrel
341
346
  end
342
347
 
343
348
 
349
+
350
+
344
351
  # This is the main driver of Mongrel, while the Mognrel::HttpParser and Mongrel::URIClassifier
345
352
  # make up the majority of how the server functions. It's a very simple class that just
346
353
  # has a thread accepting connections and a simple HttpServer.process_client function
@@ -409,7 +416,7 @@ module Mongrel
409
416
  if handlers
410
417
  params[Const::PATH_INFO] = path_info
411
418
  params[Const::SCRIPT_NAME] = script_name
412
-
419
+ params[Const::REMOTE_ADDR] = params[Const::HTTP_X_FORWARDED_FOR] || client.peeraddr.last
413
420
  request = HttpRequest.new(params, data[nread ... data.length], client)
414
421
  response = HttpResponse.new(client)
415
422
 
@@ -430,14 +437,21 @@ module Mongrel
430
437
  else
431
438
  # gotta stream and read again until we can get the parser to be character safe
432
439
  # TODO: make this more efficient since this means we're parsing a lot repeatedly
440
+ if data.length >= Const::MAX_HEADER
441
+ raise HttpParserError.new("HEADER is longer than allowed, aborting client early.")
442
+ end
443
+
433
444
  parser.reset
434
445
  data << client.readpartial(Const::CHUNK_SIZE)
435
446
  end
436
447
  end
437
448
  rescue EOFError,Errno::ECONNRESET,Errno::EPIPE,Errno::EINVAL
438
449
  # ignored
450
+ rescue HttpParserError
451
+ STDERR.puts "BAD CLIENT (#{client.peeraddr.last}): #$!"
452
+ STDERR.puts "REQUEST DATA: #{data}"
439
453
  rescue => details
440
- STDERR.puts "ERROR(#{details.class}): #{details}"
454
+ STDERR.puts "ERROR: #$!"
441
455
  STDERR.puts details.backtrace.join("\n")
442
456
  ensure
443
457
  client.close
@@ -510,14 +524,20 @@ module Mongrel
510
524
  # Simply registers a handler with the internal URIClassifier. When the URI is
511
525
  # found in the prefix of a request then your handler's HttpHandler::process method
512
526
  # is called. See Mongrel::URIClassifier#register for more information.
513
- def register(uri, handler)
527
+ #
528
+ # If you set in_front=true then the passed in handler will be put in front in the list.
529
+ def register(uri, handler, in_front=false)
514
530
  script_name, path_info, handlers = @classifier.resolve(uri)
515
531
 
516
532
  if not handlers
517
533
  @classifier.register(uri, [handler])
518
534
  else
519
535
  if path_info.length == 0 or (script_name == Const::SLASH and path_info == Const::SLASH)
520
- handlers << handler
536
+ if in_front
537
+ handlers.unshift(handler)
538
+ else
539
+ handlers << handler
540
+ end
521
541
  else
522
542
  @classifier.register(uri, [handler])
523
543
  end
@@ -648,7 +668,7 @@ module Mongrel
648
668
  # * :handler => Handler to use for this location.
649
669
  def uri(location, options={})
650
670
  ops = resolve_defaults(options)
651
- @listener.register(location, ops[:handler])
671
+ @listener.register(location, ops[:handler], in_front=ops[:in_front])
652
672
  end
653
673
 
654
674
 
@@ -723,7 +743,6 @@ module Mongrel
723
743
  # is organized.
724
744
  def load_mime_map(file, mime={})
725
745
  # configure any requested mime map
726
- log "Loading additional MIME types from #{file}"
727
746
  mime = load_yaml(file, mime)
728
747
 
729
748
  # check all the mime types to make sure they are the right format
@@ -784,11 +803,19 @@ module Mongrel
784
803
  MongrelDbg.begin_trace :rails
785
804
  MongrelDbg.begin_trace :files
786
805
 
806
+ uri location, :handler => plugin("/handlers/requestlog::access")
787
807
  uri location, :handler => plugin("/handlers/requestlog::files")
788
808
  uri location, :handler => plugin("/handlers/requestlog::objects")
789
809
  uri location, :handler => plugin("/handlers/requestlog::params")
790
810
  end
791
811
 
812
+ # Used to allow you to let users specify their own configurations
813
+ # inside your Configurator setup. You pass it a script name and
814
+ # reads it in and does an eval on the contents passing in the right
815
+ # binding so they can put their own Configurator statements.
816
+ def run_config(script)
817
+ open(script) {|f| eval(f.read, proc {self}) }
818
+ end
792
819
 
793
820
  # Sets up the standard signal handlers that are used on most Ruby
794
821
  # It only configures if the platform is not win32 and doesn't do