puma 5.0.4-java → 5.2.2-java

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.

Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +109 -48
  3. data/README.md +48 -18
  4. data/docs/architecture.md +21 -18
  5. data/docs/compile_options.md +19 -0
  6. data/docs/deployment.md +1 -1
  7. data/docs/fork_worker.md +2 -0
  8. data/docs/kubernetes.md +66 -0
  9. data/docs/plugins.md +1 -1
  10. data/docs/rails_dev_mode.md +29 -0
  11. data/docs/stats.md +142 -0
  12. data/docs/systemd.md +24 -2
  13. data/ext/puma_http11/extconf.rb +18 -5
  14. data/ext/puma_http11/http11_parser.c +45 -47
  15. data/ext/puma_http11/http11_parser.java.rl +1 -1
  16. data/ext/puma_http11/http11_parser.rl +1 -1
  17. data/ext/puma_http11/mini_ssl.c +162 -84
  18. data/ext/puma_http11/org/jruby/puma/Http11Parser.java +5 -7
  19. data/ext/puma_http11/puma_http11.c +8 -2
  20. data/lib/puma.rb +20 -10
  21. data/lib/puma/app/status.rb +4 -7
  22. data/lib/puma/binder.rb +60 -24
  23. data/lib/puma/cli.rb +4 -0
  24. data/lib/puma/client.rb +4 -9
  25. data/lib/puma/cluster.rb +10 -6
  26. data/lib/puma/cluster/worker.rb +8 -2
  27. data/lib/puma/cluster/worker_handle.rb +5 -2
  28. data/lib/puma/configuration.rb +14 -1
  29. data/lib/puma/const.rb +11 -3
  30. data/lib/puma/control_cli.rb +73 -70
  31. data/lib/puma/detect.rb +14 -10
  32. data/lib/puma/dsl.rb +104 -22
  33. data/lib/puma/error_logger.rb +10 -3
  34. data/lib/puma/events.rb +18 -3
  35. data/lib/puma/json.rb +96 -0
  36. data/lib/puma/launcher.rb +52 -6
  37. data/lib/puma/minissl.rb +48 -17
  38. data/lib/puma/minissl/context_builder.rb +6 -0
  39. data/lib/puma/null_io.rb +12 -0
  40. data/lib/puma/puma_http11.jar +0 -0
  41. data/lib/puma/reactor.rb +19 -12
  42. data/lib/puma/request.rb +20 -7
  43. data/lib/puma/runner.rb +19 -7
  44. data/lib/puma/server.rb +20 -75
  45. data/lib/puma/state_file.rb +5 -3
  46. data/lib/puma/systemd.rb +46 -0
  47. data/lib/rack/handler/puma.rb +1 -0
  48. metadata +8 -2
data/docs/architecture.md CHANGED
@@ -4,34 +4,37 @@
4
4
 
5
5
  ![https://bit.ly/2iJuFky](images/puma-general-arch.png)
6
6
 
7
- Puma is a threaded web server, processing requests across a TCP or UNIX socket.
7
+ Puma is a threaded Ruby HTTP application server, processing requests across a TCP or UNIX socket.
8
8
 
9
- Workers accept connections from the socket and a thread in the worker's thread pool processes the client's request.
9
+ Puma processes (there can be one or many) accept connections from the socket via a thread (in the `Reactor` class). The connection, once fully buffered and read, moves in to the `todo` list, where it will be picked up by a free/waiting thread in the threadpool (the `ThreadPool` class).
10
10
 
11
- Clustered mode is shown/discussed here. Single mode is analogous to having a single worker process.
11
+ Puma works in two main modes: cluster and single. In single mode, only one Puma process is booted. In cluster mode, a `master` process is booted, which prepares (and may boot) the application, and then uses the `fork()` system call to create 1 or more `child` processes. These `child` processes all listen to the same socket. The `master` process does not listen to the socket or process requests - its purpose is mostly to manage and listen for UNIX signals and possibly kill or boot `child` processes.
12
12
 
13
- ## Connection pipeline
13
+ We sometimes call `child` processes (or Puma processes in `single` mode) _workers_, and we sometimes call the threads created by Puma's `ThreadPool` _worker threads_.
14
+
15
+ ## How Requests Work
14
16
 
15
17
  ![https://bit.ly/2zwzhEK](images/puma-connection-flow.png)
16
18
 
17
19
  * Upon startup, Puma listens on a TCP or UNIX socket.
18
- * The backlog of this socket is configured (with a default of 1024), determining how many established but unaccepted connections can exist concurrently.
19
- * This socket backlog is distinct from the "backlog" of work as reported by the control server stats. The latter is the number of connections in that worker's "todo" set waiting for a worker thread.
20
- * By default, a single, separate thread is used to receive HTTP requests across the socket.
21
- * When at least one worker thread is available for work, a connection is accepted and placed in this request buffer
22
- * This thread waits for entire HTTP requests to be received over the connection
23
- * The time spent waiting for the HTTP request body to be received is exposed to the Rack app as `env['puma.request_body_wait']` (milliseconds)
24
- * Once received, the connection is pushed into the "todo" set
25
- * Worker threads pop work off the "todo" set for processing
26
- * The thread processes the request via the rack application (which generates the HTTP response)
27
- * The thread writes the response to the connection
28
- * Finally, the thread become available to process another connection in the "todo" set
29
-
30
- ### Disabling `queue_requests`
20
+ * The backlog of this socket is configured (with a default of 1024). This determines the size of the queue for unaccepted connections. Generally, this setting is unimportant and will never be hit in production use. If the backlog is full, the connection will be refused by the operating system.
21
+ * This socket backlog is distinct from the `backlog` of work as reported by `Puma.stats` or the control server. The backlog as reported by Puma is the number of connections in the process' `todo` set waiting for a thread from the `ThreadPool`.
22
+ * By default, a single, separate thread (created by the `Reactor` class) is used to read and buffer requests from the socket.
23
+ * When at least one worker thread is available for work, the reactor thread listens to the socket and accepts a request, if one is waiting.
24
+ * The reactor thread waits for the entire HTTP request to be received.
25
+ * The time spent waiting for the HTTP request body to be received is exposed to the Rack app as `env['puma.request_body_wait']` (milliseconds).
26
+ * Once fully buffered and received, the connection is pushed into the "todo" set.
27
+ * Worker threads pop work off the "todo" set for processing.
28
+ * The worker thread processes the request via `call`ing the configured Rack application. The Rack application generates the HTTP response.
29
+ * The worker thread writes the response to the connection. Note that while Puma buffers requests via a separate thread, it does not use a separate thread for responses.
30
+ * Once done, the thread become available to process another connection in the "todo" set.
31
+
32
+ ### `queue_requests`
31
33
 
32
34
  ![https://bit.ly/2zxCJ1Z](images/puma-connection-flow-no-reactor.png)
33
35
 
34
- The `queue_requests` option is `true` by default, enabling the separate thread used to buffer requests as described above.
36
+ The `queue_requests` option is `true` by default, enabling the separate reactor thread used to buffer requests as described above.
35
37
 
36
38
  If set to `false`, this buffer will not be used for connections while waiting for the request to arrive.
39
+
37
40
  In this mode, when a connection is accepted, it is added to the "todo" queue immediately, and a worker will synchronously do any waiting necessary to read the HTTP request from the socket.
@@ -0,0 +1,19 @@
1
+ # Compile Options
2
+
3
+ There are some `cflags` provided to change Puma's default configuration for its C extension.
4
+
5
+ ## Query String, `PUMA_QUERY_STRING_MAX_LENGTH`
6
+
7
+ By default, the max length of `QUERY_STRING` is `1024 * 10`. But you may want to adjust it to allow accept larger queries in GET requests.
8
+
9
+ For manual install, pass the `PUMA_QUERY_STRING_MAX_LENGTH` option like this:
10
+
11
+ ```
12
+ gem install puma -- --with-cflags="-D PUMA_QUERY_STRING_MAX_LENGTH=64000"
13
+ ```
14
+
15
+ For Bundler, use its configuration system:
16
+
17
+ ```
18
+ bundle config build.puma "--with-cflags='-D PUMA_QUERY_STRING_MAX_LENGTH=64000'"
19
+ ```
data/docs/deployment.md CHANGED
@@ -29,7 +29,7 @@ Here are some rules of thumb for cluster mode:
29
29
  * Use cluster mode and set the number of workers to 1.5x the number of cpu cores
30
30
  in the machine, minimum 2.
31
31
  * Set the number of threads to desired concurrent requests / number of workers.
32
- Puma defaults to 16 and that's a decent number.
32
+ Puma defaults to 5 and that's a decent number.
33
33
 
34
34
  #### Migrating from Unicorn
35
35
 
data/docs/fork_worker.md CHANGED
@@ -24,6 +24,8 @@ Similar to the `preload_app!` option, the `fork_worker` option allows your appli
24
24
 
25
25
  ### Limitations
26
26
 
27
+ - Not compatible with the `preload_app!` option
28
+
27
29
  - This mode is still very experimental so there may be bugs or edge-cases, particularly around expected behavior of existing hooks. Please open a [bug report](https://github.com/puma/puma/issues/new?template=bug_report.md) if you encounter any issues.
28
30
 
29
31
  - In order to fork new workers cleanly, worker 0 shuts down its server and stops serving requests so there are no open file descriptors or other kinds of shared global state between processes, and to maximize copy-on-write efficiency across the newly-forked workers. This may temporarily reduce total capacity of the cluster during a phased restart / refork.
@@ -0,0 +1,66 @@
1
+ # Kubernetes
2
+
3
+ ## Running Puma in Kubernetes
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 request 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
+
7
+ ## Basic setup
8
+
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
+
11
+ A basic Dockerfile example:
12
+ ```
13
+ FROM ruby:2.5.1-alpine # can be updated to newer ruby versions
14
+ RUN apk update && apk add build-base # and any other packages you need
15
+
16
+ # Only rebuild gem bundle if Gemfile changes
17
+ COPY Gemfile Gemfile.lock ./
18
+ RUN bundle install
19
+
20
+ # Copy over the rest of the files
21
+ COPY . .
22
+
23
+ # Open up port and start the service
24
+ EXPOSE 9292
25
+ CMD bundle exec rackup -o 0.0.0.0
26
+ ```
27
+
28
+ A sample `deployment.yaml`:
29
+ ```
30
+ ---
31
+ apiVersion: apps/v1
32
+ kind: Deployment
33
+ metadata:
34
+ name: my-awesome-puma-app
35
+ spec:
36
+ selector:
37
+ matchLabels:
38
+ app: my-awesome-puma-app
39
+ template:
40
+ metadata:
41
+ labels:
42
+ app: my-awesome-puma-app
43
+ service: my-awesome-puma-app
44
+ spec:
45
+ containers:
46
+ - name: my-awesome-puma-app
47
+ image: <your image here>
48
+ ports:
49
+ - containerPort: 9292
50
+ ```
51
+
52
+ ## Graceful shutdown and pod termination
53
+
54
+ For some high-throughput systems, it is possible that some HTTP requests will return responses with response codes in the 5XX range during a rolling deploy to a new version. This is caused by [the way that Kubernetes terminates a pod during rolling deploys](https://cloud.google.com/blog/products/gcp/kubernetes-best-practices-terminating-with-grace):
55
+
56
+ 1. The replication controller determines a pod should be shut down.
57
+ 2. The Pod is set to the “Terminating” State and removed from the endpoints list of all Services, so that it receives no more requests.
58
+ 3. The pods pre-stop hook get called. The default for this is to send `SIGTERM` to the process inside the pod.
59
+ 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
+ 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
+
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 this request 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
+
64
+ 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 guarantuee 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
+
66
+ More discussions and links to relevant articles can be found in https://github.com/puma/puma/issues/2343.
data/docs/plugins.md CHANGED
@@ -8,7 +8,7 @@ operations.
8
8
  * [tmp\_restart](https://github.com/puma/puma/blob/master/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
- Packages up the default configuration used by puma on Heroku
11
+ Packages up the default configuration used by puma on Heroku (being sunset with the release of Puma 5.0)
12
12
 
13
13
  Plugins are activated in a puma configuration file (such as `config/puma.rb'`)
14
14
  by adding `plugin "name"`, such as `plugin "heroku"`.
@@ -0,0 +1,29 @@
1
+ # Running Puma in Rails Development Mode
2
+
3
+ ## "Loopback requests"
4
+
5
+ Be cautious of "loopback requests", where a Rails application executes a request to a server that in turn, results in another request back to the same Rails application before the first request is completed. Having a loopback request will trigger [Rails' load interlock](https://guides.rubyonrails.org/threading_and_code_execution.html#load-interlock) mechanism. The load interlock mechanism prevents a thread from using Rails autoloading mechanism to load constants while the application code is still running inside another thread.
6
+
7
+ This issue only occurs in the development environment as Rails' load interlock is not used in production environments. Although we're not sure, we believe this issue may not occur with the new `zeitwerk` code loader.
8
+
9
+ ### Solutions
10
+
11
+
12
+ #### 1. Bypass Rails' load interlock with `.permit_concurrent_loads`
13
+
14
+ Wrap the first request inside a block that will allow concurrent loads, [`ActiveSupport::Dependencies.interlock.permit_concurrent_loads`](https://guides.rubyonrails.org/threading_and_code_execution.html#permit-concurrent-loads). Anything wrapped inside the `.permit_concurrent_loads` block will bypass the load interlock mechanism, allowing new threads to access the Rails environment and boot properly.
15
+
16
+ ###### Example
17
+
18
+ ```ruby
19
+ response = ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
20
+ # Your HTTP request code here. For example:
21
+ Faraday.post url, data: 'foo'
22
+ end
23
+
24
+ do_something_with response
25
+ ```
26
+
27
+ #### 2. Use multiple processes on Puma
28
+
29
+ Alternatively, you may also enable multiple (single-threaded) workers on Puma. By doing so, you are sidestepping the problem by creating multiple processes rather than new threads. However, this workaround is not ideal because debugging tools such as [byebug](https://github.com/deivid-rodriguez/byebug/issues/487) and [pry](https://github.com/pry/pry/issues/2153), work poorly with any multi-process web server.
data/docs/stats.md ADDED
@@ -0,0 +1,142 @@
1
+ ## accessing stats
2
+
3
+ Stats can be accessed in two ways:
4
+
5
+ ### control server
6
+
7
+ `$ pumactl stats` or `GET /stats`
8
+
9
+ [Read more about `pumactl` and the control server in the README.](https://github.com/puma/puma#controlstatus-server).
10
+
11
+ ### Puma.stats
12
+
13
+ `Puma.stats` produces a JSON string. `Puma.stats_hash` produces a ruby hash.
14
+
15
+ #### in single mode
16
+
17
+ Invoke `Puma.stats` anywhere in runtime, e.g. in a rails initializer:
18
+
19
+ ```ruby
20
+ # config/initializers/puma_stats.rb
21
+
22
+ Thread.new do
23
+ loop do
24
+ sleep 30
25
+ puts Puma.stats
26
+ end
27
+ end
28
+ ```
29
+
30
+ #### in cluster mode
31
+
32
+ Invoke `Puma.stats` from the master process
33
+
34
+ ```ruby
35
+ # config/puma.rb
36
+
37
+ before_fork do
38
+ Thread.new do
39
+ loop do
40
+ puts Puma.stats
41
+ sleep 30
42
+ end
43
+ end
44
+ end
45
+ ```
46
+
47
+
48
+ ## Explanation of stats
49
+
50
+ `Puma.stats` returns different information and a different structure depending on if Puma is in single vs cluster mode. There is one top-level attribute that is common to both modes:
51
+
52
+ * started_at: when puma was started
53
+
54
+ ### single mode and individual workers in cluster mode
55
+
56
+ When Puma is run in single mode, these stats ar available at the top level. When Puma is run in cluster mode, these stats are available within the `worker_status` array in a hash labeled `last_status`, in an array of hashes, one hash for each worker.
57
+
58
+ * backlog: requests that are waiting for an available thread to be available. if this is above 0, you need more capacity [always true?]
59
+ * running: how many threads are running
60
+ * pool_capacity: the number of requests that the server is capable of taking right now. For example if the number is 5 then it means there are 5 threads sitting idle ready to take a request. If one request comes in, then the value would be 4 until it finishes processing. If the minimum threads allowed is zero, this number will still have a maximum value of the maximum threads allowed.
61
+ * max_threads: the maximum number of threads puma is configured to spool up per worker
62
+ * requests_count: the number of requests this worker has served since starting
63
+
64
+
65
+ ### cluster mode
66
+
67
+ * phase: which phase of restart the process is in, during [phased restart](https://github.com/puma/puma/blob/master/docs/restart.md)
68
+ * workers: ??
69
+ * booted_workers: how many workers currently running?
70
+ * old_workers: ??
71
+ * worker_status: array of hashes of info for each worker (see below)
72
+
73
+ ### worker status
74
+
75
+ * started_at: when the worker was started
76
+ * pid: the process id of the worker process
77
+ * index: each worker gets a number. if puma is configured to have 3 workers, then this will be 0, 1, or 2
78
+ * booted: if it's done booting [?]
79
+ * last_checkin: Last time the worker responded to the master process' heartbeat check.
80
+ * last_status: a hash of info about the worker's state handling requests. See the explanation for this in "single mode and individual workers in cluster mode" section above.
81
+
82
+
83
+ ## Examples
84
+
85
+ Here are two example stats hashes produced by `Puma.stats`:
86
+
87
+ ### single
88
+
89
+ ```json
90
+ {
91
+ "started_at": "2021-01-14T07:12:35Z",
92
+ "backlog": 0,
93
+ "running": 5,
94
+ "pool_capacity": 5,
95
+ "max_threads": 5,
96
+ "requests_count": 3
97
+ }
98
+ ```
99
+
100
+ ### cluster
101
+
102
+ ```json
103
+ {
104
+ "started_at": "2021-01-14T07:09:17Z",
105
+ "workers": 2,
106
+ "phase": 0,
107
+ "booted_workers": 2,
108
+ "old_workers": 0,
109
+ "worker_status": [
110
+ {
111
+ "started_at": "2021-01-14T07:09:24Z",
112
+ "pid": 64136,
113
+ "index": 0,
114
+ "phase": 0,
115
+ "booted": true,
116
+ "last_checkin": "2021-01-14T07:11:09Z",
117
+ "last_status": {
118
+ "backlog": 0,
119
+ "running": 5,
120
+ "pool_capacity": 5,
121
+ "max_threads": 5,
122
+ "requests_count": 2
123
+ }
124
+ },
125
+ {
126
+ "started_at": "2021-01-14T07:09:24Z",
127
+ "pid": 64137,
128
+ "index": 1,
129
+ "phase": 0,
130
+ "booted": true,
131
+ "last_checkin": "2021-01-14T07:11:09Z",
132
+ "last_status": {
133
+ "backlog": 0,
134
+ "running": 5,
135
+ "pool_capacity": 5,
136
+ "max_threads": 5,
137
+ "requests_count": 1
138
+ }
139
+ }
140
+ ]
141
+ }
142
+ ```
data/docs/systemd.md CHANGED
@@ -24,8 +24,15 @@ After=network.target
24
24
  # Requires=puma.socket
25
25
 
26
26
  [Service]
27
- # Foreground process (do not use --daemon in ExecStart or config.rb)
28
- Type=simple
27
+ # Puma supports systemd's `Type=notify` and watchdog service
28
+ # monitoring, if the [sd_notify](https://github.com/agis/ruby-sdnotify) gem is installed,
29
+ # as of Puma 5.1 or later.
30
+ # On earlier versions of Puma or JRuby, change this to `Type=simple` and remove
31
+ # the `WatchdogSec` line.
32
+ Type=notify
33
+
34
+ # If your Puma process locks up, systemd's watchdog will restart it within seconds.
35
+ WatchdogSec=10
29
36
 
30
37
  # Preferably configure a non-privileged user
31
38
  # User=
@@ -122,6 +129,21 @@ Puma will detect the release path socket as different than the one provided by
122
129
  systemd and attempt to bind it again, resulting in the exception
123
130
  `There is already a server bound to:`.
124
131
 
132
+ ### Binding
133
+
134
+ By default you need to configure puma to have binds matching with all
135
+ ListenStream statements. Any mismatched systemd ListenStreams will be closed by
136
+ puma.
137
+
138
+ To automatically bind to all activated sockets, the option
139
+ `--bind-to-activated-sockets` can be used. This matches the config DSL
140
+ `bind_to_activated_sockets` statement. This will cause puma to create a bind
141
+ automatically for any activated socket. When systemd socket activation is not
142
+ enabled, this option does nothing.
143
+
144
+ This also accepts an optional argument `only` (DSL: `'only'`) to discard any
145
+ binds that's not socket activated.
146
+
125
147
  ## Usage
126
148
 
127
149
  Without socket activation, use `systemctl` as root (e.g. via `sudo`) as
@@ -17,12 +17,25 @@ unless ENV["DISABLE_SSL"]
17
17
  have_header "openssl/bio.h"
18
18
 
19
19
  # below is yes for 1.0.2 & later
20
- have_func "DTLS_method" , "openssl/ssl.h"
20
+ have_func "DTLS_method" , "openssl/ssl.h"
21
21
 
22
- # below are yes for 1.1.0 & later, may need to check func rather than macro
23
- # with versions after 1.1.1
24
- have_func "TLS_server_method" , "openssl/ssl.h"
25
- have_macro "SSL_CTX_set_min_proto_version", "openssl/ssl.h"
22
+ # below are yes for 1.1.0 & later
23
+ have_func "TLS_server_method" , "openssl/ssl.h"
24
+ have_func "SSL_CTX_set_min_proto_version(NULL, 0)", "openssl/ssl.h"
25
+
26
+ have_func "X509_STORE_up_ref"
27
+ have_func("SSL_CTX_set_ecdh_auto(NULL, 0)", "openssl/ssl.h")
28
+ end
29
+ end
30
+
31
+ if ENV["MAKE_WARNINGS_INTO_ERRORS"]
32
+ # Make all warnings into errors
33
+ # Except `implicit-fallthrough` since most failures comes from ragel state machine generated code
34
+ if respond_to? :append_cflags
35
+ append_cflags config_string 'WERRORFLAG'
36
+ append_cflags '-Wno-implicit-fallthrough'
37
+ else
38
+ $CFLAGS += ' ' << (config_string 'WERRORFLAG') << ' -Wno-implicit-fallthrough'
26
39
  end
27
40
  end
28
41
 
@@ -33,20 +33,18 @@ static void snake_upcase_char(char *c)
33
33
  /** Machine **/
34
34
 
35
35
 
36
- #line 79 "ext/puma_http11/http11_parser.rl"
36
+ #line 81 "ext/puma_http11/http11_parser.rl"
37
37
 
38
38
 
39
39
  /** Data **/
40
40
 
41
- #line 40 "ext/puma_http11/http11_parser.c"
41
+ #line 42 "ext/puma_http11/http11_parser.c"
42
42
  static const int puma_parser_start = 1;
43
43
  static const int puma_parser_first_final = 46;
44
44
  static const int puma_parser_error = 0;
45
45
 
46
- static const int puma_parser_en_main = 1;
47
46
 
48
-
49
- #line 83 "ext/puma_http11/http11_parser.rl"
47
+ #line 85 "ext/puma_http11/http11_parser.rl"
50
48
 
51
49
  int puma_parser_init(puma_parser *parser) {
52
50
  int cs = 0;
@@ -56,7 +54,7 @@ int puma_parser_init(puma_parser *parser) {
56
54
  cs = puma_parser_start;
57
55
  }
58
56
 
59
- #line 87 "ext/puma_http11/http11_parser.rl"
57
+ #line 89 "ext/puma_http11/http11_parser.rl"
60
58
  parser->cs = cs;
61
59
  parser->body_start = 0;
62
60
  parser->content_len = 0;
@@ -109,7 +107,7 @@ st0:
109
107
  cs = 0;
110
108
  goto _out;
111
109
  tr0:
112
- #line 35 "ext/puma_http11/http11_parser.rl"
110
+ #line 37 "ext/puma_http11/http11_parser.rl"
113
111
  { MARK(mark, p); }
114
112
  goto st2;
115
113
  st2:
@@ -132,7 +130,7 @@ case 2:
132
130
  goto st27;
133
131
  goto st0;
134
132
  tr2:
135
- #line 48 "ext/puma_http11/http11_parser.rl"
133
+ #line 50 "ext/puma_http11/http11_parser.rl"
136
134
  {
137
135
  parser->request_method(parser, PTR_TO(mark), LEN(mark, p));
138
136
  }
@@ -158,7 +156,7 @@ case 3:
158
156
  goto tr5;
159
157
  goto st0;
160
158
  tr4:
161
- #line 35 "ext/puma_http11/http11_parser.rl"
159
+ #line 37 "ext/puma_http11/http11_parser.rl"
162
160
  { MARK(mark, p); }
163
161
  goto st4;
164
162
  st4:
@@ -172,53 +170,53 @@ case 4:
172
170
  }
173
171
  goto st0;
174
172
  tr8:
175
- #line 51 "ext/puma_http11/http11_parser.rl"
173
+ #line 53 "ext/puma_http11/http11_parser.rl"
176
174
  {
177
175
  parser->request_uri(parser, PTR_TO(mark), LEN(mark, p));
178
176
  }
179
177
  goto st5;
180
178
  tr31:
181
- #line 35 "ext/puma_http11/http11_parser.rl"
179
+ #line 37 "ext/puma_http11/http11_parser.rl"
182
180
  { MARK(mark, p); }
183
- #line 54 "ext/puma_http11/http11_parser.rl"
181
+ #line 56 "ext/puma_http11/http11_parser.rl"
184
182
  {
185
183
  parser->fragment(parser, PTR_TO(mark), LEN(mark, p));
186
184
  }
187
185
  goto st5;
188
186
  tr33:
189
- #line 54 "ext/puma_http11/http11_parser.rl"
187
+ #line 56 "ext/puma_http11/http11_parser.rl"
190
188
  {
191
189
  parser->fragment(parser, PTR_TO(mark), LEN(mark, p));
192
190
  }
193
191
  goto st5;
194
192
  tr37:
195
- #line 67 "ext/puma_http11/http11_parser.rl"
193
+ #line 69 "ext/puma_http11/http11_parser.rl"
196
194
  {
197
195
  parser->request_path(parser, PTR_TO(mark), LEN(mark,p));
198
196
  }
199
- #line 51 "ext/puma_http11/http11_parser.rl"
197
+ #line 53 "ext/puma_http11/http11_parser.rl"
200
198
  {
201
199
  parser->request_uri(parser, PTR_TO(mark), LEN(mark, p));
202
200
  }
203
201
  goto st5;
204
202
  tr41:
205
- #line 58 "ext/puma_http11/http11_parser.rl"
203
+ #line 60 "ext/puma_http11/http11_parser.rl"
206
204
  { MARK(query_start, p); }
207
- #line 59 "ext/puma_http11/http11_parser.rl"
205
+ #line 61 "ext/puma_http11/http11_parser.rl"
208
206
  {
209
207
  parser->query_string(parser, PTR_TO(query_start), LEN(query_start, p));
210
208
  }
211
- #line 51 "ext/puma_http11/http11_parser.rl"
209
+ #line 53 "ext/puma_http11/http11_parser.rl"
212
210
  {
213
211
  parser->request_uri(parser, PTR_TO(mark), LEN(mark, p));
214
212
  }
215
213
  goto st5;
216
214
  tr44:
217
- #line 59 "ext/puma_http11/http11_parser.rl"
215
+ #line 61 "ext/puma_http11/http11_parser.rl"
218
216
  {
219
217
  parser->query_string(parser, PTR_TO(query_start), LEN(query_start, p));
220
218
  }
221
- #line 51 "ext/puma_http11/http11_parser.rl"
219
+ #line 53 "ext/puma_http11/http11_parser.rl"
222
220
  {
223
221
  parser->request_uri(parser, PTR_TO(mark), LEN(mark, p));
224
222
  }
@@ -232,7 +230,7 @@ case 5:
232
230
  goto tr10;
233
231
  goto st0;
234
232
  tr10:
235
- #line 35 "ext/puma_http11/http11_parser.rl"
233
+ #line 37 "ext/puma_http11/http11_parser.rl"
236
234
  { MARK(mark, p); }
237
235
  goto st6;
238
236
  st6:
@@ -297,21 +295,21 @@ case 13:
297
295
  goto st13;
298
296
  goto st0;
299
297
  tr18:
300
- #line 63 "ext/puma_http11/http11_parser.rl"
298
+ #line 65 "ext/puma_http11/http11_parser.rl"
301
299
  {
302
300
  parser->http_version(parser, PTR_TO(mark), LEN(mark, p));
303
301
  }
304
302
  goto st14;
305
303
  tr26:
306
- #line 44 "ext/puma_http11/http11_parser.rl"
304
+ #line 46 "ext/puma_http11/http11_parser.rl"
307
305
  { MARK(mark, p); }
308
- #line 45 "ext/puma_http11/http11_parser.rl"
306
+ #line 47 "ext/puma_http11/http11_parser.rl"
309
307
  {
310
308
  parser->http_field(parser, PTR_TO(field_start), parser->field_len, PTR_TO(mark), LEN(mark, p));
311
309
  }
312
310
  goto st14;
313
311
  tr29:
314
- #line 45 "ext/puma_http11/http11_parser.rl"
312
+ #line 47 "ext/puma_http11/http11_parser.rl"
315
313
  {
316
314
  parser->http_field(parser, PTR_TO(field_start), parser->field_len, PTR_TO(mark), LEN(mark, p));
317
315
  }
@@ -360,7 +358,7 @@ case 16:
360
358
  goto tr22;
361
359
  goto st0;
362
360
  tr22:
363
- #line 71 "ext/puma_http11/http11_parser.rl"
361
+ #line 73 "ext/puma_http11/http11_parser.rl"
364
362
  {
365
363
  parser->body_start = p - buffer + 1;
366
364
  parser->header_done(parser, p + 1, pe - p - 1);
@@ -374,13 +372,13 @@ case 46:
374
372
  #line 373 "ext/puma_http11/http11_parser.c"
375
373
  goto st0;
376
374
  tr21:
377
- #line 38 "ext/puma_http11/http11_parser.rl"
375
+ #line 40 "ext/puma_http11/http11_parser.rl"
378
376
  { MARK(field_start, p); }
379
- #line 39 "ext/puma_http11/http11_parser.rl"
377
+ #line 41 "ext/puma_http11/http11_parser.rl"
380
378
  { snake_upcase_char((char *)p); }
381
379
  goto st17;
382
380
  tr23:
383
- #line 39 "ext/puma_http11/http11_parser.rl"
381
+ #line 41 "ext/puma_http11/http11_parser.rl"
384
382
  { snake_upcase_char((char *)p); }
385
383
  goto st17;
386
384
  st17:
@@ -413,13 +411,13 @@ case 17:
413
411
  goto tr23;
414
412
  goto st0;
415
413
  tr24:
416
- #line 40 "ext/puma_http11/http11_parser.rl"
414
+ #line 42 "ext/puma_http11/http11_parser.rl"
417
415
  {
418
416
  parser->field_len = LEN(field_start, p);
419
417
  }
420
418
  goto st18;
421
419
  tr27:
422
- #line 44 "ext/puma_http11/http11_parser.rl"
420
+ #line 46 "ext/puma_http11/http11_parser.rl"
423
421
  { MARK(mark, p); }
424
422
  goto st18;
425
423
  st18:
@@ -433,7 +431,7 @@ case 18:
433
431
  }
434
432
  goto tr25;
435
433
  tr25:
436
- #line 44 "ext/puma_http11/http11_parser.rl"
434
+ #line 46 "ext/puma_http11/http11_parser.rl"
437
435
  { MARK(mark, p); }
438
436
  goto st19;
439
437
  st19:
@@ -445,39 +443,39 @@ case 19:
445
443
  goto tr29;
446
444
  goto st19;
447
445
  tr9:
448
- #line 51 "ext/puma_http11/http11_parser.rl"
446
+ #line 53 "ext/puma_http11/http11_parser.rl"
449
447
  {
450
448
  parser->request_uri(parser, PTR_TO(mark), LEN(mark, p));
451
449
  }
452
450
  goto st20;
453
451
  tr38:
454
- #line 67 "ext/puma_http11/http11_parser.rl"
452
+ #line 69 "ext/puma_http11/http11_parser.rl"
455
453
  {
456
454
  parser->request_path(parser, PTR_TO(mark), LEN(mark,p));
457
455
  }
458
- #line 51 "ext/puma_http11/http11_parser.rl"
456
+ #line 53 "ext/puma_http11/http11_parser.rl"
459
457
  {
460
458
  parser->request_uri(parser, PTR_TO(mark), LEN(mark, p));
461
459
  }
462
460
  goto st20;
463
461
  tr42:
464
- #line 58 "ext/puma_http11/http11_parser.rl"
462
+ #line 60 "ext/puma_http11/http11_parser.rl"
465
463
  { MARK(query_start, p); }
466
- #line 59 "ext/puma_http11/http11_parser.rl"
464
+ #line 61 "ext/puma_http11/http11_parser.rl"
467
465
  {
468
466
  parser->query_string(parser, PTR_TO(query_start), LEN(query_start, p));
469
467
  }
470
- #line 51 "ext/puma_http11/http11_parser.rl"
468
+ #line 53 "ext/puma_http11/http11_parser.rl"
471
469
  {
472
470
  parser->request_uri(parser, PTR_TO(mark), LEN(mark, p));
473
471
  }
474
472
  goto st20;
475
473
  tr45:
476
- #line 59 "ext/puma_http11/http11_parser.rl"
474
+ #line 61 "ext/puma_http11/http11_parser.rl"
477
475
  {
478
476
  parser->query_string(parser, PTR_TO(query_start), LEN(query_start, p));
479
477
  }
480
- #line 51 "ext/puma_http11/http11_parser.rl"
478
+ #line 53 "ext/puma_http11/http11_parser.rl"
481
479
  {
482
480
  parser->request_uri(parser, PTR_TO(mark), LEN(mark, p));
483
481
  }
@@ -500,7 +498,7 @@ case 20:
500
498
  goto st0;
501
499
  goto tr30;
502
500
  tr30:
503
- #line 35 "ext/puma_http11/http11_parser.rl"
501
+ #line 37 "ext/puma_http11/http11_parser.rl"
504
502
  { MARK(mark, p); }
505
503
  goto st21;
506
504
  st21:
@@ -521,7 +519,7 @@ case 21:
521
519
  goto st0;
522
520
  goto st21;
523
521
  tr5:
524
- #line 35 "ext/puma_http11/http11_parser.rl"
522
+ #line 37 "ext/puma_http11/http11_parser.rl"
525
523
  { MARK(mark, p); }
526
524
  goto st22;
527
525
  st22:
@@ -546,7 +544,7 @@ case 22:
546
544
  goto st22;
547
545
  goto st0;
548
546
  tr7:
549
- #line 35 "ext/puma_http11/http11_parser.rl"
547
+ #line 37 "ext/puma_http11/http11_parser.rl"
550
548
  { MARK(mark, p); }
551
549
  goto st23;
552
550
  st23:
@@ -566,7 +564,7 @@ case 23:
566
564
  goto st0;
567
565
  goto st23;
568
566
  tr6:
569
- #line 35 "ext/puma_http11/http11_parser.rl"
567
+ #line 37 "ext/puma_http11/http11_parser.rl"
570
568
  { MARK(mark, p); }
571
569
  goto st24;
572
570
  st24:
@@ -587,7 +585,7 @@ case 24:
587
585
  goto st0;
588
586
  goto st24;
589
587
  tr39:
590
- #line 67 "ext/puma_http11/http11_parser.rl"
588
+ #line 69 "ext/puma_http11/http11_parser.rl"
591
589
  {
592
590
  parser->request_path(parser, PTR_TO(mark), LEN(mark,p));
593
591
  }
@@ -609,7 +607,7 @@ case 25:
609
607
  goto st0;
610
608
  goto tr40;
611
609
  tr40:
612
- #line 58 "ext/puma_http11/http11_parser.rl"
610
+ #line 60 "ext/puma_http11/http11_parser.rl"
613
611
  { MARK(query_start, p); }
614
612
  goto st26;
615
613
  st26:
@@ -1010,7 +1008,7 @@ case 45:
1010
1008
  _out: {}
1011
1009
  }
1012
1010
 
1013
- #line 115 "ext/puma_http11/http11_parser.rl"
1011
+ #line 117 "ext/puma_http11/http11_parser.rl"
1014
1012
 
1015
1013
  if (!puma_parser_has_error(parser))
1016
1014
  parser->cs = cs;