puma 6.6.1 → 7.2.0
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.
- checksums.yaml +4 -4
- data/History.md +224 -4
- data/README.md +34 -34
- data/docs/deployment.md +58 -23
- data/docs/fork_worker.md +5 -5
- data/docs/jungle/README.md +1 -1
- data/docs/kubernetes.md +11 -16
- data/docs/plugins.md +2 -2
- data/docs/restart.md +2 -2
- data/docs/signals.md +19 -19
- data/docs/stats.md +4 -3
- data/docs/systemd.md +3 -3
- data/ext/puma_http11/extconf.rb +2 -17
- data/ext/puma_http11/mini_ssl.c +18 -8
- data/ext/puma_http11/org/jruby/puma/Http11.java +9 -1
- data/ext/puma_http11/puma_http11.c +122 -118
- data/lib/puma/app/status.rb +10 -2
- data/lib/puma/binder.rb +10 -8
- data/lib/puma/cli.rb +3 -5
- data/lib/puma/client.rb +52 -56
- data/lib/puma/cluster/worker.rb +17 -17
- data/lib/puma/cluster/worker_handle.rb +38 -7
- data/lib/puma/cluster.rb +23 -23
- data/lib/puma/cluster_accept_loop_delay.rb +91 -0
- data/lib/puma/commonlogger.rb +3 -3
- data/lib/puma/configuration.rb +104 -51
- data/lib/puma/const.rb +9 -10
- data/lib/puma/control_cli.rb +6 -2
- data/lib/puma/detect.rb +2 -0
- data/lib/puma/dsl.rb +149 -91
- data/lib/puma/error_logger.rb +3 -1
- data/lib/puma/events.rb +25 -10
- data/lib/puma/io_buffer.rb +8 -4
- data/lib/puma/launcher/bundle_pruner.rb +1 -1
- data/lib/puma/launcher.rb +54 -49
- data/lib/puma/minissl.rb +0 -1
- data/lib/puma/plugin/systemd.rb +3 -3
- data/lib/puma/rack/urlmap.rb +1 -1
- data/lib/puma/reactor.rb +19 -13
- data/lib/puma/request.rb +42 -31
- data/lib/puma/runner.rb +9 -18
- data/lib/puma/server.rb +114 -64
- data/lib/puma/single.rb +6 -3
- data/lib/puma/state_file.rb +3 -2
- data/lib/puma/thread_pool.rb +47 -82
- data/lib/puma/util.rb +0 -7
- data/lib/puma.rb +10 -0
- data/lib/rack/handler/puma.rb +2 -2
- data/tools/Dockerfile +13 -5
- metadata +6 -5
- data/ext/puma_http11/ext_help.h +0 -15
data/docs/kubernetes.md
CHANGED
|
@@ -2,16 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
## Running Puma in Kubernetes
|
|
4
4
|
|
|
5
|
-
In general running Puma in Kubernetes works as-is, no special configuration is needed beyond what you would write anyway to get a new Kubernetes Deployment going. There is one known interaction between the way Kubernetes handles pod termination and how Puma handles `SIGINT`, where some
|
|
5
|
+
In general running Puma in Kubernetes works as-is, no special configuration is needed beyond what you would write anyway to get a new Kubernetes Deployment going. There is one known interaction between the way Kubernetes handles pod termination and how Puma handles `SIGINT`, where some requests might be sent to Puma after it has already entered graceful shutdown mode and is no longer accepting requests. This can lead to dropped requests during rolling deploys. A workaround for this is listed at the end of this article.
|
|
6
6
|
|
|
7
7
|
## Basic setup
|
|
8
8
|
|
|
9
9
|
Assuming you already have a running cluster and docker image repository, you can run a simple Puma app with the following example Dockerfile and Deployment specification. These are meant as examples only and are deliberately very minimal to the point of skipping many options that are recommended for running in production, like healthchecks and envvar configuration with ConfigMaps. In general you should check the [Kubernetes documentation](https://kubernetes.io/docs/home/) and [Docker documentation](https://docs.docker.com/) for a more comprehensive overview of the available options.
|
|
10
10
|
|
|
11
|
-
A basic Dockerfile example:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
A basic Dockerfile example:
|
|
12
|
+
|
|
13
|
+
```Dockerfile
|
|
14
|
+
FROM ruby:3.4.5-alpine # can be updated to newer ruby versions
|
|
15
|
+
RUN apk update && apk add build-base # and any other packages you need
|
|
15
16
|
|
|
16
17
|
# Only rebuild gem bundle if Gemfile changes
|
|
17
18
|
COPY Gemfile Gemfile.lock ./
|
|
@@ -26,7 +27,8 @@ CMD bundle exec rackup -o 0.0.0.0
|
|
|
26
27
|
```
|
|
27
28
|
|
|
28
29
|
A sample `deployment.yaml`:
|
|
29
|
-
|
|
30
|
+
|
|
31
|
+
```yaml
|
|
30
32
|
---
|
|
31
33
|
apiVersion: apps/v1
|
|
32
34
|
kind: Deployment
|
|
@@ -47,7 +49,7 @@ spec:
|
|
|
47
49
|
image: <your image here>
|
|
48
50
|
ports:
|
|
49
51
|
- containerPort: 9292
|
|
50
|
-
```
|
|
52
|
+
```
|
|
51
53
|
|
|
52
54
|
## Graceful shutdown and pod termination
|
|
53
55
|
|
|
@@ -59,7 +61,7 @@ For some high-throughput systems, it is possible that some HTTP requests will re
|
|
|
59
61
|
4. The pod has up to `terminationGracePeriodSeconds` (default: 30 seconds) to gracefully shut down. Puma will do this (after it receives SIGTERM) by closing down the socket that accepts new requests and finishing any requests already running before exiting the Puma process.
|
|
60
62
|
5. If the pod is still running after `terminationGracePeriodSeconds` has elapsed, the pod receives `SIGKILL` to make sure the process inside it stops. After that, the container exits and all other Kubernetes objects associated with it are cleaned up.
|
|
61
63
|
|
|
62
|
-
There is a subtle race condition between step 2 and 3: The replication controller does not synchronously remove the pod from the Services AND THEN call the pre-stop hook of the pod, but rather it asynchronously sends "remove this pod from your endpoints" requests to the Services and then immediately proceeds to invoke the pods' pre-stop hook. If the Service controller (typically something like nginx or haproxy) receives
|
|
64
|
+
There is a subtle race condition between step 2 and 3: The replication controller does not synchronously remove the pod from the Services AND THEN call the pre-stop hook of the pod, but rather it asynchronously sends "remove this pod from your endpoints" requests to the Services and then immediately proceeds to invoke the pods' pre-stop hook. If the Service controller (typically something like nginx or haproxy) receives and handles this request "too" late (due to internal lag or network latency between the replication and Service controllers) then it is possible that the Service controller will send one or more requests to a Puma process which has already shut down its listening socket. These requests will then fail with 5XX error codes.
|
|
63
65
|
|
|
64
66
|
The way Kubernetes works this way, rather than handling step 2 synchronously, is due to the CAP theorem: in a distributed system there is no way to guarantee that any message will arrive promptly. In particular, waiting for all Service controllers to report back might get stuck for an indefinite time if one of them has already been terminated or if there has been a net split. A way to work around this is to add a sleep to the pre-stop hook of the same time as the `terminationGracePeriodSeconds` time. This will allow the Puma process to keep serving new requests during the entire grace period, although it will no longer receive new requests after all Service controllers have propagated the removal of the pod from their endpoint lists. Then, after `terminationGracePeriodSeconds`, the pod receives `SIGKILL` and closes down. If your process can't handle SIGKILL properly, for example because it needs to release locks in different services, you can also sleep for a shorter period (and/or increase `terminationGracePeriodSeconds`) as long as the time slept is longer than the time that your Service controllers take to propagate the pod removal. The downside of this workaround is that all pods will take at minimum the amount of time slept to shut down and this will increase the time required for your rolling deploy.
|
|
65
67
|
|
|
@@ -67,12 +69,5 @@ More discussions and links to relevant articles can be found in https://github.c
|
|
|
67
69
|
|
|
68
70
|
## Workers Per Pod, and Other Config Issues
|
|
69
71
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
* Worker counts should be somewhere between 4 and 32 in most cases. You want more than 4 in order to minimize time spent in request queueing for a free Puma worker, but probably less than ~32 because otherwise autoscaling is working in too large of an increment or they probably won't fit very well into your nodes. In any queueing system, queue time is proportional to 1/n, where n is the number of things pulling from the queue. Each pod will have its own request queue (i.e., the socket backlog). If you have 4 pods with 1 worker each (4 request queues), wait times are, proportionally, about 4 times higher than if you had 1 pod with 4 workers (1 request queue).
|
|
73
|
-
* Unless you have a very I/O-heavy application (50%+ time spent waiting on IO), use the default thread count (5 for MRI). Using higher numbers of threads with low I/O wait (<50%) will lead to additional request queueing time (latency!) and additional memory usage.
|
|
74
|
-
* More processes per pod reduces memory usage per process, because of copy-on-write memory and because the cost of the single master process is "amortized" over more child processes.
|
|
75
|
-
* Don't run less than 4 processes per pod if you can. Low numbers of processes per pod will lead to high request queueing, which means you will have to run more pods.
|
|
76
|
-
* If multithreaded, allocate 1 CPU per worker. If single threaded, allocate 0.75 cpus per worker. Most web applications spend about 25% of their time in I/O - but when you're running multi-threaded, your Puma process will have higher CPU usage and should be able to fully saturate a CPU core.
|
|
77
|
-
* Most Puma processes will use about ~512MB-1GB per worker, and about 1GB for the master process. However, you probably shouldn't bother with setting memory limits lower than around 2GB per process, because most places you are deploying will have 2GB of RAM per CPU. A sensible memory limit for a Puma configuration of 4 child workers might be something like 8 GB (1 GB for the master, 7GB for the 4 children).
|
|
72
|
+
See our [deployment docs](./deployment.md) for more information about how to correctly size your pods and choose the right number of workers and threads.
|
|
78
73
|
|
data/docs/plugins.md
CHANGED
|
@@ -5,13 +5,13 @@ operations.
|
|
|
5
5
|
|
|
6
6
|
There are two canonical plugins to aid in the development of new plugins:
|
|
7
7
|
|
|
8
|
-
* [tmp\_restart](https://github.com/puma/puma/blob/
|
|
8
|
+
* [tmp\_restart](https://github.com/puma/puma/blob/main/lib/puma/plugin/tmp_restart.rb):
|
|
9
9
|
Restarts the server if the file `tmp/restart.txt` is touched
|
|
10
10
|
* [heroku](https://github.com/puma/puma-heroku/blob/master/lib/puma/plugin/heroku.rb):
|
|
11
11
|
Packages up the default configuration used by Puma on Heroku (being sunset
|
|
12
12
|
with the release of Puma 5.0)
|
|
13
13
|
|
|
14
|
-
Plugins are activated in a Puma configuration file (such as `config/puma.rb
|
|
14
|
+
Plugins are activated in a Puma configuration file (such as `config/puma.rb`)
|
|
15
15
|
by adding `plugin "name"`, such as `plugin "heroku"`.
|
|
16
16
|
|
|
17
17
|
Plugins are activated based on path requirements so, activating the `heroku`
|
data/docs/restart.md
CHANGED
|
@@ -29,7 +29,7 @@ Any of the following will cause a Puma server to perform a hot restart:
|
|
|
29
29
|
|
|
30
30
|
* The newly started Puma process changes its current working directory to the directory specified by the `directory` option. If `directory` is set to symlink, this is automatically re-evaluated, so this mechanism can be used to upgrade the application.
|
|
31
31
|
* Only one version of the application is running at a time.
|
|
32
|
-
* `
|
|
32
|
+
* `before_restart` is invoked just before the server shuts down. This can be used to clean up resources (like long-lived database connections) gracefully. Since Ruby 2.0, it is not typically necessary to explicitly close file descriptors on restart. This is because any file descriptor opened by Ruby will have the `FD_CLOEXEC` flag set, meaning that file descriptors are closed on `exec`. `before_restart` is useful, though, if your application needs to perform any more graceful protocol-specific shutdown procedures before closing connections.
|
|
33
33
|
|
|
34
34
|
## Phased restart
|
|
35
35
|
|
|
@@ -59,7 +59,7 @@ Any of the following will cause a Puma server to perform a phased restart:
|
|
|
59
59
|
|
|
60
60
|
* When a phased restart begins, the Puma master process changes its current working directory to the directory specified by the `directory` option. If `directory` is set to symlink, this is automatically re-evaluated, so this mechanism can be used to upgrade the application.
|
|
61
61
|
* On a single server, it's possible that two versions of the application are running concurrently during a phased restart.
|
|
62
|
-
* `
|
|
62
|
+
* `before_restart` is not invoked
|
|
63
63
|
* Phased restarts can be slow for Puma clusters with many workers. Hot restarts often complete more quickly, but at the cost of increased latency during the restart.
|
|
64
64
|
* Phased restarts cannot be used to upgrade any gems loaded by the Puma master process, including `puma` itself, anything in `extra_runtime_dependencies`, or dependencies thereof. Upgrading other gems is safe.
|
|
65
65
|
* If you remove the gems from old releases as part of your deployment strategy, there are additional considerations. Do not put any gems into `extra_runtime_dependencies` that have native extensions or have dependencies that have native extensions (one common example is `puma_worker_killer` and its dependency on `ffi`). Workers will fail on boot during a phased restart. The underlying issue is recorded in [an issue on the rubygems project](https://github.com/rubygems/rubygems/issues/4004). Hot restarts are your only option here if you need these dependencies.
|
data/docs/signals.md
CHANGED
|
@@ -33,16 +33,16 @@ Now you will see via `ps` that there is no more `tail` process. Sometimes when r
|
|
|
33
33
|
|
|
34
34
|
Puma cluster responds to these signals:
|
|
35
35
|
|
|
36
|
-
- `TTIN
|
|
37
|
-
- `TTOU
|
|
38
|
-
- `TERM
|
|
39
|
-
- `USR2
|
|
40
|
-
- `USR1
|
|
41
|
-
- `HUP
|
|
42
|
-
- `INT
|
|
43
|
-
- `CHLD`
|
|
44
|
-
- `URG
|
|
45
|
-
- `INFO
|
|
36
|
+
- `TTIN`: Increment the worker count by 1.
|
|
37
|
+
- `TTOU`: Decrement the worker count by 1.
|
|
38
|
+
- `TERM`: Send `TERM` to worker. The worker will attempt to finish then exit.
|
|
39
|
+
- `USR2`: Restart workers. This also reloads the Puma configuration file, if there is one.
|
|
40
|
+
- `USR1`: Restart workers in phases, a rolling restart. This will not reload the configuration file.
|
|
41
|
+
- `HUP`: Reopen log files defined in `stdout_redirect` configuration parameter. If there is no `stdout_redirect` option provided, it will behave like `INT`.
|
|
42
|
+
- `INT`: Equivalent of sending Ctrl-C to cluster. Puma will attempt to finish then exit.
|
|
43
|
+
- `CHLD`: Reap zombie child processes and wake event loop in `fork_worker` mode.
|
|
44
|
+
- `URG`: Refork workers in phases from worker 0 if `fork_worker` option is enabled.
|
|
45
|
+
- `INFO`: Print backtraces of all Puma threads.
|
|
46
46
|
|
|
47
47
|
## Callbacks order in case of different signals
|
|
48
48
|
|
|
@@ -54,12 +54,12 @@ puma configuration file reloaded, if there is one
|
|
|
54
54
|
puma configuration file reloaded, if there is one
|
|
55
55
|
|
|
56
56
|
before_fork
|
|
57
|
-
|
|
57
|
+
before_worker_fork
|
|
58
58
|
after_worker_fork
|
|
59
59
|
|
|
60
60
|
Gemfile in context
|
|
61
61
|
|
|
62
|
-
|
|
62
|
+
before_worker_boot
|
|
63
63
|
|
|
64
64
|
Code of the app is loaded and running
|
|
65
65
|
```
|
|
@@ -67,18 +67,18 @@ Code of the app is loaded and running
|
|
|
67
67
|
### Send USR2
|
|
68
68
|
|
|
69
69
|
```
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
before_worker_shutdown
|
|
71
|
+
before_restart
|
|
72
72
|
|
|
73
73
|
puma configuration file reloaded, if there is one
|
|
74
74
|
|
|
75
75
|
before_fork
|
|
76
|
-
|
|
76
|
+
before_worker_fork
|
|
77
77
|
after_worker_fork
|
|
78
78
|
|
|
79
79
|
Gemfile in context
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
before_worker_boot
|
|
82
82
|
|
|
83
83
|
Code of the app is loaded and running
|
|
84
84
|
```
|
|
@@ -86,13 +86,13 @@ Code of the app is loaded and running
|
|
|
86
86
|
### Send USR1
|
|
87
87
|
|
|
88
88
|
```
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
before_worker_shutdown
|
|
90
|
+
before_worker_fork
|
|
91
91
|
after_worker_fork
|
|
92
92
|
|
|
93
93
|
Gemfile in context
|
|
94
94
|
|
|
95
|
-
|
|
95
|
+
before_worker_boot
|
|
96
96
|
|
|
97
97
|
Code of the app is loaded and running
|
|
98
98
|
```
|
data/docs/stats.md
CHANGED
|
@@ -62,14 +62,15 @@ When Puma runs in single mode, these stats are available at the top level. When
|
|
|
62
62
|
this is a "wholistic" stat reflecting the overall current state of work to be done and the capacity to do it.
|
|
63
63
|
* pool_capacity: `how many threads are waiting to receive work` + `max_threads` - `running`. In a typical configuration where `min_threads`
|
|
64
64
|
and `max_threads` are configured to the same number, this is simply `how many threads are waiting to receive work`. This number exists only as a stat
|
|
65
|
-
and is not used for any internal decisions, unlike `
|
|
65
|
+
and is not used for any internal decisions, unlike `busy_threads`, which is usually a more useful stat.
|
|
66
66
|
* max_threads: the maximum number of threads Puma is configured to spool per worker
|
|
67
67
|
* requests_count: the number of requests this worker has served since starting
|
|
68
|
-
|
|
68
|
+
* reactor_max: the maximum observed number of requests held in Puma's "reactor" which is used for asyncronously buffering request bodies. This stat is reset on every call, so it's the maximum value observed since the last stat call.
|
|
69
|
+
* backlog_max: the maximum number of requests that have been fully buffered by the reactor and placed in a ready queue, but have not yet been picked up by a server thread. This stat is reset on every call, so it's the maximum value observed since the last stat call.
|
|
69
70
|
|
|
70
71
|
### cluster mode
|
|
71
72
|
|
|
72
|
-
* phase: which phase of restart the process is in, during [phased restart](https://github.com/puma/puma/blob/
|
|
73
|
+
* phase: which phase of restart the process is in, during [phased restart](https://github.com/puma/puma/blob/main/docs/restart.md)
|
|
73
74
|
* workers: ??
|
|
74
75
|
* booted_workers: how many workers currently running?
|
|
75
76
|
* old_workers: ??
|
data/docs/systemd.md
CHANGED
|
@@ -119,8 +119,8 @@ or cluster mode.
|
|
|
119
119
|
### Sockets and symlinks
|
|
120
120
|
|
|
121
121
|
When using releases folders, you should set the socket path using the shared
|
|
122
|
-
folder path (ex. `/srv/
|
|
123
|
-
path (`/srv/
|
|
122
|
+
folder path (ex. `/srv/project/shared/tmp/puma.sock`), not the release folder
|
|
123
|
+
path (`/srv/project/releases/1234/tmp/puma.sock`).
|
|
124
124
|
|
|
125
125
|
Puma will detect the release path socket as different than the one provided by
|
|
126
126
|
systemd and attempt to bind it again, resulting in the exception `There is
|
|
@@ -139,7 +139,7 @@ automatically for any activated socket. When systemd socket activation is not
|
|
|
139
139
|
enabled, this option does nothing.
|
|
140
140
|
|
|
141
141
|
This also accepts an optional argument `only` (DSL: `'only'`) to discard any
|
|
142
|
-
binds that
|
|
142
|
+
binds that are not socket activated.
|
|
143
143
|
|
|
144
144
|
## Usage
|
|
145
145
|
|
data/ext/puma_http11/extconf.rb
CHANGED
|
@@ -52,29 +52,14 @@ unless ENV["PUMA_DISABLE_SSL"]
|
|
|
52
52
|
have_func "SSL_get1_peer_certificate" , ssl_h
|
|
53
53
|
|
|
54
54
|
puts ''
|
|
55
|
-
|
|
56
|
-
# Random.bytes available in Ruby 2.5 and later, Random::DEFAULT deprecated in 3.0
|
|
57
|
-
if Random.respond_to?(:bytes)
|
|
58
|
-
$defs.push "-DHAVE_RANDOM_BYTES"
|
|
59
|
-
puts "checking for Random.bytes... yes"
|
|
60
|
-
else
|
|
61
|
-
puts "checking for Random.bytes... no"
|
|
62
|
-
end
|
|
63
55
|
end
|
|
64
56
|
end
|
|
65
57
|
|
|
66
58
|
if ENV["PUMA_MAKE_WARNINGS_INTO_ERRORS"]
|
|
67
59
|
# Make all warnings into errors
|
|
68
60
|
# Except `implicit-fallthrough` since most failures comes from ragel state machine generated code
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
append_cflags '-Wno-implicit-fallthrough'
|
|
72
|
-
else
|
|
73
|
-
# flag may not exist on some platforms, -Werror may not be defined on some platforms, but
|
|
74
|
-
# works with all in current CI
|
|
75
|
-
$CFLAGS << " #{config_string('WERRORFLAG') || '-Werror'}"
|
|
76
|
-
$CFLAGS << ' -Wno-implicit-fallthrough'
|
|
77
|
-
end
|
|
61
|
+
append_cflags(config_string('WERRORFLAG') || '-Werror')
|
|
62
|
+
append_cflags '-Wno-implicit-fallthrough'
|
|
78
63
|
end
|
|
79
64
|
|
|
80
65
|
create_makefile("puma/puma_http11")
|
data/ext/puma_http11/mini_ssl.c
CHANGED
|
@@ -471,13 +471,8 @@ sslctx_initialize(VALUE self, VALUE mini_ssl_ctx) {
|
|
|
471
471
|
SSL_CTX_set_verify(ctx, NUM2INT(verify_mode), engine_verify_callback);
|
|
472
472
|
}
|
|
473
473
|
|
|
474
|
-
// Random.bytes available in Ruby 2.5 and later, Random::DEFAULT deprecated in 3.0
|
|
475
474
|
session_id_bytes = rb_funcall(
|
|
476
|
-
#ifdef HAVE_RANDOM_BYTES
|
|
477
475
|
rb_cRandom,
|
|
478
|
-
#else
|
|
479
|
-
rb_const_get(rb_cRandom, rb_intern_const("DEFAULT")),
|
|
480
|
-
#endif
|
|
481
476
|
rb_intern_const("bytes"),
|
|
482
477
|
1, ULL2NUM(SSL_MAX_SSL_SESSION_ID_LENGTH));
|
|
483
478
|
|
|
@@ -665,14 +660,29 @@ VALUE engine_shutdown(VALUE self) {
|
|
|
665
660
|
|
|
666
661
|
TypedData_Get_Struct(self, ms_conn, &engine_data_type, conn);
|
|
667
662
|
|
|
663
|
+
if (SSL_in_init(conn->ssl)) {
|
|
664
|
+
// Avoid "shutdown while in init" error
|
|
665
|
+
// See https://github.com/openssl/openssl/blob/openssl-3.5.2/ssl/ssl_lib.c#L2827-L2828
|
|
666
|
+
return Qtrue;
|
|
667
|
+
}
|
|
668
|
+
|
|
668
669
|
ERR_clear_error();
|
|
669
670
|
|
|
670
671
|
ok = SSL_shutdown(conn->ssl);
|
|
671
|
-
|
|
672
|
-
|
|
672
|
+
// See https://github.com/openssl/openssl/blob/openssl-3.5.2/ssl/ssl_lib.c#L2792-L2797
|
|
673
|
+
// for description of SSL_shutdown return values.
|
|
674
|
+
switch (ok) {
|
|
675
|
+
case 0:
|
|
676
|
+
// "close notify" alert is sent by us.
|
|
677
|
+
return Qfalse;
|
|
678
|
+
case 1:
|
|
679
|
+
// "close notify" alert was received from peer.
|
|
680
|
+
return Qtrue;
|
|
681
|
+
default:
|
|
682
|
+
raise_error(conn->ssl, ok);
|
|
673
683
|
}
|
|
674
684
|
|
|
675
|
-
return
|
|
685
|
+
return Qnil;
|
|
676
686
|
}
|
|
677
687
|
|
|
678
688
|
VALUE engine_init(VALUE self) {
|
|
@@ -109,6 +109,10 @@ public class Http11 extends RubyObject {
|
|
|
109
109
|
return (RubyClass)runtime.getModule("Puma").getConstant("HttpParserError");
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
+
private static boolean is_ows(int c) {
|
|
113
|
+
return c == ' ' || c == '\t';
|
|
114
|
+
}
|
|
115
|
+
|
|
112
116
|
public static void http_field(Ruby runtime, RubyHash req, ByteList buffer, int field, int flen, int value, int vlen) {
|
|
113
117
|
RubyString f;
|
|
114
118
|
IRubyObject v;
|
|
@@ -127,7 +131,11 @@ public class Http11 extends RubyObject {
|
|
|
127
131
|
}
|
|
128
132
|
}
|
|
129
133
|
|
|
130
|
-
while (vlen > 0 &&
|
|
134
|
+
while (vlen > 0 && is_ows(buffer.get(value + vlen - 1))) vlen--;
|
|
135
|
+
while (vlen > 0 && is_ows(buffer.get(value))) {
|
|
136
|
+
vlen--;
|
|
137
|
+
value++;
|
|
138
|
+
}
|
|
131
139
|
|
|
132
140
|
if (b.equals(CONTENT_LENGTH_BYTELIST) || b.equals(CONTENT_TYPE_BYTELIST)) {
|
|
133
141
|
f = RubyString.newString(runtime, b);
|