puma 8.1.0 → 8.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/History.md +10 -0
- data/README.md +16 -381
- data/docs/binding.md +135 -0
- data/docs/cluster_mode.md +241 -0
- data/docs/configuration.md +78 -0
- data/docs/{stats.md → control_server.md} +23 -3
- data/docs/{deployment.md → deployment/README.md} +20 -4
- data/docs/{kubernetes.md → deployment/kubernetes.md} +1 -1
- data/docs/plugins.md +61 -2
- data/docs/puma_support.md +15 -1
- data/docs/restart.md +5 -1
- data/docs/signals.md +2 -0
- data/docs/{5.0-Upgrade.md → upgrading/5.0-Upgrade.md} +3 -3
- data/docs/{6.0-Upgrade.md → upgrading/6.0-Upgrade.md} +2 -2
- data/docs/{7.0-Upgrade.md → upgrading/7.0-Upgrade.md} +2 -2
- data/docs/{8.0-Upgrade.md → upgrading/8.0-Upgrade.md} +2 -2
- data/lib/puma/cluster.rb +0 -1
- data/lib/puma/const.rb +1 -1
- data/lib/puma/minissl.rb +1 -4
- metadata +17 -30
- data/docs/fork_worker.md +0 -71
- data/docs/grpc.md +0 -62
- data/docs/jungle/README.md +0 -9
- data/docs/testing_benchmarks_local_files.md +0 -150
- data/docs/testing_test_rackup_ci_files.md +0 -36
- data/ext/puma_http11/PumaHttp11Service.java +0 -17
- data/ext/puma_http11/http11_parser.java.rl +0 -131
- data/ext/puma_http11/http11_parser.rl +0 -149
- data/ext/puma_http11/http11_parser_common.rl +0 -57
- data/ext/puma_http11/no_ssl/PumaHttp11Service.java +0 -15
- data/ext/puma_http11/org/jruby/puma/EnvKey.java +0 -241
- data/ext/puma_http11/org/jruby/puma/Http11.java +0 -321
- data/ext/puma_http11/org/jruby/puma/Http11Parser.java +0 -441
- data/ext/puma_http11/org/jruby/puma/MiniSSL.java +0 -519
- data/tools/Dockerfile +0 -26
- data/tools/trickletest.rb +0 -44
- /data/docs/{nginx.md → deployment/nginx.md} +0 -0
- /data/docs/{jungle → deployment}/rc.d/README.md +0 -0
- /data/docs/{jungle → deployment}/rc.d/puma +0 -0
- /data/docs/{jungle → deployment}/rc.d/puma.conf +0 -0
- /data/docs/{systemd.md → deployment/systemd.md} +0 -0
|
@@ -1,321 +0,0 @@
|
|
|
1
|
-
package org.jruby.puma;
|
|
2
|
-
|
|
3
|
-
import org.jruby.Ruby;
|
|
4
|
-
import org.jruby.RubyClass;
|
|
5
|
-
import org.jruby.RubyHash;
|
|
6
|
-
import org.jruby.RubyModule;
|
|
7
|
-
import org.jruby.RubyNumeric;
|
|
8
|
-
import org.jruby.RubyObject;
|
|
9
|
-
import org.jruby.RubyString;
|
|
10
|
-
|
|
11
|
-
import org.jruby.anno.JRubyMethod;
|
|
12
|
-
|
|
13
|
-
import org.jruby.runtime.ThreadContext;
|
|
14
|
-
import org.jruby.runtime.builtin.IRubyObject;
|
|
15
|
-
|
|
16
|
-
import org.jruby.exceptions.RaiseException;
|
|
17
|
-
|
|
18
|
-
import org.jruby.util.ByteList;
|
|
19
|
-
|
|
20
|
-
import java.util.Arrays;
|
|
21
|
-
|
|
22
|
-
import static java.util.Arrays.stream;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* @author <a href="mailto:ola.bini@ki.se">Ola Bini</a>
|
|
26
|
-
* @author <a href="mailto:headius@headius.com">Charles Oliver Nutter</a>
|
|
27
|
-
*/
|
|
28
|
-
public class Http11 extends RubyObject {
|
|
29
|
-
|
|
30
|
-
public static String getEnvOrProperty(String name) {
|
|
31
|
-
String envValue = System.getenv(name);
|
|
32
|
-
return (envValue != null) ? envValue : System.getProperty(name);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
public static int getConstLength(String name, Integer defaultValue) {
|
|
36
|
-
String stringValue = getEnvOrProperty(name);
|
|
37
|
-
if (stringValue == null || stringValue.isEmpty()) return defaultValue;
|
|
38
|
-
|
|
39
|
-
try {
|
|
40
|
-
int value = Integer.parseUnsignedInt(stringValue);
|
|
41
|
-
if (value <= 0) {
|
|
42
|
-
throw new NumberFormatException("The number is not positive.");
|
|
43
|
-
}
|
|
44
|
-
return value;
|
|
45
|
-
} catch (NumberFormatException e) {
|
|
46
|
-
System.err.println(String.format("The value %s for %s is invalid. Using default value %d instead.", stringValue, name, defaultValue));
|
|
47
|
-
return defaultValue;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
public static void createHttp11(Ruby runtime) {
|
|
52
|
-
RubyModule mPuma = runtime.defineModule("Puma");
|
|
53
|
-
mPuma.defineClassUnder("HttpParserError",runtime.getClass("StandardError"),runtime.getClass("StandardError").getAllocator());
|
|
54
|
-
|
|
55
|
-
// Set up pre-allocated strings for HTTP/1.1 headers and CGI variables
|
|
56
|
-
RubyString[] envStrings =
|
|
57
|
-
stream(EnvKey.values())
|
|
58
|
-
.map((key) -> internRubyString(runtime, key))
|
|
59
|
-
.toArray(RubyString[]::new);
|
|
60
|
-
|
|
61
|
-
RubyClass cHttpParser = mPuma.defineClassUnder("HttpParser",runtime.getObject(),(r, c) -> new Http11(r, c, envStrings));
|
|
62
|
-
cHttpParser.defineAnnotatedMethods(Http11.class);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
private static RubyString internRubyString(Ruby runtime, EnvKey key) {
|
|
66
|
-
return runtime.freezeAndDedupString(RubyString.newStringShared(runtime, key.httpName));
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
private final Ruby runtime;
|
|
70
|
-
private final Http11Parser hp;
|
|
71
|
-
final RubyString[] envStrings;
|
|
72
|
-
private RubyString body;
|
|
73
|
-
|
|
74
|
-
public Http11(Ruby runtime, RubyClass clazz, RubyString[] envStrings) {
|
|
75
|
-
super(runtime,clazz);
|
|
76
|
-
this.runtime = runtime;
|
|
77
|
-
this.hp = new Http11Parser();
|
|
78
|
-
this.envStrings = envStrings;
|
|
79
|
-
this.hp.init();
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
public static void validateMaxLength(Ruby runtime, int len, int max, String msg) {
|
|
83
|
-
if(len>max) {
|
|
84
|
-
throw newHTTPParserError(runtime, msg);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
private static RaiseException newHTTPParserError(Ruby runtime, String msg) {
|
|
89
|
-
return runtime.newRaiseException(getHTTPParserError(runtime), msg);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
private static RubyClass getHTTPParserError(Ruby runtime) {
|
|
93
|
-
// Cheaper to look this up lazily than cache eagerly and consume a field, since it's rarely encountered
|
|
94
|
-
return (RubyClass)runtime.getModule("Puma").getConstant("HttpParserError");
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
private static RubyString fstringForField(RubyString[] envStrings, byte[] buffer, int field, int flen) {
|
|
98
|
-
EnvKey key = EnvKey.keyForField(buffer, field, flen);
|
|
99
|
-
if (key != null) return envStrings[key.ordinal()];
|
|
100
|
-
return null;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
private static boolean is_ows(int c) {
|
|
104
|
-
return c == ' ' || c == '\t';
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
public static final byte[] HTTP_PREFIX_BYTELIST = ByteList.plain("HTTP_");
|
|
108
|
-
private static final int HTTP_PREFIX_LENGTH = 5;
|
|
109
|
-
public static final byte[] COMMA_SPACE_BYTELIST = ByteList.plain(", ");
|
|
110
|
-
|
|
111
|
-
public static void http_field(Ruby runtime, RubyString[] envStrings, Http11Parser hp, int vlen) {
|
|
112
|
-
RubyString f;
|
|
113
|
-
IRubyObject v;
|
|
114
|
-
int field_len = hp.field_len;
|
|
115
|
-
validateFieldNameLength(runtime, field_len);
|
|
116
|
-
validateFieldValueLength(runtime, vlen);
|
|
117
|
-
|
|
118
|
-
byte[] buffer = hp.buffer;
|
|
119
|
-
int field_start = hp.field_start;
|
|
120
|
-
f = fstringForField(envStrings, buffer, field_start, field_len);
|
|
121
|
-
|
|
122
|
-
if (f == null) {
|
|
123
|
-
f = newHttpHeader(runtime, buffer, field_start, field_len);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
int mark = hp.mark;
|
|
127
|
-
while (vlen > 0) {
|
|
128
|
-
if (!is_ows(buffer[mark + vlen - 1])) break;
|
|
129
|
-
vlen--;
|
|
130
|
-
}
|
|
131
|
-
while (vlen > 0 && is_ows(buffer[mark])) {
|
|
132
|
-
vlen--;
|
|
133
|
-
mark++;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
RubyHash req = hp.data;
|
|
137
|
-
v = req.fastARef(f);
|
|
138
|
-
if (v == null || v.isNil()) {
|
|
139
|
-
req.fastASet(f, RubyString.newStringShared(runtime, buffer, mark, vlen));
|
|
140
|
-
} else {
|
|
141
|
-
RubyString vs = v.convertToString();
|
|
142
|
-
vs.cat(COMMA_SPACE_BYTELIST);
|
|
143
|
-
vs.cat(buffer, mark, vlen);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
private static RubyString newHttpHeader(Ruby runtime, byte[] buffer, int field_start, int field_len) {
|
|
148
|
-
byte[] bytes = new byte[HTTP_PREFIX_LENGTH + field_len];
|
|
149
|
-
System.arraycopy(HTTP_PREFIX_BYTELIST, 0, bytes, 0, HTTP_PREFIX_LENGTH);
|
|
150
|
-
snakeCaseCopy(buffer, field_start, field_len, bytes, HTTP_PREFIX_LENGTH);
|
|
151
|
-
return RubyString.newStringNoCopy(runtime, bytes);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
static void snakeCaseCopy(byte[] s, int soff, int slen, byte[] d, int doff) {
|
|
155
|
-
for (int i = 0; i < slen; i++) {
|
|
156
|
-
int si = soff + i;
|
|
157
|
-
byte sch = s[si];
|
|
158
|
-
int di = doff + i;
|
|
159
|
-
byte dch = snakeUpcase(sch);
|
|
160
|
-
d[di] = dch;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
static byte snakeUpcase(byte ch) {
|
|
165
|
-
if (ch >= 'a' && ch <= 'z')
|
|
166
|
-
ch = (byte) (ch & ~0x20);
|
|
167
|
-
else if (ch == '_')
|
|
168
|
-
ch = ',';
|
|
169
|
-
else if (ch == '-')
|
|
170
|
-
ch = '_';
|
|
171
|
-
return ch;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
public static void request_method(Ruby runtime, RubyString[] envStrings, Http11Parser hp, int length) {
|
|
175
|
-
hp.data.fastASet(envStrings[EnvKey.REQUEST_METHOD.ordinal()], newValueString(runtime, hp, length));
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
public static void request_uri(Ruby runtime, RubyString[] envStrings, Http11Parser hp, int length) {
|
|
179
|
-
validateRequestURILength(runtime, length);
|
|
180
|
-
hp.data.fastASet(envStrings[EnvKey.REQUEST_URI.ordinal()], newValueString(runtime, hp, length));
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
public static void fragment(Ruby runtime, RubyString[] envStrings, Http11Parser hp, int length) {
|
|
184
|
-
validateFragmentLength(runtime, length);
|
|
185
|
-
hp.data.fastASet(envStrings[EnvKey.FRAGMENT.ordinal()], newValueString(runtime, hp, length));
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
public static void request_path(Ruby runtime, RubyString[] envStrings, Http11Parser hp, int length) {
|
|
189
|
-
validateRequestPathLength(runtime, length);
|
|
190
|
-
hp.data.fastASet(envStrings[EnvKey.REQUEST_PATH.ordinal()], newValueString(runtime, hp, length));
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
public static void query_string(Ruby runtime, RubyString[] envStrings, Http11Parser hp, int length) {
|
|
194
|
-
validateQueryStringLength(runtime, length);
|
|
195
|
-
hp.data.fastASet(envStrings[EnvKey.QUERY_STRING.ordinal()], newQueryString(runtime, hp, length));
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
public static void server_protocol(Ruby runtime, RubyString[] envStrings, Http11Parser hp, int length) {
|
|
199
|
-
hp.data.fastASet(envStrings[EnvKey.SERVER_PROTOCOL.ordinal()], newValueString(runtime, hp, length));
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
public void header_done(Ruby runtime, Http11Parser hp, int at, int length) {
|
|
203
|
-
body = RubyString.newStringShared(runtime, hp.buffer, at, length);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
@JRubyMethod
|
|
207
|
-
public IRubyObject initialize() {
|
|
208
|
-
this.hp.init();
|
|
209
|
-
return this;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
@JRubyMethod
|
|
213
|
-
public IRubyObject reset(ThreadContext context) {
|
|
214
|
-
this.hp.init();
|
|
215
|
-
return context.nil;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
@JRubyMethod
|
|
219
|
-
public IRubyObject finish(ThreadContext context) {
|
|
220
|
-
Http11Parser hp = this.hp;
|
|
221
|
-
hp.finish();
|
|
222
|
-
return hp.is_finished() ? context.tru : context.fals;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
@JRubyMethod
|
|
226
|
-
public IRubyObject execute(IRubyObject req_hash, IRubyObject data, IRubyObject start) {
|
|
227
|
-
Ruby runtime = this.runtime;
|
|
228
|
-
int from = RubyNumeric.fix2int(start);
|
|
229
|
-
RubyString dataString = (RubyString) data;
|
|
230
|
-
dataString.setByteListShared();
|
|
231
|
-
ByteList d = dataString.getByteList();
|
|
232
|
-
if(from >= d.length()) {
|
|
233
|
-
throw newHTTPParserError(runtime, "Requested start is after data buffer end.");
|
|
234
|
-
} else {
|
|
235
|
-
Http11Parser hp = this.hp;
|
|
236
|
-
|
|
237
|
-
hp.data = (RubyHash) req_hash;
|
|
238
|
-
|
|
239
|
-
hp.execute(runtime, this, d,from);
|
|
240
|
-
|
|
241
|
-
validateMaxHeaderLength(runtime, hp);
|
|
242
|
-
|
|
243
|
-
if(hp.has_error()) {
|
|
244
|
-
throw newHTTPParserError(runtime, "Invalid HTTP format, parsing fails. Are you trying to open an SSL connection to a non-SSL Puma?");
|
|
245
|
-
} else {
|
|
246
|
-
return runtime.newFixnum(hp.nread);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
@JRubyMethod(name = "error?")
|
|
252
|
-
public IRubyObject has_error(ThreadContext context) {
|
|
253
|
-
return this.hp.has_error() ? context.tru : context.fals;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
@JRubyMethod(name = "finished?")
|
|
257
|
-
public IRubyObject is_finished(ThreadContext context) {
|
|
258
|
-
return this.hp.is_finished() ? context.tru : context.fals;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
@JRubyMethod
|
|
262
|
-
public IRubyObject nread() {
|
|
263
|
-
return runtime.newFixnum(this.hp.nread);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
@JRubyMethod
|
|
267
|
-
public IRubyObject body() {
|
|
268
|
-
return body;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
public final static int MAX_FIELD_NAME_LENGTH = 256;
|
|
272
|
-
public final static String MAX_FIELD_NAME_LENGTH_ERR = "HTTP element FIELD_NAME is longer than the 256 allowed length.";
|
|
273
|
-
public final static int MAX_FIELD_VALUE_LENGTH = 80 * 1024;
|
|
274
|
-
public final static String MAX_FIELD_VALUE_LENGTH_ERR = "HTTP element FIELD_VALUE is longer than the 81920 allowed length.";
|
|
275
|
-
public final static int MAX_REQUEST_URI_LENGTH = getConstLength("PUMA_REQUEST_URI_MAX_LENGTH", 1024 * 12);
|
|
276
|
-
public final static String MAX_REQUEST_URI_LENGTH_ERR = "HTTP element REQUEST_URI is longer than the " + MAX_REQUEST_URI_LENGTH + " allowed length.";
|
|
277
|
-
public final static int MAX_FRAGMENT_LENGTH = 1024;
|
|
278
|
-
public final static String MAX_FRAGMENT_LENGTH_ERR = "HTTP element FRAGMENT is longer than the 1024 allowed length.";
|
|
279
|
-
public final static int MAX_REQUEST_PATH_LENGTH = getConstLength("PUMA_REQUEST_PATH_MAX_LENGTH", 8192);
|
|
280
|
-
public final static String MAX_REQUEST_PATH_LENGTH_ERR = "HTTP element REQUEST_PATH is longer than the " + MAX_REQUEST_PATH_LENGTH + " allowed length.";
|
|
281
|
-
public final static int MAX_QUERY_STRING_LENGTH = getConstLength("PUMA_QUERY_STRING_MAX_LENGTH", 10 * 1024);
|
|
282
|
-
public final static String MAX_QUERY_STRING_LENGTH_ERR = "HTTP element QUERY_STRING is longer than the " + MAX_QUERY_STRING_LENGTH +" allowed length.";
|
|
283
|
-
public final static int MAX_HEADER_LENGTH = 1024 * (80 + 32);
|
|
284
|
-
public final static String MAX_HEADER_LENGTH_ERR = "HTTP element HEADER is longer than the 114688 allowed length.";
|
|
285
|
-
|
|
286
|
-
private static void validateFieldNameLength(Ruby runtime, int field_len) {
|
|
287
|
-
validateMaxLength(runtime, field_len, MAX_FIELD_NAME_LENGTH, MAX_FIELD_NAME_LENGTH_ERR);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
private static void validateFieldValueLength(Ruby runtime, int field_len) {
|
|
291
|
-
validateMaxLength(runtime, field_len, MAX_FIELD_VALUE_LENGTH, MAX_FIELD_VALUE_LENGTH_ERR);
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
private static void validateRequestURILength(Ruby runtime, int length) {
|
|
295
|
-
validateMaxLength(runtime, length, MAX_REQUEST_URI_LENGTH, MAX_REQUEST_URI_LENGTH_ERR);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
private static void validateFragmentLength(Ruby runtime, int length) {
|
|
299
|
-
validateMaxLength(runtime, length, MAX_FRAGMENT_LENGTH, MAX_FRAGMENT_LENGTH_ERR);
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
private static void validateRequestPathLength(Ruby runtime, int length) {
|
|
303
|
-
validateMaxLength(runtime, length, MAX_REQUEST_PATH_LENGTH, MAX_REQUEST_PATH_LENGTH_ERR);
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
private static void validateQueryStringLength(Ruby runtime, int length) {
|
|
307
|
-
validateMaxLength(runtime, length, MAX_QUERY_STRING_LENGTH, MAX_QUERY_STRING_LENGTH_ERR);
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
private static RubyString newValueString(Ruby runtime, Http11Parser hp, int length) {
|
|
311
|
-
return RubyString.newStringShared(runtime, hp.buffer, hp.mark, length);
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
private static RubyString newQueryString(Ruby runtime, Http11Parser hp, int length) {
|
|
315
|
-
return RubyString.newStringShared(runtime, hp.buffer, hp.query_start, length);
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
private static void validateMaxHeaderLength(Ruby runtime, Http11Parser hp) {
|
|
319
|
-
validateMaxLength(runtime, hp.nread, MAX_HEADER_LENGTH, MAX_HEADER_LENGTH_ERR);
|
|
320
|
-
}
|
|
321
|
-
}// Http11
|