puma 3.12.6 → 4.3.10
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of puma might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/History.md +145 -3
- data/README.md +76 -48
- data/docs/architecture.md +1 -0
- data/docs/deployment.md +24 -4
- data/docs/images/puma-connection-flow-no-reactor.png +0 -0
- data/docs/images/puma-connection-flow.png +0 -0
- data/docs/images/puma-general-arch.png +0 -0
- data/docs/plugins.md +20 -10
- data/docs/restart.md +4 -2
- data/docs/systemd.md +27 -9
- data/docs/tcp_mode.md +96 -0
- data/ext/puma_http11/PumaHttp11Service.java +2 -0
- data/ext/puma_http11/extconf.rb +13 -0
- data/ext/puma_http11/http11_parser.c +58 -70
- data/ext/puma_http11/http11_parser.java.rl +21 -37
- data/ext/puma_http11/http11_parser_common.rl +4 -4
- data/ext/puma_http11/mini_ssl.c +78 -8
- data/ext/puma_http11/org/jruby/puma/Http11.java +106 -114
- data/ext/puma_http11/org/jruby/puma/Http11Parser.java +86 -99
- data/ext/puma_http11/org/jruby/puma/IOBuffer.java +72 -0
- data/ext/puma_http11/org/jruby/puma/MiniSSL.java +15 -4
- data/ext/puma_http11/puma_http11.c +3 -0
- data/lib/puma/accept_nonblock.rb +7 -1
- data/lib/puma/app/status.rb +37 -29
- data/lib/puma/binder.rb +38 -60
- data/lib/puma/cli.rb +4 -0
- data/lib/puma/client.rb +242 -208
- data/lib/puma/cluster.rb +53 -30
- data/lib/puma/configuration.rb +4 -3
- data/lib/puma/const.rb +22 -18
- data/lib/puma/control_cli.rb +30 -5
- data/lib/puma/dsl.rb +299 -75
- data/lib/puma/events.rb +4 -1
- data/lib/puma/io_buffer.rb +1 -6
- data/lib/puma/launcher.rb +95 -53
- data/lib/puma/minissl/context_builder.rb +76 -0
- data/lib/puma/minissl.rb +35 -17
- data/lib/puma/plugin/tmp_restart.rb +2 -0
- data/lib/puma/plugin.rb +5 -2
- data/lib/puma/rack/builder.rb +2 -0
- data/lib/puma/rack/urlmap.rb +2 -0
- data/lib/puma/rack_default.rb +2 -0
- data/lib/puma/reactor.rb +110 -57
- data/lib/puma/runner.rb +11 -3
- data/lib/puma/server.rb +73 -57
- data/lib/puma/single.rb +3 -3
- data/lib/puma/thread_pool.rb +15 -33
- data/lib/puma/util.rb +1 -6
- data/lib/puma.rb +8 -0
- data/lib/rack/handler/puma.rb +3 -3
- data/tools/docker/Dockerfile +16 -0
- data/tools/jungle/init.d/puma +6 -6
- data/tools/trickletest.rb +0 -1
- metadata +26 -13
- data/lib/puma/compat.rb +0 -14
- data/lib/puma/convenient.rb +0 -25
- data/lib/puma/daemon_ext.rb +0 -33
- data/lib/puma/delegation.rb +0 -13
- data/lib/puma/java_io_buffer.rb +0 -47
- data/lib/puma/rack/backports/uri/common_193.rb +0 -33
data/docs/systemd.md
CHANGED
@@ -32,21 +32,26 @@ Type=simple
|
|
32
32
|
# Preferably configure a non-privileged user
|
33
33
|
# User=
|
34
34
|
|
35
|
-
# The path to the
|
36
|
-
# Also replace the "<
|
37
|
-
|
35
|
+
# The path to the your application code root directory.
|
36
|
+
# Also replace the "<YOUR_APP_PATH>" place holders below with this path.
|
37
|
+
# Example /home/username/myapp
|
38
|
+
WorkingDirectory=<YOUR_APP_PATH>
|
38
39
|
|
39
40
|
# Helpful for debugging socket activation, etc.
|
40
41
|
# Environment=PUMA_DEBUG=1
|
41
42
|
|
42
|
-
#
|
43
|
-
#
|
44
|
-
#
|
45
|
-
ExecStart
|
43
|
+
# SystemD will not run puma even if it is in your path. You must specify
|
44
|
+
# an absolute URL to puma. For example /usr/local/bin/puma
|
45
|
+
# Alternatively, create a binstub with `bundle binstubs puma --path ./sbin` in the WorkingDirectory
|
46
|
+
ExecStart=/<FULLPATH>/bin/puma -C <YOUR_APP_PATH>/puma.rb
|
47
|
+
|
48
|
+
# Variant: Rails start.
|
49
|
+
# ExecStart=/<FULLPATH>/bin/puma -C <YOUR_APP_PATH>/config/puma.rb ../config.ru
|
46
50
|
|
47
|
-
# Variant: Use config file with `bind` directives instead:
|
48
|
-
# ExecStart=<WD>/sbin/puma -C config.rb
|
49
51
|
# Variant: Use `bundle exec --keep-file-descriptors puma` instead of binstub
|
52
|
+
# Variant: Specify directives inline.
|
53
|
+
# ExecStart=/<FULLPATH>/puma -b tcp://0.0.0.0:9292 -b ssl://0.0.0.0:9293?key=key.pem&cert=cert.pem
|
54
|
+
|
50
55
|
|
51
56
|
Restart=always
|
52
57
|
|
@@ -66,6 +71,13 @@ listening sockets open across puma restarts and achieves graceful
|
|
66
71
|
restarts, including when upgraded puma, and is compatible with both
|
67
72
|
clustered mode and application preload.
|
68
73
|
|
74
|
+
**Note:** Any wrapper scripts which `exec`, or other indirections in
|
75
|
+
`ExecStart`, may result in activated socket file descriptors being closed
|
76
|
+
before they reach the puma master process. For example, if using `bundle exec`,
|
77
|
+
pass the `--keep-file-descriptors` flag. `bundle exec` can be avoided by using a
|
78
|
+
`puma` executable generated by `bundle binstubs puma`. This is tracked in
|
79
|
+
[#1499].
|
80
|
+
|
69
81
|
**Note:** Socket activation doesn't currently work on jruby. This is
|
70
82
|
tracked in [#1367].
|
71
83
|
|
@@ -247,6 +259,12 @@ PIDFile=<WD>/shared/tmp/pids/puma.pid
|
|
247
259
|
# reconsider if you actually need the forking config.
|
248
260
|
Restart=no
|
249
261
|
|
262
|
+
# `puma_ctl restart` wouldn't work without this. It's because `pumactl`
|
263
|
+
# changes PID on restart and systemd stops the service afterwards
|
264
|
+
# because of the PID change. This option prevents stopping after PID
|
265
|
+
# change.
|
266
|
+
RemainAfterExit=yes
|
267
|
+
|
250
268
|
[Install]
|
251
269
|
WantedBy=multi-user.target
|
252
270
|
~~~~
|
data/docs/tcp_mode.md
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
# TCP mode
|
2
|
+
|
3
|
+
Puma also could be used as a TCP server to process incoming TCP
|
4
|
+
connections.
|
5
|
+
|
6
|
+
|
7
|
+
## Configuration
|
8
|
+
|
9
|
+
TCP mode can be enabled with CLI option `--tcp-mode`:
|
10
|
+
|
11
|
+
```
|
12
|
+
$ puma --tcp-mode
|
13
|
+
```
|
14
|
+
|
15
|
+
Default ip and port to listen to are `0.0.0.0` and `9292`. You can configure
|
16
|
+
them with `--port` and `--bind` options:
|
17
|
+
|
18
|
+
```
|
19
|
+
$ puma --tcp-mode --bind tcp://127.0.0.1:9293
|
20
|
+
$ puma --tcp-mode --port 9293
|
21
|
+
```
|
22
|
+
|
23
|
+
TCP mode could be set with a configuration file as well with `tcp_mode`
|
24
|
+
and `tcp_mode!` methods:
|
25
|
+
|
26
|
+
```
|
27
|
+
# config/puma.rb
|
28
|
+
tcp_mode
|
29
|
+
```
|
30
|
+
|
31
|
+
When Puma starts in the TCP mode it prints the corresponding message:
|
32
|
+
|
33
|
+
```
|
34
|
+
puma --tcp-mode
|
35
|
+
Puma starting in single mode...
|
36
|
+
...
|
37
|
+
* Mode: Lopez Express (tcp)
|
38
|
+
```
|
39
|
+
|
40
|
+
|
41
|
+
## How to declare an application
|
42
|
+
|
43
|
+
An application to process TCP connections should be declared as a
|
44
|
+
callable object which accepts `env` and `socket` arguments.
|
45
|
+
|
46
|
+
`env` argument is a Hash with following structure:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
{ "thread" => {}, "REMOTE_ADDR" => "127.0.0.1:51133", "log" => "#<Proc:0x000..." }
|
50
|
+
```
|
51
|
+
|
52
|
+
It consists of:
|
53
|
+
* `thread` - a Hash for each thread in the thread pool that could be
|
54
|
+
used to store information between requests
|
55
|
+
* `REMOTE_ADDR` - a client ip address
|
56
|
+
* `log` - a proc object to write something down
|
57
|
+
|
58
|
+
`log` object could be used this way:
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
env['log'].call('message to log')
|
62
|
+
#> 19/Oct/2019 20:28:53 - 127.0.0.1:51266 - message to log
|
63
|
+
```
|
64
|
+
|
65
|
+
|
66
|
+
## Example of an application
|
67
|
+
|
68
|
+
Let's look at an example of a simple application which just echoes
|
69
|
+
incoming string:
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
# config/puma.rb
|
73
|
+
app do |env, socket|
|
74
|
+
s = socket.gets
|
75
|
+
socket.puts "Echo #{s}"
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
79
|
+
We can easily access the TCP server with `telnet` command and receive an
|
80
|
+
echo:
|
81
|
+
|
82
|
+
```shell
|
83
|
+
telnet 0.0.0.0 9293
|
84
|
+
Trying 0.0.0.0...
|
85
|
+
Connected to 0.0.0.0.
|
86
|
+
Escape character is '^]'.
|
87
|
+
sssss
|
88
|
+
Echo sssss
|
89
|
+
^CConnection closed by foreign host.
|
90
|
+
```
|
91
|
+
|
92
|
+
|
93
|
+
## Socket management
|
94
|
+
|
95
|
+
After the application finishes, Puma closes the socket. In order to
|
96
|
+
prevent this, the application should set `env['detach'] = true`.
|
@@ -6,11 +6,13 @@ import org.jruby.Ruby;
|
|
6
6
|
import org.jruby.runtime.load.BasicLibraryService;
|
7
7
|
|
8
8
|
import org.jruby.puma.Http11;
|
9
|
+
import org.jruby.puma.IOBuffer;
|
9
10
|
import org.jruby.puma.MiniSSL;
|
10
11
|
|
11
12
|
public class PumaHttp11Service implements BasicLibraryService {
|
12
13
|
public boolean basicLoad(final Ruby runtime) throws IOException {
|
13
14
|
Http11.createHttp11(runtime);
|
15
|
+
IOBuffer.createIOBuffer(runtime);
|
14
16
|
MiniSSL.createMiniSSL(runtime);
|
15
17
|
return true;
|
16
18
|
}
|
data/ext/puma_http11/extconf.rb
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
require 'mkmf'
|
2
2
|
|
3
3
|
dir_config("puma_http11")
|
4
|
+
if $mingw && RUBY_VERSION >= '2.4'
|
5
|
+
append_cflags '-D_FORTIFY_SOURCE=2'
|
6
|
+
append_ldflags '-fstack-protector'
|
7
|
+
have_library 'ssp'
|
8
|
+
end
|
4
9
|
|
5
10
|
unless ENV["DISABLE_SSL"]
|
6
11
|
dir_config("openssl")
|
@@ -9,6 +14,14 @@ unless ENV["DISABLE_SSL"]
|
|
9
14
|
%w'ssl ssleay32'.find {|ssl| have_library(ssl, 'SSL_CTX_new')}
|
10
15
|
|
11
16
|
have_header "openssl/bio.h"
|
17
|
+
|
18
|
+
# below is yes for 1.0.2 & later
|
19
|
+
have_func "DTLS_method" , "openssl/ssl.h"
|
20
|
+
|
21
|
+
# below are yes for 1.1.0 & later, may need to check func rather than macro
|
22
|
+
# with versions after 1.1.1
|
23
|
+
have_func "TLS_server_method" , "openssl/ssl.h"
|
24
|
+
have_macro "SSL_CTX_set_min_proto_version", "openssl/ssl.h"
|
12
25
|
end
|
13
26
|
end
|
14
27
|
|
@@ -40,7 +40,7 @@ static void snake_upcase_char(char *c)
|
|
40
40
|
|
41
41
|
#line 40 "ext/puma_http11/http11_parser.c"
|
42
42
|
static const int puma_parser_start = 1;
|
43
|
-
static const int puma_parser_first_final =
|
43
|
+
static const int puma_parser_first_final = 46;
|
44
44
|
static const int puma_parser_error = 0;
|
45
45
|
|
46
46
|
static const int puma_parser_en_main = 1;
|
@@ -119,17 +119,17 @@ case 2:
|
|
119
119
|
#line 118 "ext/puma_http11/http11_parser.c"
|
120
120
|
switch( (*p) ) {
|
121
121
|
case 32: goto tr2;
|
122
|
-
case 36: goto
|
123
|
-
case 95: goto
|
122
|
+
case 36: goto st27;
|
123
|
+
case 95: goto st27;
|
124
124
|
}
|
125
125
|
if ( (*p) < 48 ) {
|
126
126
|
if ( 45 <= (*p) && (*p) <= 46 )
|
127
|
-
goto
|
127
|
+
goto st27;
|
128
128
|
} else if ( (*p) > 57 ) {
|
129
129
|
if ( 65 <= (*p) && (*p) <= 90 )
|
130
|
-
goto
|
130
|
+
goto st27;
|
131
131
|
} else
|
132
|
-
goto
|
132
|
+
goto st27;
|
133
133
|
goto st0;
|
134
134
|
tr2:
|
135
135
|
#line 48 "ext/puma_http11/http11_parser.rl"
|
@@ -201,7 +201,7 @@ tr37:
|
|
201
201
|
parser->request_uri(parser, PTR_TO(mark), LEN(mark, p));
|
202
202
|
}
|
203
203
|
goto st5;
|
204
|
-
|
204
|
+
tr41:
|
205
205
|
#line 58 "ext/puma_http11/http11_parser.rl"
|
206
206
|
{ MARK(query_start, p); }
|
207
207
|
#line 59 "ext/puma_http11/http11_parser.rl"
|
@@ -213,7 +213,7 @@ tr44:
|
|
213
213
|
parser->request_uri(parser, PTR_TO(mark), LEN(mark, p));
|
214
214
|
}
|
215
215
|
goto st5;
|
216
|
-
|
216
|
+
tr44:
|
217
217
|
#line 59 "ext/puma_http11/http11_parser.rl"
|
218
218
|
{
|
219
219
|
parser->query_string(parser, PTR_TO(query_start), LEN(query_start, p));
|
@@ -364,13 +364,13 @@ tr22:
|
|
364
364
|
{
|
365
365
|
parser->body_start = p - buffer + 1;
|
366
366
|
parser->header_done(parser, p + 1, pe - p - 1);
|
367
|
-
{p++; cs =
|
367
|
+
{p++; cs = 46; goto _out;}
|
368
368
|
}
|
369
|
-
goto
|
370
|
-
|
369
|
+
goto st46;
|
370
|
+
st46:
|
371
371
|
if ( ++p == pe )
|
372
|
-
goto
|
373
|
-
case
|
372
|
+
goto _test_eof46;
|
373
|
+
case 46:
|
374
374
|
#line 373 "ext/puma_http11/http11_parser.c"
|
375
375
|
goto st0;
|
376
376
|
tr21:
|
@@ -430,7 +430,13 @@ case 18:
|
|
430
430
|
switch( (*p) ) {
|
431
431
|
case 13: goto tr26;
|
432
432
|
case 32: goto tr27;
|
433
|
+
case 127: goto st0;
|
433
434
|
}
|
435
|
+
if ( (*p) > 8 ) {
|
436
|
+
if ( 10 <= (*p) && (*p) <= 31 )
|
437
|
+
goto st0;
|
438
|
+
} else if ( (*p) >= 0 )
|
439
|
+
goto st0;
|
434
440
|
goto tr25;
|
435
441
|
tr25:
|
436
442
|
#line 44 "ext/puma_http11/http11_parser.rl"
|
@@ -440,9 +446,16 @@ st19:
|
|
440
446
|
if ( ++p == pe )
|
441
447
|
goto _test_eof19;
|
442
448
|
case 19:
|
443
|
-
#line
|
444
|
-
|
445
|
-
goto tr29;
|
449
|
+
#line 448 "ext/puma_http11/http11_parser.c"
|
450
|
+
switch( (*p) ) {
|
451
|
+
case 13: goto tr29;
|
452
|
+
case 127: goto st0;
|
453
|
+
}
|
454
|
+
if ( (*p) > 8 ) {
|
455
|
+
if ( 10 <= (*p) && (*p) <= 31 )
|
456
|
+
goto st0;
|
457
|
+
} else if ( (*p) >= 0 )
|
458
|
+
goto st0;
|
446
459
|
goto st19;
|
447
460
|
tr9:
|
448
461
|
#line 51 "ext/puma_http11/http11_parser.rl"
|
@@ -460,7 +473,7 @@ tr38:
|
|
460
473
|
parser->request_uri(parser, PTR_TO(mark), LEN(mark, p));
|
461
474
|
}
|
462
475
|
goto st20;
|
463
|
-
|
476
|
+
tr42:
|
464
477
|
#line 58 "ext/puma_http11/http11_parser.rl"
|
465
478
|
{ MARK(query_start, p); }
|
466
479
|
#line 59 "ext/puma_http11/http11_parser.rl"
|
@@ -472,7 +485,7 @@ tr45:
|
|
472
485
|
parser->request_uri(parser, PTR_TO(mark), LEN(mark, p));
|
473
486
|
}
|
474
487
|
goto st20;
|
475
|
-
|
488
|
+
tr45:
|
476
489
|
#line 59 "ext/puma_http11/http11_parser.rl"
|
477
490
|
{
|
478
491
|
parser->query_string(parser, PTR_TO(query_start), LEN(query_start, p));
|
@@ -486,7 +499,7 @@ st20:
|
|
486
499
|
if ( ++p == pe )
|
487
500
|
goto _test_eof20;
|
488
501
|
case 20:
|
489
|
-
#line
|
502
|
+
#line 501 "ext/puma_http11/http11_parser.c"
|
490
503
|
switch( (*p) ) {
|
491
504
|
case 32: goto tr31;
|
492
505
|
case 60: goto st0;
|
@@ -507,7 +520,7 @@ st21:
|
|
507
520
|
if ( ++p == pe )
|
508
521
|
goto _test_eof21;
|
509
522
|
case 21:
|
510
|
-
#line
|
523
|
+
#line 522 "ext/puma_http11/http11_parser.c"
|
511
524
|
switch( (*p) ) {
|
512
525
|
case 32: goto tr33;
|
513
526
|
case 60: goto st0;
|
@@ -528,7 +541,7 @@ st22:
|
|
528
541
|
if ( ++p == pe )
|
529
542
|
goto _test_eof22;
|
530
543
|
case 22:
|
531
|
-
#line
|
544
|
+
#line 543 "ext/puma_http11/http11_parser.c"
|
532
545
|
switch( (*p) ) {
|
533
546
|
case 43: goto st22;
|
534
547
|
case 58: goto st23;
|
@@ -553,7 +566,7 @@ st23:
|
|
553
566
|
if ( ++p == pe )
|
554
567
|
goto _test_eof23;
|
555
568
|
case 23:
|
556
|
-
#line
|
569
|
+
#line 568 "ext/puma_http11/http11_parser.c"
|
557
570
|
switch( (*p) ) {
|
558
571
|
case 32: goto tr8;
|
559
572
|
case 34: goto st0;
|
@@ -573,15 +586,14 @@ st24:
|
|
573
586
|
if ( ++p == pe )
|
574
587
|
goto _test_eof24;
|
575
588
|
case 24:
|
576
|
-
#line
|
589
|
+
#line 588 "ext/puma_http11/http11_parser.c"
|
577
590
|
switch( (*p) ) {
|
578
591
|
case 32: goto tr37;
|
579
592
|
case 34: goto st0;
|
580
593
|
case 35: goto tr38;
|
581
|
-
case 59: goto tr39;
|
582
594
|
case 60: goto st0;
|
583
595
|
case 62: goto st0;
|
584
|
-
case 63: goto
|
596
|
+
case 63: goto tr39;
|
585
597
|
case 127: goto st0;
|
586
598
|
}
|
587
599
|
if ( 0 <= (*p) && (*p) <= 31 )
|
@@ -597,30 +609,27 @@ st25:
|
|
597
609
|
if ( ++p == pe )
|
598
610
|
goto _test_eof25;
|
599
611
|
case 25:
|
600
|
-
#line
|
612
|
+
#line 611 "ext/puma_http11/http11_parser.c"
|
601
613
|
switch( (*p) ) {
|
602
|
-
case 32: goto
|
614
|
+
case 32: goto tr41;
|
603
615
|
case 34: goto st0;
|
604
|
-
case 35: goto
|
616
|
+
case 35: goto tr42;
|
605
617
|
case 60: goto st0;
|
606
618
|
case 62: goto st0;
|
607
|
-
case 63: goto st26;
|
608
619
|
case 127: goto st0;
|
609
620
|
}
|
610
621
|
if ( 0 <= (*p) && (*p) <= 31 )
|
611
622
|
goto st0;
|
612
|
-
goto
|
623
|
+
goto tr40;
|
613
624
|
tr40:
|
614
|
-
#line
|
615
|
-
{
|
616
|
-
parser->request_path(parser, PTR_TO(mark), LEN(mark,p));
|
617
|
-
}
|
625
|
+
#line 58 "ext/puma_http11/http11_parser.rl"
|
626
|
+
{ MARK(query_start, p); }
|
618
627
|
goto st26;
|
619
628
|
st26:
|
620
629
|
if ( ++p == pe )
|
621
630
|
goto _test_eof26;
|
622
631
|
case 26:
|
623
|
-
#line
|
632
|
+
#line 631 "ext/puma_http11/http11_parser.c"
|
624
633
|
switch( (*p) ) {
|
625
634
|
case 32: goto tr44;
|
626
635
|
case 34: goto st0;
|
@@ -631,27 +640,25 @@ case 26:
|
|
631
640
|
}
|
632
641
|
if ( 0 <= (*p) && (*p) <= 31 )
|
633
642
|
goto st0;
|
634
|
-
goto
|
635
|
-
tr43:
|
636
|
-
#line 58 "ext/puma_http11/http11_parser.rl"
|
637
|
-
{ MARK(query_start, p); }
|
638
|
-
goto st27;
|
643
|
+
goto st26;
|
639
644
|
st27:
|
640
645
|
if ( ++p == pe )
|
641
646
|
goto _test_eof27;
|
642
647
|
case 27:
|
643
|
-
#line 642 "ext/puma_http11/http11_parser.c"
|
644
648
|
switch( (*p) ) {
|
645
|
-
case 32: goto
|
646
|
-
case
|
647
|
-
case
|
648
|
-
case 60: goto st0;
|
649
|
-
case 62: goto st0;
|
650
|
-
case 127: goto st0;
|
649
|
+
case 32: goto tr2;
|
650
|
+
case 36: goto st28;
|
651
|
+
case 95: goto st28;
|
651
652
|
}
|
652
|
-
if (
|
653
|
-
|
654
|
-
|
653
|
+
if ( (*p) < 48 ) {
|
654
|
+
if ( 45 <= (*p) && (*p) <= 46 )
|
655
|
+
goto st28;
|
656
|
+
} else if ( (*p) > 57 ) {
|
657
|
+
if ( 65 <= (*p) && (*p) <= 90 )
|
658
|
+
goto st28;
|
659
|
+
} else
|
660
|
+
goto st28;
|
661
|
+
goto st0;
|
655
662
|
st28:
|
656
663
|
if ( ++p == pe )
|
657
664
|
goto _test_eof28;
|
@@ -962,24 +969,6 @@ st45:
|
|
962
969
|
if ( ++p == pe )
|
963
970
|
goto _test_eof45;
|
964
971
|
case 45:
|
965
|
-
switch( (*p) ) {
|
966
|
-
case 32: goto tr2;
|
967
|
-
case 36: goto st46;
|
968
|
-
case 95: goto st46;
|
969
|
-
}
|
970
|
-
if ( (*p) < 48 ) {
|
971
|
-
if ( 45 <= (*p) && (*p) <= 46 )
|
972
|
-
goto st46;
|
973
|
-
} else if ( (*p) > 57 ) {
|
974
|
-
if ( 65 <= (*p) && (*p) <= 90 )
|
975
|
-
goto st46;
|
976
|
-
} else
|
977
|
-
goto st46;
|
978
|
-
goto st0;
|
979
|
-
st46:
|
980
|
-
if ( ++p == pe )
|
981
|
-
goto _test_eof46;
|
982
|
-
case 46:
|
983
972
|
if ( (*p) == 32 )
|
984
973
|
goto tr2;
|
985
974
|
goto st0;
|
@@ -999,7 +988,7 @@ case 46:
|
|
999
988
|
_test_eof14: cs = 14; goto _test_eof;
|
1000
989
|
_test_eof15: cs = 15; goto _test_eof;
|
1001
990
|
_test_eof16: cs = 16; goto _test_eof;
|
1002
|
-
|
991
|
+
_test_eof46: cs = 46; goto _test_eof;
|
1003
992
|
_test_eof17: cs = 17; goto _test_eof;
|
1004
993
|
_test_eof18: cs = 18; goto _test_eof;
|
1005
994
|
_test_eof19: cs = 19; goto _test_eof;
|
@@ -1029,7 +1018,6 @@ case 46:
|
|
1029
1018
|
_test_eof43: cs = 43; goto _test_eof;
|
1030
1019
|
_test_eof44: cs = 44; goto _test_eof;
|
1031
1020
|
_test_eof45: cs = 45; goto _test_eof;
|
1032
|
-
_test_eof46: cs = 46; goto _test_eof;
|
1033
1021
|
|
1034
1022
|
_test_eof: {}
|
1035
1023
|
_out: {}
|
@@ -1,5 +1,7 @@
|
|
1
1
|
package org.jruby.puma;
|
2
2
|
|
3
|
+
import org.jruby.Ruby;
|
4
|
+
import org.jruby.RubyHash;
|
3
5
|
import org.jruby.util.ByteList;
|
4
6
|
|
5
7
|
public class Http11Parser {
|
@@ -19,44 +21,35 @@ public class Http11Parser {
|
|
19
21
|
}
|
20
22
|
|
21
23
|
action start_value { parser.mark = fpc; }
|
22
|
-
action write_value {
|
23
|
-
|
24
|
-
parser.http_field.call(parser.data, parser.field_start, parser.field_len, parser.mark, fpc-parser.mark);
|
25
|
-
}
|
24
|
+
action write_value {
|
25
|
+
Http11.http_field(runtime, parser.data, parser.buffer, parser.field_start, parser.field_len, parser.mark, fpc-parser.mark);
|
26
26
|
}
|
27
|
-
action request_method {
|
28
|
-
|
29
|
-
parser.request_method.call(parser.data, parser.mark, fpc-parser.mark);
|
27
|
+
action request_method {
|
28
|
+
Http11.request_method(runtime, parser.data, parser.buffer, parser.mark, fpc-parser.mark);
|
30
29
|
}
|
31
|
-
action request_uri {
|
32
|
-
|
33
|
-
parser.request_uri.call(parser.data, parser.mark, fpc-parser.mark);
|
30
|
+
action request_uri {
|
31
|
+
Http11.request_uri(runtime, parser.data, parser.buffer, parser.mark, fpc-parser.mark);
|
34
32
|
}
|
35
|
-
action fragment {
|
36
|
-
|
37
|
-
parser.fragment.call(parser.data, parser.mark, fpc-parser.mark);
|
33
|
+
action fragment {
|
34
|
+
Http11.fragment(runtime, parser.data, parser.buffer, parser.mark, fpc-parser.mark);
|
38
35
|
}
|
39
36
|
|
40
37
|
action start_query {parser.query_start = fpc; }
|
41
|
-
action query_string {
|
42
|
-
|
43
|
-
parser.query_string.call(parser.data, parser.query_start, fpc-parser.query_start);
|
38
|
+
action query_string {
|
39
|
+
Http11.query_string(runtime, parser.data, parser.buffer, parser.query_start, fpc-parser.query_start);
|
44
40
|
}
|
45
41
|
|
46
|
-
action http_version {
|
47
|
-
|
48
|
-
parser.http_version.call(parser.data, parser.mark, fpc-parser.mark);
|
42
|
+
action http_version {
|
43
|
+
Http11.http_version(runtime, parser.data, parser.buffer, parser.mark, fpc-parser.mark);
|
49
44
|
}
|
50
45
|
|
51
46
|
action request_path {
|
52
|
-
|
53
|
-
parser.request_path.call(parser.data, parser.mark, fpc-parser.mark);
|
47
|
+
Http11.request_path(runtime, parser.data, parser.buffer, parser.mark, fpc-parser.mark);
|
54
48
|
}
|
55
49
|
|
56
50
|
action done {
|
57
|
-
parser.body_start = fpc + 1;
|
58
|
-
|
59
|
-
parser.header_done.call(parser.data, fpc + 1, pe - fpc - 1);
|
51
|
+
parser.body_start = fpc + 1;
|
52
|
+
http.header_done(runtime, parser.data, parser.buffer, fpc + 1, pe - fpc - 1);
|
60
53
|
fbreak;
|
61
54
|
}
|
62
55
|
|
@@ -68,11 +61,11 @@ public class Http11Parser {
|
|
68
61
|
%% write data;
|
69
62
|
|
70
63
|
public static interface ElementCB {
|
71
|
-
public void call(
|
64
|
+
public void call(Ruby runtime, RubyHash data, ByteList buffer, int at, int length);
|
72
65
|
}
|
73
66
|
|
74
67
|
public static interface FieldCB {
|
75
|
-
public void call(
|
68
|
+
public void call(Ruby runtime, RubyHash data, ByteList buffer, int field, int flen, int value, int vlen);
|
76
69
|
}
|
77
70
|
|
78
71
|
public static class HttpParser {
|
@@ -85,18 +78,9 @@ public class Http11Parser {
|
|
85
78
|
int field_len;
|
86
79
|
int query_start;
|
87
80
|
|
88
|
-
|
81
|
+
RubyHash data;
|
89
82
|
ByteList buffer;
|
90
83
|
|
91
|
-
public FieldCB http_field;
|
92
|
-
public ElementCB request_method;
|
93
|
-
public ElementCB request_uri;
|
94
|
-
public ElementCB fragment;
|
95
|
-
public ElementCB request_path;
|
96
|
-
public ElementCB query_string;
|
97
|
-
public ElementCB http_version;
|
98
|
-
public ElementCB header_done;
|
99
|
-
|
100
84
|
public void init() {
|
101
85
|
cs = 0;
|
102
86
|
|
@@ -113,7 +97,7 @@ public class Http11Parser {
|
|
113
97
|
|
114
98
|
public final HttpParser parser = new HttpParser();
|
115
99
|
|
116
|
-
public int execute(ByteList buffer, int off) {
|
100
|
+
public int execute(Ruby runtime, Http11 http, ByteList buffer, int off) {
|
117
101
|
int p, pe;
|
118
102
|
int cs = parser.cs;
|
119
103
|
int len = buffer.length();
|
@@ -1,5 +1,5 @@
|
|
1
1
|
%%{
|
2
|
-
|
2
|
+
|
3
3
|
machine puma_parser_common;
|
4
4
|
|
5
5
|
#### HTTP PROTOCOL GRAMMAR
|
@@ -16,7 +16,7 @@
|
|
16
16
|
unreserved = (alpha | digit | safe | extra | national);
|
17
17
|
escape = ("%" xdigit xdigit);
|
18
18
|
uchar = (unreserved | escape | "%");
|
19
|
-
pchar = (uchar | ":" | "@" | "&" | "=" | "+");
|
19
|
+
pchar = (uchar | ":" | "@" | "&" | "=" | "+" | ";");
|
20
20
|
tspecials = ("(" | ")" | "<" | ">" | "@" | "," | ";" | ":" | "\\" | "\"" | "/" | "[" | "]" | "?" | "=" | "{" | "}" | " " | "\t");
|
21
21
|
|
22
22
|
# elements
|
@@ -30,7 +30,7 @@
|
|
30
30
|
query = ( uchar | reserved )* %query_string ;
|
31
31
|
param = ( pchar | "/" )* ;
|
32
32
|
params = ( param ( ";" param )* ) ;
|
33
|
-
rel_path = ( path? %request_path
|
33
|
+
rel_path = ( path? %request_path ) ("?" %start_query query)?;
|
34
34
|
absolute_path = ( "/"+ rel_path );
|
35
35
|
|
36
36
|
Request_URI = ( "*" | absolute_uri | absolute_path ) >mark %request_uri;
|
@@ -43,7 +43,7 @@
|
|
43
43
|
|
44
44
|
field_name = ( token -- ":" )+ >start_field $snake_upcase_field %write_field;
|
45
45
|
|
46
|
-
field_value = any* >start_value %write_value;
|
46
|
+
field_value = ( (any -- CTL) | "\t" )* >start_value %write_value;
|
47
47
|
|
48
48
|
message_header = field_name ":" " "* field_value :> CRLF;
|
49
49
|
|