puma 3.12.6 → 4.3.12

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 (82) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +155 -3
  3. data/LICENSE +0 -0
  4. data/README.md +76 -48
  5. data/bin/puma-wild +0 -0
  6. data/docs/architecture.md +1 -0
  7. data/docs/deployment.md +24 -4
  8. data/docs/images/puma-connection-flow-no-reactor.png +0 -0
  9. data/docs/images/puma-connection-flow.png +0 -0
  10. data/docs/images/puma-general-arch.png +0 -0
  11. data/docs/nginx.md +0 -0
  12. data/docs/plugins.md +20 -10
  13. data/docs/restart.md +4 -2
  14. data/docs/signals.md +0 -0
  15. data/docs/systemd.md +27 -9
  16. data/docs/tcp_mode.md +96 -0
  17. data/ext/puma_http11/PumaHttp11Service.java +2 -0
  18. data/ext/puma_http11/ext_help.h +0 -0
  19. data/ext/puma_http11/extconf.rb +21 -0
  20. data/ext/puma_http11/http11_parser.c +58 -70
  21. data/ext/puma_http11/http11_parser.h +0 -0
  22. data/ext/puma_http11/http11_parser.java.rl +21 -37
  23. data/ext/puma_http11/http11_parser.rl +0 -0
  24. data/ext/puma_http11/http11_parser_common.rl +4 -4
  25. data/ext/puma_http11/io_buffer.c +0 -0
  26. data/ext/puma_http11/mini_ssl.c +138 -33
  27. data/ext/puma_http11/org/jruby/puma/Http11.java +106 -114
  28. data/ext/puma_http11/org/jruby/puma/Http11Parser.java +86 -99
  29. data/ext/puma_http11/org/jruby/puma/IOBuffer.java +72 -0
  30. data/ext/puma_http11/org/jruby/puma/MiniSSL.java +15 -4
  31. data/ext/puma_http11/puma_http11.c +3 -0
  32. data/lib/puma/accept_nonblock.rb +7 -1
  33. data/lib/puma/app/status.rb +37 -29
  34. data/lib/puma/binder.rb +38 -60
  35. data/lib/puma/cli.rb +4 -0
  36. data/lib/puma/client.rb +285 -208
  37. data/lib/puma/cluster.rb +53 -30
  38. data/lib/puma/commonlogger.rb +0 -0
  39. data/lib/puma/configuration.rb +4 -3
  40. data/lib/puma/const.rb +26 -20
  41. data/lib/puma/control_cli.rb +30 -5
  42. data/lib/puma/detect.rb +0 -0
  43. data/lib/puma/dsl.rb +299 -75
  44. data/lib/puma/events.rb +4 -1
  45. data/lib/puma/io_buffer.rb +1 -6
  46. data/lib/puma/jruby_restart.rb +0 -0
  47. data/lib/puma/launcher.rb +95 -53
  48. data/lib/puma/minissl/context_builder.rb +76 -0
  49. data/lib/puma/minissl.rb +35 -17
  50. data/lib/puma/null_io.rb +0 -0
  51. data/lib/puma/plugin/tmp_restart.rb +2 -0
  52. data/lib/puma/plugin.rb +5 -2
  53. data/lib/puma/rack/builder.rb +2 -0
  54. data/lib/puma/rack/urlmap.rb +2 -0
  55. data/lib/puma/rack_default.rb +2 -0
  56. data/lib/puma/reactor.rb +110 -57
  57. data/lib/puma/runner.rb +11 -3
  58. data/lib/puma/server.rb +89 -61
  59. data/lib/puma/single.rb +3 -3
  60. data/lib/puma/state_file.rb +0 -0
  61. data/lib/puma/tcp_logger.rb +0 -0
  62. data/lib/puma/thread_pool.rb +15 -33
  63. data/lib/puma/util.rb +1 -6
  64. data/lib/puma.rb +8 -0
  65. data/lib/rack/handler/puma.rb +3 -3
  66. data/tools/docker/Dockerfile +16 -0
  67. data/tools/jungle/README.md +0 -0
  68. data/tools/jungle/init.d/README.md +0 -0
  69. data/tools/jungle/init.d/puma +6 -6
  70. data/tools/jungle/rc.d/README.md +0 -0
  71. data/tools/jungle/rc.d/puma.conf +0 -0
  72. data/tools/jungle/upstart/README.md +0 -0
  73. data/tools/jungle/upstart/puma-manager.conf +0 -0
  74. data/tools/jungle/upstart/puma.conf +0 -0
  75. data/tools/trickletest.rb +0 -1
  76. metadata +26 -13
  77. data/lib/puma/compat.rb +0 -14
  78. data/lib/puma/convenient.rb +0 -25
  79. data/lib/puma/daemon_ext.rb +0 -33
  80. data/lib/puma/delegation.rb +0 -13
  81. data/lib/puma/java_io_buffer.rb +0 -47
  82. data/lib/puma/rack/backports/uri/common_193.rb +0 -33
@@ -2,6 +2,8 @@
2
2
  // line 1 "ext/puma_http11/http11_parser.java.rl"
3
3
  package org.jruby.puma;
4
4
 
5
+ import org.jruby.Ruby;
6
+ import org.jruby.RubyHash;
5
7
  import org.jruby.util.ByteList;
6
8
 
7
9
  public class Http11Parser {
@@ -9,12 +11,12 @@ public class Http11Parser {
9
11
  /** Machine **/
10
12
 
11
13
 
12
- // line 65 "ext/puma_http11/http11_parser.java.rl"
14
+ // line 58 "ext/puma_http11/http11_parser.java.rl"
13
15
 
14
16
 
15
17
  /** Data **/
16
18
 
17
- // line 18 "ext/puma_http11/org/jruby/puma/Http11Parser.java"
19
+ // line 20 "ext/puma_http11/org/jruby/puma/Http11Parser.java"
18
20
  private static byte[] init__puma_parser_actions_0()
19
21
  {
20
22
  return new byte [] {
@@ -32,9 +34,9 @@ private static short[] init__puma_parser_key_offsets_0()
32
34
  {
33
35
  return new short [] {
34
36
  0, 0, 8, 17, 27, 29, 30, 31, 32, 33, 34, 36,
35
- 39, 41, 44, 45, 61, 62, 78, 80, 81, 89, 97, 107,
36
- 115, 125, 134, 142, 150, 159, 168, 177, 186, 195, 204, 213,
37
- 222, 231, 240, 249, 258, 267, 276, 285, 294, 303, 312, 313
37
+ 39, 41, 44, 45, 61, 62, 78, 85, 91, 99, 107, 117,
38
+ 125, 134, 142, 150, 159, 168, 177, 186, 195, 204, 213, 222,
39
+ 231, 240, 249, 258, 267, 276, 285, 294, 303, 312, 313
38
40
  };
39
41
  }
40
42
 
@@ -50,11 +52,11 @@ private static char[] init__puma_parser_trans_keys_0()
50
52
  46, 48, 57, 48, 57, 13, 48, 57, 10, 13, 33, 124,
51
53
  126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94,
52
54
  122, 10, 33, 58, 124, 126, 35, 39, 42, 43, 45, 46,
53
- 48, 57, 65, 90, 94, 122, 13, 32, 13, 32, 60, 62,
54
- 127, 0, 31, 34, 35, 32, 60, 62, 127, 0, 31, 34,
55
- 35, 43, 58, 45, 46, 48, 57, 65, 90, 97, 122, 32,
56
- 34, 35, 60, 62, 127, 0, 31, 32, 34, 35, 59, 60,
57
- 62, 63, 127, 0, 31, 32, 34, 35, 60, 62, 63, 127,
55
+ 48, 57, 65, 90, 94, 122, 13, 32, 127, 0, 8, 10,
56
+ 31, 13, 127, 0, 8, 10, 31, 32, 60, 62, 127, 0,
57
+ 31, 34, 35, 32, 60, 62, 127, 0, 31, 34, 35, 43,
58
+ 58, 45, 46, 48, 57, 65, 90, 97, 122, 32, 34, 35,
59
+ 60, 62, 127, 0, 31, 32, 34, 35, 60, 62, 63, 127,
58
60
  0, 31, 32, 34, 35, 60, 62, 127, 0, 31, 32, 34,
59
61
  35, 60, 62, 127, 0, 31, 32, 36, 95, 45, 46, 48,
60
62
  57, 65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90,
@@ -81,9 +83,9 @@ private static byte[] init__puma_parser_single_lengths_0()
81
83
  {
82
84
  return new byte [] {
83
85
  0, 2, 3, 4, 2, 1, 1, 1, 1, 1, 0, 1,
84
- 0, 1, 1, 4, 1, 4, 2, 1, 4, 4, 2, 6,
85
- 8, 7, 6, 6, 3, 3, 3, 3, 3, 3, 3, 3,
86
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 0
86
+ 0, 1, 1, 4, 1, 4, 3, 2, 4, 4, 2, 6,
87
+ 7, 6, 6, 3, 3, 3, 3, 3, 3, 3, 3, 3,
88
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 0
87
89
  };
88
90
  }
89
91
 
@@ -94,9 +96,9 @@ private static byte[] init__puma_parser_range_lengths_0()
94
96
  {
95
97
  return new byte [] {
96
98
  0, 3, 3, 3, 0, 0, 0, 0, 0, 0, 1, 1,
97
- 1, 1, 0, 6, 0, 6, 0, 0, 2, 2, 4, 1,
98
- 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3,
99
- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0
99
+ 1, 1, 0, 6, 0, 6, 2, 2, 2, 2, 4, 1,
100
+ 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3,
101
+ 3, 3, 3, 3, 3, 3, 3, 3, 3, 0, 0
100
102
  };
101
103
  }
102
104
 
@@ -107,9 +109,9 @@ private static short[] init__puma_parser_index_offsets_0()
107
109
  {
108
110
  return new short [] {
109
111
  0, 0, 6, 13, 21, 24, 26, 28, 30, 32, 34, 36,
110
- 39, 41, 44, 46, 57, 59, 70, 73, 75, 82, 89, 96,
111
- 104, 114, 123, 131, 139, 146, 153, 160, 167, 174, 181, 188,
112
- 195, 202, 209, 216, 223, 230, 237, 244, 251, 258, 265, 267
112
+ 39, 41, 44, 46, 57, 59, 70, 76, 81, 88, 95, 102,
113
+ 110, 119, 127, 135, 142, 149, 156, 163, 170, 177, 184, 191,
114
+ 198, 205, 212, 219, 226, 233, 240, 247, 254, 261, 263
113
115
  };
114
116
  }
115
117
 
@@ -125,23 +127,23 @@ private static byte[] init__puma_parser_indicies_0()
125
127
  16, 15, 1, 17, 1, 18, 17, 1, 19, 1, 20, 21,
126
128
  21, 21, 21, 21, 21, 21, 21, 21, 1, 22, 1, 23,
127
129
  24, 23, 23, 23, 23, 23, 23, 23, 23, 1, 26, 27,
128
- 25, 29, 28, 30, 1, 1, 1, 1, 1, 31, 32, 1,
129
- 1, 1, 1, 1, 33, 34, 35, 34, 34, 34, 34, 1,
130
- 8, 1, 9, 1, 1, 1, 1, 35, 36, 1, 38, 39,
131
- 1, 1, 40, 1, 1, 37, 8, 1, 9, 1, 1, 42,
132
- 1, 1, 41, 43, 1, 45, 1, 1, 1, 1, 44, 46,
133
- 1, 48, 1, 1, 1, 1, 47, 2, 49, 49, 49, 49,
134
- 49, 1, 2, 50, 50, 50, 50, 50, 1, 2, 51, 51,
135
- 51, 51, 51, 1, 2, 52, 52, 52, 52, 52, 1, 2,
136
- 53, 53, 53, 53, 53, 1, 2, 54, 54, 54, 54, 54,
137
- 1, 2, 55, 55, 55, 55, 55, 1, 2, 56, 56, 56,
138
- 56, 56, 1, 2, 57, 57, 57, 57, 57, 1, 2, 58,
139
- 58, 58, 58, 58, 1, 2, 59, 59, 59, 59, 59, 1,
140
- 2, 60, 60, 60, 60, 60, 1, 2, 61, 61, 61, 61,
141
- 61, 1, 2, 62, 62, 62, 62, 62, 1, 2, 63, 63,
142
- 63, 63, 63, 1, 2, 64, 64, 64, 64, 64, 1, 2,
143
- 65, 65, 65, 65, 65, 1, 2, 66, 66, 66, 66, 66,
144
- 1, 2, 1, 1, 0
130
+ 1, 1, 1, 25, 29, 1, 1, 1, 28, 30, 1, 1,
131
+ 1, 1, 1, 31, 32, 1, 1, 1, 1, 1, 33, 34,
132
+ 35, 34, 34, 34, 34, 1, 8, 1, 9, 1, 1, 1,
133
+ 1, 35, 36, 1, 38, 1, 1, 39, 1, 1, 37, 40,
134
+ 1, 42, 1, 1, 1, 1, 41, 43, 1, 45, 1, 1,
135
+ 1, 1, 44, 2, 46, 46, 46, 46, 46, 1, 2, 47,
136
+ 47, 47, 47, 47, 1, 2, 48, 48, 48, 48, 48, 1,
137
+ 2, 49, 49, 49, 49, 49, 1, 2, 50, 50, 50, 50,
138
+ 50, 1, 2, 51, 51, 51, 51, 51, 1, 2, 52, 52,
139
+ 52, 52, 52, 1, 2, 53, 53, 53, 53, 53, 1, 2,
140
+ 54, 54, 54, 54, 54, 1, 2, 55, 55, 55, 55, 55,
141
+ 1, 2, 56, 56, 56, 56, 56, 1, 2, 57, 57, 57,
142
+ 57, 57, 1, 2, 58, 58, 58, 58, 58, 1, 2, 59,
143
+ 59, 59, 59, 59, 1, 2, 60, 60, 60, 60, 60, 1,
144
+ 2, 61, 61, 61, 61, 61, 1, 2, 62, 62, 62, 62,
145
+ 62, 1, 2, 63, 63, 63, 63, 63, 1, 2, 1, 1,
146
+ 0
145
147
  };
146
148
  }
147
149
 
@@ -151,12 +153,12 @@ private static final byte _puma_parser_indicies[] = init__puma_parser_indicies_0
151
153
  private static byte[] init__puma_parser_trans_targs_0()
152
154
  {
153
155
  return new byte [] {
154
- 2, 0, 3, 28, 4, 22, 24, 23, 5, 20, 6, 7,
155
- 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 47, 17,
156
+ 2, 0, 3, 27, 4, 22, 24, 23, 5, 20, 6, 7,
157
+ 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 46, 17,
156
158
  18, 19, 14, 18, 19, 14, 5, 21, 5, 21, 22, 23,
157
- 5, 24, 20, 25, 26, 25, 26, 5, 27, 20, 5, 27,
158
- 20, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
159
- 40, 41, 42, 43, 44, 45, 46
159
+ 5, 24, 20, 25, 5, 26, 20, 5, 26, 20, 28, 29,
160
+ 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
161
+ 42, 43, 44, 45
160
162
  };
161
163
  }
162
164
 
@@ -169,9 +171,9 @@ private static byte[] init__puma_parser_trans_actions_0()
169
171
  1, 0, 11, 0, 1, 1, 1, 1, 13, 13, 1, 0,
170
172
  0, 0, 0, 0, 0, 0, 19, 0, 0, 28, 23, 3,
171
173
  5, 7, 31, 7, 0, 9, 25, 1, 15, 0, 0, 0,
172
- 37, 0, 37, 21, 21, 0, 0, 40, 17, 40, 34, 0,
173
- 34, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
174
- 0, 0, 0, 0, 0, 0, 0
174
+ 37, 0, 37, 21, 40, 17, 40, 34, 0, 34, 0, 0,
175
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
176
+ 0, 0, 0, 0
175
177
  };
176
178
  }
177
179
 
@@ -179,17 +181,20 @@ private static final byte _puma_parser_trans_actions[] = init__puma_parser_trans
179
181
 
180
182
 
181
183
  static final int puma_parser_start = 1;
182
- static final int puma_parser_first_final = 47;
184
+ static final int puma_parser_first_final = 46;
183
185
  static final int puma_parser_error = 0;
184
186
 
185
- // line 69 "ext/puma_http11/http11_parser.java.rl"
187
+ static final int puma_parser_en_main = 1;
188
+
189
+
190
+ // line 62 "ext/puma_http11/http11_parser.java.rl"
186
191
 
187
192
  public static interface ElementCB {
188
- public void call(Object data, int at, int length);
193
+ public void call(Ruby runtime, RubyHash data, ByteList buffer, int at, int length);
189
194
  }
190
195
 
191
196
  public static interface FieldCB {
192
- public void call(Object data, int field, int flen, int value, int vlen);
197
+ public void call(Ruby runtime, RubyHash data, ByteList buffer, int field, int flen, int value, int vlen);
193
198
  }
194
199
 
195
200
  public static class HttpParser {
@@ -202,28 +207,19 @@ static final int puma_parser_error = 0;
202
207
  int field_len;
203
208
  int query_start;
204
209
 
205
- Object data;
210
+ RubyHash data;
206
211
  ByteList buffer;
207
212
 
208
- public FieldCB http_field;
209
- public ElementCB request_method;
210
- public ElementCB request_uri;
211
- public ElementCB fragment;
212
- public ElementCB request_path;
213
- public ElementCB query_string;
214
- public ElementCB http_version;
215
- public ElementCB header_done;
216
-
217
213
  public void init() {
218
214
  cs = 0;
219
215
 
220
-
221
- // line 225 "ext/puma_http11/org/jruby/puma/Http11Parser.java"
216
+
217
+ // line 218 "ext/puma_http11/org/jruby/puma/Http11Parser.java"
222
218
  {
223
219
  cs = puma_parser_start;
224
220
  }
225
221
 
226
- // line 104 "ext/puma_http11/http11_parser.java.rl"
222
+ // line 88 "ext/puma_http11/http11_parser.java.rl"
227
223
 
228
224
  body_start = 0;
229
225
  content_len = 0;
@@ -236,7 +232,7 @@ static final int puma_parser_error = 0;
236
232
 
237
233
  public final HttpParser parser = new HttpParser();
238
234
 
239
- public int execute(ByteList buffer, int off) {
235
+ public int execute(Ruby runtime, Http11 http, ByteList buffer, int off) {
240
236
  int p, pe;
241
237
  int cs = parser.cs;
242
238
  int len = buffer.length();
@@ -249,8 +245,8 @@ static final int puma_parser_error = 0;
249
245
  byte[] data = buffer.bytes();
250
246
  parser.buffer = buffer;
251
247
 
252
-
253
- // line 257 "ext/puma_http11/org/jruby/puma/Http11Parser.java"
248
+
249
+ // line 250 "ext/puma_http11/org/jruby/puma/Http11Parser.java"
254
250
  {
255
251
  int _klen;
256
252
  int _trans = 0;
@@ -331,91 +327,82 @@ case 1:
331
327
  switch ( _puma_parser_actions[_acts++] )
332
328
  {
333
329
  case 0:
334
- // line 13 "ext/puma_http11/http11_parser.java.rl"
330
+ // line 15 "ext/puma_http11/http11_parser.java.rl"
335
331
  {parser.mark = p; }
336
332
  break;
337
333
  case 1:
338
- // line 15 "ext/puma_http11/http11_parser.java.rl"
334
+ // line 17 "ext/puma_http11/http11_parser.java.rl"
339
335
  { parser.field_start = p; }
340
336
  break;
341
337
  case 2:
342
- // line 16 "ext/puma_http11/http11_parser.java.rl"
338
+ // line 18 "ext/puma_http11/http11_parser.java.rl"
343
339
  { /* FIXME stub */ }
344
340
  break;
345
341
  case 3:
346
- // line 17 "ext/puma_http11/http11_parser.java.rl"
347
- {
342
+ // line 19 "ext/puma_http11/http11_parser.java.rl"
343
+ {
348
344
  parser.field_len = p-parser.field_start;
349
345
  }
350
346
  break;
351
347
  case 4:
352
- // line 21 "ext/puma_http11/http11_parser.java.rl"
348
+ // line 23 "ext/puma_http11/http11_parser.java.rl"
353
349
  { parser.mark = p; }
354
350
  break;
355
351
  case 5:
356
- // line 22 "ext/puma_http11/http11_parser.java.rl"
352
+ // line 24 "ext/puma_http11/http11_parser.java.rl"
357
353
  {
358
- if(parser.http_field != null) {
359
- parser.http_field.call(parser.data, parser.field_start, parser.field_len, parser.mark, p-parser.mark);
360
- }
354
+ Http11.http_field(runtime, parser.data, parser.buffer, parser.field_start, parser.field_len, parser.mark, p-parser.mark);
361
355
  }
362
356
  break;
363
357
  case 6:
364
358
  // line 27 "ext/puma_http11/http11_parser.java.rl"
365
359
  {
366
- if(parser.request_method != null)
367
- parser.request_method.call(parser.data, parser.mark, p-parser.mark);
360
+ Http11.request_method(runtime, parser.data, parser.buffer, parser.mark, p-parser.mark);
368
361
  }
369
362
  break;
370
363
  case 7:
371
- // line 31 "ext/puma_http11/http11_parser.java.rl"
364
+ // line 30 "ext/puma_http11/http11_parser.java.rl"
372
365
  {
373
- if(parser.request_uri != null)
374
- parser.request_uri.call(parser.data, parser.mark, p-parser.mark);
366
+ Http11.request_uri(runtime, parser.data, parser.buffer, parser.mark, p-parser.mark);
375
367
  }
376
368
  break;
377
369
  case 8:
378
- // line 35 "ext/puma_http11/http11_parser.java.rl"
370
+ // line 33 "ext/puma_http11/http11_parser.java.rl"
379
371
  {
380
- if(parser.fragment != null)
381
- parser.fragment.call(parser.data, parser.mark, p-parser.mark);
372
+ Http11.fragment(runtime, parser.data, parser.buffer, parser.mark, p-parser.mark);
382
373
  }
383
374
  break;
384
375
  case 9:
385
- // line 40 "ext/puma_http11/http11_parser.java.rl"
376
+ // line 37 "ext/puma_http11/http11_parser.java.rl"
386
377
  {parser.query_start = p; }
387
378
  break;
388
379
  case 10:
389
- // line 41 "ext/puma_http11/http11_parser.java.rl"
380
+ // line 38 "ext/puma_http11/http11_parser.java.rl"
390
381
  {
391
- if(parser.query_string != null)
392
- parser.query_string.call(parser.data, parser.query_start, p-parser.query_start);
382
+ Http11.query_string(runtime, parser.data, parser.buffer, parser.query_start, p-parser.query_start);
393
383
  }
394
384
  break;
395
385
  case 11:
396
- // line 46 "ext/puma_http11/http11_parser.java.rl"
386
+ // line 42 "ext/puma_http11/http11_parser.java.rl"
397
387
  {
398
- if(parser.http_version != null)
399
- parser.http_version.call(parser.data, parser.mark, p-parser.mark);
388
+ Http11.http_version(runtime, parser.data, parser.buffer, parser.mark, p-parser.mark);
400
389
  }
401
390
  break;
402
391
  case 12:
403
- // line 51 "ext/puma_http11/http11_parser.java.rl"
392
+ // line 46 "ext/puma_http11/http11_parser.java.rl"
404
393
  {
405
- if(parser.request_path != null)
406
- parser.request_path.call(parser.data, parser.mark, p-parser.mark);
394
+ Http11.request_path(runtime, parser.data, parser.buffer, parser.mark, p-parser.mark);
407
395
  }
408
396
  break;
409
397
  case 13:
410
- // line 56 "ext/puma_http11/http11_parser.java.rl"
411
- {
398
+ // line 50 "ext/puma_http11/http11_parser.java.rl"
399
+ {
412
400
  parser.body_start = p + 1;
413
- if(parser.header_done != null)
414
- parser.header_done.call(parser.data, p + 1, pe - p - 1);
401
+ http.header_done(runtime, parser.data, parser.buffer, p + 1, pe - p - 1);
415
402
  { p += 1; _goto_targ = 5; if (true) continue _goto;}
416
403
  }
417
404
  break;
418
- // line 422 "ext/puma_http11/org/jruby/puma/Http11Parser.java"
405
+ // line 406 "ext/puma_http11/org/jruby/puma/Http11Parser.java"
419
406
  }
420
407
  }
421
408
  }
@@ -435,11 +422,11 @@ case 5:
435
422
  break; }
436
423
  }
437
424
 
438
- // line 130 "ext/puma_http11/http11_parser.java.rl"
425
+ // line 114 "ext/puma_http11/http11_parser.java.rl"
439
426
 
440
427
  parser.cs = cs;
441
428
  parser.nread += (p - off);
442
-
429
+
443
430
  assert p <= pe : "buffer overflow after parsing execute";
444
431
  assert parser.nread <= len : "nread longer than length";
445
432
  assert parser.body_start <= len : "body starts after buffer end";
@@ -0,0 +1,72 @@
1
+ package org.jruby.puma;
2
+
3
+ import org.jruby.*;
4
+ import org.jruby.anno.JRubyMethod;
5
+ import org.jruby.runtime.ObjectAllocator;
6
+ import org.jruby.runtime.ThreadContext;
7
+ import org.jruby.runtime.builtin.IRubyObject;
8
+ import org.jruby.util.ByteList;
9
+
10
+ /**
11
+ * @author kares
12
+ */
13
+ public class IOBuffer extends RubyObject {
14
+
15
+ private static final ObjectAllocator ALLOCATOR = new ObjectAllocator() {
16
+ public IRubyObject allocate(Ruby runtime, RubyClass klass) {
17
+ return new IOBuffer(runtime, klass);
18
+ }
19
+ };
20
+
21
+ public static void createIOBuffer(Ruby runtime) {
22
+ RubyModule mPuma = runtime.defineModule("Puma");
23
+ RubyClass cIOBuffer = mPuma.defineClassUnder("IOBuffer", runtime.getObject(), ALLOCATOR);
24
+ cIOBuffer.defineAnnotatedMethods(IOBuffer.class);
25
+ }
26
+
27
+ private static final int DEFAULT_SIZE = 4096;
28
+
29
+ final ByteList buffer = new ByteList(DEFAULT_SIZE);
30
+
31
+ IOBuffer(Ruby runtime, RubyClass klass) {
32
+ super(runtime, klass);
33
+ }
34
+
35
+ @JRubyMethod
36
+ public RubyInteger used(ThreadContext context) {
37
+ return context.runtime.newFixnum(buffer.getRealSize());
38
+ }
39
+
40
+ @JRubyMethod
41
+ public RubyInteger capacity(ThreadContext context) {
42
+ return context.runtime.newFixnum(buffer.unsafeBytes().length);
43
+ }
44
+
45
+ @JRubyMethod
46
+ public IRubyObject reset() {
47
+ buffer.setRealSize(0);
48
+ return this;
49
+ }
50
+
51
+ @JRubyMethod(name = { "to_s", "to_str" })
52
+ public RubyString to_s(ThreadContext context) {
53
+ return RubyString.newStringShared(context.runtime, buffer.unsafeBytes(), 0, buffer.getRealSize());
54
+ }
55
+
56
+ @JRubyMethod(name = "<<")
57
+ public IRubyObject add(IRubyObject str) {
58
+ addImpl(str.convertToString());
59
+ return this;
60
+ }
61
+
62
+ @JRubyMethod(rest = true)
63
+ public IRubyObject append(IRubyObject[] strs) {
64
+ for (IRubyObject str : strs) addImpl(str.convertToString());
65
+ return this;
66
+ }
67
+
68
+ private void addImpl(RubyString str) {
69
+ buffer.append(str.getByteList());
70
+ }
71
+
72
+ }
@@ -23,6 +23,7 @@ import javax.net.ssl.SSLPeerUnverifiedException;
23
23
  import javax.net.ssl.SSLSession;
24
24
  import java.io.FileInputStream;
25
25
  import java.io.IOException;
26
+ import java.nio.Buffer;
26
27
  import java.nio.ByteBuffer;
27
28
  import java.security.KeyManagementException;
28
29
  import java.security.KeyStore;
@@ -65,7 +66,7 @@ public class MiniSSL extends RubyObject {
65
66
 
66
67
  public void clear() { buffer.clear(); }
67
68
  public void compact() { buffer.compact(); }
68
- public void flip() { buffer.flip(); }
69
+ public void flip() { ((Buffer) buffer).flip(); }
69
70
  public boolean hasRemaining() { return buffer.hasRemaining(); }
70
71
  public int position() { return buffer.position(); }
71
72
 
@@ -89,7 +90,7 @@ public class MiniSSL extends RubyObject {
89
90
  public void resize(int newCapacity) {
90
91
  if (newCapacity > buffer.capacity()) {
91
92
  ByteBuffer dstTmp = ByteBuffer.allocate(newCapacity);
92
- buffer.flip();
93
+ flip();
93
94
  dstTmp.put(buffer);
94
95
  buffer = dstTmp;
95
96
  } else {
@@ -101,7 +102,7 @@ public class MiniSSL extends RubyObject {
101
102
  * Drains the buffer to a ByteList, or returns null for an empty buffer
102
103
  */
103
104
  public ByteList asByteList() {
104
- buffer.flip();
105
+ flip();
105
106
  if (!buffer.hasRemaining()) {
106
107
  buffer.clear();
107
108
  return null;
@@ -158,7 +159,17 @@ public class MiniSSL extends RubyObject {
158
159
  sslCtx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
159
160
  engine = sslCtx.createSSLEngine();
160
161
 
161
- String[] protocols = new String[] { "TLSv1", "TLSv1.1", "TLSv1.2" };
162
+ String[] protocols;
163
+ if(miniSSLContext.callMethod(threadContext, "no_tlsv1").isTrue()) {
164
+ protocols = new String[] { "TLSv1.1", "TLSv1.2" };
165
+ } else {
166
+ protocols = new String[] { "TLSv1", "TLSv1.1", "TLSv1.2" };
167
+ }
168
+
169
+ if(miniSSLContext.callMethod(threadContext, "no_tlsv1_1").isTrue()) {
170
+ protocols = new String[] { "TLSv1.2" };
171
+ }
172
+
162
173
  engine.setEnabledProtocols(protocols);
163
174
  engine.setUseClientMode(false);
164
175
 
@@ -10,6 +10,7 @@
10
10
  #include "ext_help.h"
11
11
  #include <assert.h>
12
12
  #include <string.h>
13
+ #include <ctype.h>
13
14
  #include "http11_parser.h"
14
15
 
15
16
  #ifndef MANAGED_STRINGS
@@ -200,6 +201,8 @@ void http_field(puma_parser* hp, const char *field, size_t flen,
200
201
  f = rb_str_new(hp->buf, new_size);
201
202
  }
202
203
 
204
+ while (vlen > 0 && isspace(value[vlen - 1])) vlen--;
205
+
203
206
  /* check for duplicate header */
204
207
  v = rb_hash_aref(hp->request, f);
205
208
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'openssl'
2
4
 
3
5
  module OpenSSL
@@ -13,7 +15,11 @@ module OpenSSL
13
15
  ssl.accept if @start_immediately
14
16
  ssl
15
17
  rescue SSLError => ex
16
- sock.close
18
+ if ssl
19
+ ssl.close
20
+ else
21
+ sock.close
22
+ end
17
23
  raise ex
18
24
  end
19
25
  end
@@ -1,26 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Puma
2
4
  module App
5
+ # Check out {#call}'s source code to see what actions this web application
6
+ # can respond to.
3
7
  class Status
4
- def initialize(cli)
5
- @cli = cli
6
- @auth_token = nil
7
- end
8
8
  OK_STATUS = '{ "status": "ok" }'.freeze
9
9
 
10
- attr_accessor :auth_token
11
-
12
- def authenticate(env)
13
- return true unless @auth_token
14
- env['QUERY_STRING'].to_s.split(/&;/).include?("token=#{@auth_token}")
15
- end
16
-
17
- def rack_response(status, body, content_type='application/json')
18
- headers = {
19
- 'Content-Type' => content_type,
20
- 'Content-Length' => body.bytesize.to_s
21
- }
22
-
23
- [status, headers, [body]]
10
+ def initialize(cli, token = nil)
11
+ @cli = cli
12
+ @auth_token = token
24
13
  end
25
14
 
26
15
  def call(env)
@@ -28,47 +17,66 @@ module Puma
28
17
  return rack_response(403, 'Invalid auth token', 'text/plain')
29
18
  end
30
19
 
20
+ if env['PATH_INFO'] =~ /\/(gc-stats|stats|thread-backtraces)$/
21
+ require 'json'
22
+ end
23
+
31
24
  case env['PATH_INFO']
32
25
  when /\/stop$/
33
26
  @cli.stop
34
- return rack_response(200, OK_STATUS)
27
+ rack_response(200, OK_STATUS)
35
28
 
36
29
  when /\/halt$/
37
30
  @cli.halt
38
- return rack_response(200, OK_STATUS)
31
+ rack_response(200, OK_STATUS)
39
32
 
40
33
  when /\/restart$/
41
34
  @cli.restart
42
- return rack_response(200, OK_STATUS)
35
+ rack_response(200, OK_STATUS)
43
36
 
44
37
  when /\/phased-restart$/
45
38
  if !@cli.phased_restart
46
- return rack_response(404, '{ "error": "phased restart not available" }')
39
+ rack_response(404, '{ "error": "phased restart not available" }')
47
40
  else
48
- return rack_response(200, OK_STATUS)
41
+ rack_response(200, OK_STATUS)
49
42
  end
50
43
 
51
44
  when /\/reload-worker-directory$/
52
45
  if !@cli.send(:reload_worker_directory)
53
- return rack_response(404, '{ "error": "reload_worker_directory not available" }')
46
+ rack_response(404, '{ "error": "reload_worker_directory not available" }')
54
47
  else
55
- return rack_response(200, OK_STATUS)
48
+ rack_response(200, OK_STATUS)
56
49
  end
57
50
 
58
51
  when /\/gc$/
59
52
  GC.start
60
- return rack_response(200, OK_STATUS)
53
+ rack_response(200, OK_STATUS)
61
54
 
62
55
  when /\/gc-stats$/
63
- json = "{" + GC.stat.map { |k, v| "\"#{k}\": #{v}" }.join(",") + "}"
64
- return rack_response(200, json)
56
+ rack_response(200, GC.stat.to_json)
65
57
 
66
58
  when /\/stats$/
67
- return rack_response(200, @cli.stats)
59
+ rack_response(200, @cli.stats)
68
60
  else
69
61
  rack_response 404, "Unsupported action", 'text/plain'
70
62
  end
71
63
  end
64
+
65
+ private
66
+
67
+ def authenticate(env)
68
+ return true unless @auth_token
69
+ env['QUERY_STRING'].to_s.split(/&;/).include?("token=#{@auth_token}")
70
+ end
71
+
72
+ def rack_response(status, body, content_type='application/json')
73
+ headers = {
74
+ 'Content-Type' => content_type,
75
+ 'Content-Length' => body.bytesize.to_s
76
+ }
77
+
78
+ [status, headers, [body]]
79
+ end
72
80
  end
73
81
  end
74
82
  end