puma 4.3.0

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 (80) hide show
  1. checksums.yaml +7 -0
  2. data/History.md +1532 -0
  3. data/LICENSE +26 -0
  4. data/README.md +291 -0
  5. data/bin/puma +10 -0
  6. data/bin/puma-wild +31 -0
  7. data/bin/pumactl +12 -0
  8. data/docs/architecture.md +37 -0
  9. data/docs/deployment.md +111 -0
  10. data/docs/images/puma-connection-flow-no-reactor.png +0 -0
  11. data/docs/images/puma-connection-flow.png +0 -0
  12. data/docs/images/puma-general-arch.png +0 -0
  13. data/docs/nginx.md +80 -0
  14. data/docs/plugins.md +38 -0
  15. data/docs/restart.md +41 -0
  16. data/docs/signals.md +96 -0
  17. data/docs/systemd.md +290 -0
  18. data/docs/tcp_mode.md +96 -0
  19. data/ext/puma_http11/PumaHttp11Service.java +19 -0
  20. data/ext/puma_http11/ext_help.h +15 -0
  21. data/ext/puma_http11/extconf.rb +28 -0
  22. data/ext/puma_http11/http11_parser.c +1044 -0
  23. data/ext/puma_http11/http11_parser.h +65 -0
  24. data/ext/puma_http11/http11_parser.java.rl +145 -0
  25. data/ext/puma_http11/http11_parser.rl +147 -0
  26. data/ext/puma_http11/http11_parser_common.rl +54 -0
  27. data/ext/puma_http11/io_buffer.c +155 -0
  28. data/ext/puma_http11/mini_ssl.c +553 -0
  29. data/ext/puma_http11/org/jruby/puma/Http11.java +226 -0
  30. data/ext/puma_http11/org/jruby/puma/Http11Parser.java +455 -0
  31. data/ext/puma_http11/org/jruby/puma/IOBuffer.java +72 -0
  32. data/ext/puma_http11/org/jruby/puma/MiniSSL.java +363 -0
  33. data/ext/puma_http11/puma_http11.c +502 -0
  34. data/lib/puma.rb +31 -0
  35. data/lib/puma/accept_nonblock.rb +29 -0
  36. data/lib/puma/app/status.rb +80 -0
  37. data/lib/puma/binder.rb +385 -0
  38. data/lib/puma/cli.rb +239 -0
  39. data/lib/puma/client.rb +494 -0
  40. data/lib/puma/cluster.rb +554 -0
  41. data/lib/puma/commonlogger.rb +108 -0
  42. data/lib/puma/configuration.rb +362 -0
  43. data/lib/puma/const.rb +235 -0
  44. data/lib/puma/control_cli.rb +289 -0
  45. data/lib/puma/detect.rb +15 -0
  46. data/lib/puma/dsl.rb +740 -0
  47. data/lib/puma/events.rb +156 -0
  48. data/lib/puma/io_buffer.rb +4 -0
  49. data/lib/puma/jruby_restart.rb +84 -0
  50. data/lib/puma/launcher.rb +475 -0
  51. data/lib/puma/minissl.rb +278 -0
  52. data/lib/puma/minissl/context_builder.rb +76 -0
  53. data/lib/puma/null_io.rb +44 -0
  54. data/lib/puma/plugin.rb +120 -0
  55. data/lib/puma/plugin/tmp_restart.rb +36 -0
  56. data/lib/puma/rack/builder.rb +301 -0
  57. data/lib/puma/rack/urlmap.rb +93 -0
  58. data/lib/puma/rack_default.rb +9 -0
  59. data/lib/puma/reactor.rb +400 -0
  60. data/lib/puma/runner.rb +192 -0
  61. data/lib/puma/server.rb +1030 -0
  62. data/lib/puma/single.rb +123 -0
  63. data/lib/puma/state_file.rb +31 -0
  64. data/lib/puma/tcp_logger.rb +41 -0
  65. data/lib/puma/thread_pool.rb +328 -0
  66. data/lib/puma/util.rb +124 -0
  67. data/lib/rack/handler/puma.rb +115 -0
  68. data/tools/docker/Dockerfile +16 -0
  69. data/tools/jungle/README.md +19 -0
  70. data/tools/jungle/init.d/README.md +61 -0
  71. data/tools/jungle/init.d/puma +421 -0
  72. data/tools/jungle/init.d/run-puma +18 -0
  73. data/tools/jungle/rc.d/README.md +74 -0
  74. data/tools/jungle/rc.d/puma +61 -0
  75. data/tools/jungle/rc.d/puma.conf +10 -0
  76. data/tools/jungle/upstart/README.md +61 -0
  77. data/tools/jungle/upstart/puma-manager.conf +31 -0
  78. data/tools/jungle/upstart/puma.conf +69 -0
  79. data/tools/trickletest.rb +44 -0
  80. metadata +144 -0
@@ -0,0 +1,96 @@
1
+ # TCP mode
2
+
3
+ Puma also could be used as a TCP server to process incoming TCP
4
+ connections.
5
+
6
+
7
+ ## Configuration
8
+
9
+ TCP mode can be enabled with CLI option `--tcp-mode`:
10
+
11
+ ```
12
+ $ puma --tcp-mode
13
+ ```
14
+
15
+ Default ip and port to listen to are `0.0.0.0` and `9292`. You can configure
16
+ them with `--port` and `--bind` options:
17
+
18
+ ```
19
+ $ puma --tcp-mode --bind tcp://127.0.0.1:9293
20
+ $ puma --tcp-mode --port 9293
21
+ ```
22
+
23
+ TCP mode could be set with a configuration file as well with `tcp_mode`
24
+ and `tcp_mode!` methods:
25
+
26
+ ```
27
+ # config/puma.rb
28
+ tcp_mode
29
+ ```
30
+
31
+ When Puma starts in the TCP mode it prints the corresponding message:
32
+
33
+ ```
34
+ puma --tcp-mode
35
+ Puma starting in single mode...
36
+ ...
37
+ * Mode: Lopez Express (tcp)
38
+ ```
39
+
40
+
41
+ ## How to declare an application
42
+
43
+ An application to process TCP connections should be declared as a
44
+ callable object which accepts `env` and `socket` arguments.
45
+
46
+ `env` argument is a Hash with following structure:
47
+
48
+ ```ruby
49
+ { "thread" => {}, "REMOTE_ADDR" => "127.0.0.1:51133", "log" => "#<Proc:0x000..." }
50
+ ```
51
+
52
+ It consists of:
53
+ * `thread` - a Hash for each thread in the thread pool that could be
54
+ used to store information between requests
55
+ * `REMOTE_ADDR` - a client ip address
56
+ * `log` - a proc object to write something down
57
+
58
+ `log` object could be used this way:
59
+
60
+ ```ruby
61
+ env['log'].call('message to log')
62
+ #> 19/Oct/2019 20:28:53 - 127.0.0.1:51266 - message to log
63
+ ```
64
+
65
+
66
+ ## Example of an application
67
+
68
+ Let's look at an example of a simple application which just echoes
69
+ incoming string:
70
+
71
+ ```ruby
72
+ # config/puma.rb
73
+ app do |env, socket|
74
+ s = socket.gets
75
+ socket.puts "Echo #{s}"
76
+ end
77
+ ```
78
+
79
+ We can easily access the TCP server with `telnet` command and receive an
80
+ echo:
81
+
82
+ ```shell
83
+ telnet 0.0.0.0 9293
84
+ Trying 0.0.0.0...
85
+ Connected to 0.0.0.0.
86
+ Escape character is '^]'.
87
+ sssss
88
+ Echo sssss
89
+ ^CConnection closed by foreign host.
90
+ ```
91
+
92
+
93
+ ## Socket management
94
+
95
+ After the application finishes, Puma closes the socket. In order to
96
+ prevent this, the application should set `env['detach'] = true`.
@@ -0,0 +1,19 @@
1
+ package puma;
2
+
3
+ import java.io.IOException;
4
+
5
+ import org.jruby.Ruby;
6
+ import org.jruby.runtime.load.BasicLibraryService;
7
+
8
+ import org.jruby.puma.Http11;
9
+ import org.jruby.puma.IOBuffer;
10
+ import org.jruby.puma.MiniSSL;
11
+
12
+ public class PumaHttp11Service implements BasicLibraryService {
13
+ public boolean basicLoad(final Ruby runtime) throws IOException {
14
+ Http11.createHttp11(runtime);
15
+ IOBuffer.createIOBuffer(runtime);
16
+ MiniSSL.createMiniSSL(runtime);
17
+ return true;
18
+ }
19
+ }
@@ -0,0 +1,15 @@
1
+ #ifndef ext_help_h
2
+ #define ext_help_h
3
+
4
+ #define RAISE_NOT_NULL(T) if(T == NULL) rb_raise(rb_eArgError, "%s", "NULL found for " # T " when shouldn't be.");
5
+ #define DATA_GET(from,type,name) Data_Get_Struct(from,type,name); RAISE_NOT_NULL(name);
6
+ #define REQUIRE_TYPE(V, T) if(TYPE(V) != T) rb_raise(rb_eTypeError, "%s", "Wrong argument type for " # V " required " # T);
7
+ #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
8
+
9
+ #ifdef DEBUG
10
+ #define TRACE() fprintf(stderr, "> %s:%d:%s\n", __FILE__, __LINE__, __FUNCTION__)
11
+ #else
12
+ #define TRACE()
13
+ #endif
14
+
15
+ #endif
@@ -0,0 +1,28 @@
1
+ require 'mkmf'
2
+
3
+ dir_config("puma_http11")
4
+ if RUBY_PLATFORM[/mingw32/]
5
+ append_cflags '-D_FORTIFY_SOURCE=2'
6
+ append_ldflags '-fstack-protector'
7
+ have_library 'ssp'
8
+ end
9
+
10
+ unless ENV["DISABLE_SSL"]
11
+ dir_config("openssl")
12
+
13
+ if %w'crypto libeay32'.find {|crypto| have_library(crypto, 'BIO_read')} and
14
+ %w'ssl ssleay32'.find {|ssl| have_library(ssl, 'SSL_CTX_new')}
15
+
16
+ have_header "openssl/bio.h"
17
+
18
+ # below is yes for 1.0.2 & later
19
+ have_func "DTLS_method" , "openssl/ssl.h"
20
+
21
+ # below are yes for 1.1.0 & later, may need to check func rather than macro
22
+ # with versions after 1.1.1
23
+ have_func "TLS_server_method" , "openssl/ssl.h"
24
+ have_macro "SSL_CTX_set_min_proto_version", "openssl/ssl.h"
25
+ end
26
+ end
27
+
28
+ create_makefile("puma/puma_http11")
@@ -0,0 +1,1044 @@
1
+
2
+ #line 1 "ext/puma_http11/http11_parser.rl"
3
+ /**
4
+ * Copyright (c) 2005 Zed A. Shaw
5
+ * You can redistribute it and/or modify it under the same terms as Ruby.
6
+ * License 3-clause BSD
7
+ */
8
+ #include "http11_parser.h"
9
+ #include <stdio.h>
10
+ #include <assert.h>
11
+ #include <stdlib.h>
12
+ #include <ctype.h>
13
+ #include <string.h>
14
+
15
+ /*
16
+ * capitalizes all lower-case ASCII characters,
17
+ * converts dashes to underscores.
18
+ */
19
+ static void snake_upcase_char(char *c)
20
+ {
21
+ if (*c >= 'a' && *c <= 'z')
22
+ *c &= ~0x20;
23
+ else if (*c == '-')
24
+ *c = '_';
25
+ }
26
+
27
+ #define LEN(AT, FPC) (FPC - buffer - parser->AT)
28
+ #define MARK(M,FPC) (parser->M = (FPC) - buffer)
29
+ #define PTR_TO(F) (buffer + parser->F)
30
+
31
+ /** Machine **/
32
+
33
+
34
+ #line 79 "ext/puma_http11/http11_parser.rl"
35
+
36
+
37
+ /** Data **/
38
+
39
+ #line 40 "ext/puma_http11/http11_parser.c"
40
+ static const int puma_parser_start = 1;
41
+ static const int puma_parser_first_final = 46;
42
+ static const int puma_parser_error = 0;
43
+
44
+ static const int puma_parser_en_main = 1;
45
+
46
+
47
+ #line 83 "ext/puma_http11/http11_parser.rl"
48
+
49
+ int puma_parser_init(puma_parser *parser) {
50
+ int cs = 0;
51
+
52
+ #line 53 "ext/puma_http11/http11_parser.c"
53
+ {
54
+ cs = puma_parser_start;
55
+ }
56
+
57
+ #line 87 "ext/puma_http11/http11_parser.rl"
58
+ parser->cs = cs;
59
+ parser->body_start = 0;
60
+ parser->content_len = 0;
61
+ parser->mark = 0;
62
+ parser->nread = 0;
63
+ parser->field_len = 0;
64
+ parser->field_start = 0;
65
+ parser->request = Qnil;
66
+ parser->body = Qnil;
67
+
68
+ return 1;
69
+ }
70
+
71
+
72
+ /** exec **/
73
+ size_t puma_parser_execute(puma_parser *parser, const char *buffer, size_t len, size_t off) {
74
+ const char *p, *pe;
75
+ int cs = parser->cs;
76
+
77
+ assert(off <= len && "offset past end of buffer");
78
+
79
+ p = buffer+off;
80
+ pe = buffer+len;
81
+
82
+ /* assert(*pe == '\0' && "pointer does not end on NUL"); */
83
+ assert((size_t) (pe - p) == len - off && "pointers aren't same distance");
84
+
85
+
86
+ #line 87 "ext/puma_http11/http11_parser.c"
87
+ {
88
+ if ( p == pe )
89
+ goto _test_eof;
90
+ switch ( cs )
91
+ {
92
+ case 1:
93
+ switch( (*p) ) {
94
+ case 36: goto tr0;
95
+ case 95: goto tr0;
96
+ }
97
+ if ( (*p) < 48 ) {
98
+ if ( 45 <= (*p) && (*p) <= 46 )
99
+ goto tr0;
100
+ } else if ( (*p) > 57 ) {
101
+ if ( 65 <= (*p) && (*p) <= 90 )
102
+ goto tr0;
103
+ } else
104
+ goto tr0;
105
+ goto st0;
106
+ st0:
107
+ cs = 0;
108
+ goto _out;
109
+ tr0:
110
+ #line 35 "ext/puma_http11/http11_parser.rl"
111
+ { MARK(mark, p); }
112
+ goto st2;
113
+ st2:
114
+ if ( ++p == pe )
115
+ goto _test_eof2;
116
+ case 2:
117
+ #line 118 "ext/puma_http11/http11_parser.c"
118
+ switch( (*p) ) {
119
+ case 32: goto tr2;
120
+ case 36: goto st27;
121
+ case 95: goto st27;
122
+ }
123
+ if ( (*p) < 48 ) {
124
+ if ( 45 <= (*p) && (*p) <= 46 )
125
+ goto st27;
126
+ } else if ( (*p) > 57 ) {
127
+ if ( 65 <= (*p) && (*p) <= 90 )
128
+ goto st27;
129
+ } else
130
+ goto st27;
131
+ goto st0;
132
+ tr2:
133
+ #line 48 "ext/puma_http11/http11_parser.rl"
134
+ {
135
+ parser->request_method(parser, PTR_TO(mark), LEN(mark, p));
136
+ }
137
+ goto st3;
138
+ st3:
139
+ if ( ++p == pe )
140
+ goto _test_eof3;
141
+ case 3:
142
+ #line 143 "ext/puma_http11/http11_parser.c"
143
+ switch( (*p) ) {
144
+ case 42: goto tr4;
145
+ case 43: goto tr5;
146
+ case 47: goto tr6;
147
+ case 58: goto tr7;
148
+ }
149
+ if ( (*p) < 65 ) {
150
+ if ( 45 <= (*p) && (*p) <= 57 )
151
+ goto tr5;
152
+ } else if ( (*p) > 90 ) {
153
+ if ( 97 <= (*p) && (*p) <= 122 )
154
+ goto tr5;
155
+ } else
156
+ goto tr5;
157
+ goto st0;
158
+ tr4:
159
+ #line 35 "ext/puma_http11/http11_parser.rl"
160
+ { MARK(mark, p); }
161
+ goto st4;
162
+ st4:
163
+ if ( ++p == pe )
164
+ goto _test_eof4;
165
+ case 4:
166
+ #line 167 "ext/puma_http11/http11_parser.c"
167
+ switch( (*p) ) {
168
+ case 32: goto tr8;
169
+ case 35: goto tr9;
170
+ }
171
+ goto st0;
172
+ tr8:
173
+ #line 51 "ext/puma_http11/http11_parser.rl"
174
+ {
175
+ parser->request_uri(parser, PTR_TO(mark), LEN(mark, p));
176
+ }
177
+ goto st5;
178
+ tr31:
179
+ #line 35 "ext/puma_http11/http11_parser.rl"
180
+ { MARK(mark, p); }
181
+ #line 54 "ext/puma_http11/http11_parser.rl"
182
+ {
183
+ parser->fragment(parser, PTR_TO(mark), LEN(mark, p));
184
+ }
185
+ goto st5;
186
+ tr33:
187
+ #line 54 "ext/puma_http11/http11_parser.rl"
188
+ {
189
+ parser->fragment(parser, PTR_TO(mark), LEN(mark, p));
190
+ }
191
+ goto st5;
192
+ tr37:
193
+ #line 67 "ext/puma_http11/http11_parser.rl"
194
+ {
195
+ parser->request_path(parser, PTR_TO(mark), LEN(mark,p));
196
+ }
197
+ #line 51 "ext/puma_http11/http11_parser.rl"
198
+ {
199
+ parser->request_uri(parser, PTR_TO(mark), LEN(mark, p));
200
+ }
201
+ goto st5;
202
+ tr41:
203
+ #line 58 "ext/puma_http11/http11_parser.rl"
204
+ { MARK(query_start, p); }
205
+ #line 59 "ext/puma_http11/http11_parser.rl"
206
+ {
207
+ parser->query_string(parser, PTR_TO(query_start), LEN(query_start, p));
208
+ }
209
+ #line 51 "ext/puma_http11/http11_parser.rl"
210
+ {
211
+ parser->request_uri(parser, PTR_TO(mark), LEN(mark, p));
212
+ }
213
+ goto st5;
214
+ tr44:
215
+ #line 59 "ext/puma_http11/http11_parser.rl"
216
+ {
217
+ parser->query_string(parser, PTR_TO(query_start), LEN(query_start, p));
218
+ }
219
+ #line 51 "ext/puma_http11/http11_parser.rl"
220
+ {
221
+ parser->request_uri(parser, PTR_TO(mark), LEN(mark, p));
222
+ }
223
+ goto st5;
224
+ st5:
225
+ if ( ++p == pe )
226
+ goto _test_eof5;
227
+ case 5:
228
+ #line 229 "ext/puma_http11/http11_parser.c"
229
+ if ( (*p) == 72 )
230
+ goto tr10;
231
+ goto st0;
232
+ tr10:
233
+ #line 35 "ext/puma_http11/http11_parser.rl"
234
+ { MARK(mark, p); }
235
+ goto st6;
236
+ st6:
237
+ if ( ++p == pe )
238
+ goto _test_eof6;
239
+ case 6:
240
+ #line 241 "ext/puma_http11/http11_parser.c"
241
+ if ( (*p) == 84 )
242
+ goto st7;
243
+ goto st0;
244
+ st7:
245
+ if ( ++p == pe )
246
+ goto _test_eof7;
247
+ case 7:
248
+ if ( (*p) == 84 )
249
+ goto st8;
250
+ goto st0;
251
+ st8:
252
+ if ( ++p == pe )
253
+ goto _test_eof8;
254
+ case 8:
255
+ if ( (*p) == 80 )
256
+ goto st9;
257
+ goto st0;
258
+ st9:
259
+ if ( ++p == pe )
260
+ goto _test_eof9;
261
+ case 9:
262
+ if ( (*p) == 47 )
263
+ goto st10;
264
+ goto st0;
265
+ st10:
266
+ if ( ++p == pe )
267
+ goto _test_eof10;
268
+ case 10:
269
+ if ( 48 <= (*p) && (*p) <= 57 )
270
+ goto st11;
271
+ goto st0;
272
+ st11:
273
+ if ( ++p == pe )
274
+ goto _test_eof11;
275
+ case 11:
276
+ if ( (*p) == 46 )
277
+ goto st12;
278
+ if ( 48 <= (*p) && (*p) <= 57 )
279
+ goto st11;
280
+ goto st0;
281
+ st12:
282
+ if ( ++p == pe )
283
+ goto _test_eof12;
284
+ case 12:
285
+ if ( 48 <= (*p) && (*p) <= 57 )
286
+ goto st13;
287
+ goto st0;
288
+ st13:
289
+ if ( ++p == pe )
290
+ goto _test_eof13;
291
+ case 13:
292
+ if ( (*p) == 13 )
293
+ goto tr18;
294
+ if ( 48 <= (*p) && (*p) <= 57 )
295
+ goto st13;
296
+ goto st0;
297
+ tr18:
298
+ #line 63 "ext/puma_http11/http11_parser.rl"
299
+ {
300
+ parser->http_version(parser, PTR_TO(mark), LEN(mark, p));
301
+ }
302
+ goto st14;
303
+ tr26:
304
+ #line 44 "ext/puma_http11/http11_parser.rl"
305
+ { MARK(mark, p); }
306
+ #line 45 "ext/puma_http11/http11_parser.rl"
307
+ {
308
+ parser->http_field(parser, PTR_TO(field_start), parser->field_len, PTR_TO(mark), LEN(mark, p));
309
+ }
310
+ goto st14;
311
+ tr29:
312
+ #line 45 "ext/puma_http11/http11_parser.rl"
313
+ {
314
+ parser->http_field(parser, PTR_TO(field_start), parser->field_len, PTR_TO(mark), LEN(mark, p));
315
+ }
316
+ goto st14;
317
+ st14:
318
+ if ( ++p == pe )
319
+ goto _test_eof14;
320
+ case 14:
321
+ #line 322 "ext/puma_http11/http11_parser.c"
322
+ if ( (*p) == 10 )
323
+ goto st15;
324
+ goto st0;
325
+ st15:
326
+ if ( ++p == pe )
327
+ goto _test_eof15;
328
+ case 15:
329
+ switch( (*p) ) {
330
+ case 13: goto st16;
331
+ case 33: goto tr21;
332
+ case 124: goto tr21;
333
+ case 126: goto tr21;
334
+ }
335
+ if ( (*p) < 45 ) {
336
+ if ( (*p) > 39 ) {
337
+ if ( 42 <= (*p) && (*p) <= 43 )
338
+ goto tr21;
339
+ } else if ( (*p) >= 35 )
340
+ goto tr21;
341
+ } else if ( (*p) > 46 ) {
342
+ if ( (*p) < 65 ) {
343
+ if ( 48 <= (*p) && (*p) <= 57 )
344
+ goto tr21;
345
+ } else if ( (*p) > 90 ) {
346
+ if ( 94 <= (*p) && (*p) <= 122 )
347
+ goto tr21;
348
+ } else
349
+ goto tr21;
350
+ } else
351
+ goto tr21;
352
+ goto st0;
353
+ st16:
354
+ if ( ++p == pe )
355
+ goto _test_eof16;
356
+ case 16:
357
+ if ( (*p) == 10 )
358
+ goto tr22;
359
+ goto st0;
360
+ tr22:
361
+ #line 71 "ext/puma_http11/http11_parser.rl"
362
+ {
363
+ parser->body_start = p - buffer + 1;
364
+ parser->header_done(parser, p + 1, pe - p - 1);
365
+ {p++; cs = 46; goto _out;}
366
+ }
367
+ goto st46;
368
+ st46:
369
+ if ( ++p == pe )
370
+ goto _test_eof46;
371
+ case 46:
372
+ #line 373 "ext/puma_http11/http11_parser.c"
373
+ goto st0;
374
+ tr21:
375
+ #line 38 "ext/puma_http11/http11_parser.rl"
376
+ { MARK(field_start, p); }
377
+ #line 39 "ext/puma_http11/http11_parser.rl"
378
+ { snake_upcase_char((char *)p); }
379
+ goto st17;
380
+ tr23:
381
+ #line 39 "ext/puma_http11/http11_parser.rl"
382
+ { snake_upcase_char((char *)p); }
383
+ goto st17;
384
+ st17:
385
+ if ( ++p == pe )
386
+ goto _test_eof17;
387
+ case 17:
388
+ #line 389 "ext/puma_http11/http11_parser.c"
389
+ switch( (*p) ) {
390
+ case 33: goto tr23;
391
+ case 58: goto tr24;
392
+ case 124: goto tr23;
393
+ case 126: goto tr23;
394
+ }
395
+ if ( (*p) < 45 ) {
396
+ if ( (*p) > 39 ) {
397
+ if ( 42 <= (*p) && (*p) <= 43 )
398
+ goto tr23;
399
+ } else if ( (*p) >= 35 )
400
+ goto tr23;
401
+ } else if ( (*p) > 46 ) {
402
+ if ( (*p) < 65 ) {
403
+ if ( 48 <= (*p) && (*p) <= 57 )
404
+ goto tr23;
405
+ } else if ( (*p) > 90 ) {
406
+ if ( 94 <= (*p) && (*p) <= 122 )
407
+ goto tr23;
408
+ } else
409
+ goto tr23;
410
+ } else
411
+ goto tr23;
412
+ goto st0;
413
+ tr24:
414
+ #line 40 "ext/puma_http11/http11_parser.rl"
415
+ {
416
+ parser->field_len = LEN(field_start, p);
417
+ }
418
+ goto st18;
419
+ tr27:
420
+ #line 44 "ext/puma_http11/http11_parser.rl"
421
+ { MARK(mark, p); }
422
+ goto st18;
423
+ st18:
424
+ if ( ++p == pe )
425
+ goto _test_eof18;
426
+ case 18:
427
+ #line 428 "ext/puma_http11/http11_parser.c"
428
+ switch( (*p) ) {
429
+ case 13: goto tr26;
430
+ case 32: goto tr27;
431
+ }
432
+ goto tr25;
433
+ tr25:
434
+ #line 44 "ext/puma_http11/http11_parser.rl"
435
+ { MARK(mark, p); }
436
+ goto st19;
437
+ st19:
438
+ if ( ++p == pe )
439
+ goto _test_eof19;
440
+ case 19:
441
+ #line 442 "ext/puma_http11/http11_parser.c"
442
+ if ( (*p) == 13 )
443
+ goto tr29;
444
+ goto st19;
445
+ tr9:
446
+ #line 51 "ext/puma_http11/http11_parser.rl"
447
+ {
448
+ parser->request_uri(parser, PTR_TO(mark), LEN(mark, p));
449
+ }
450
+ goto st20;
451
+ tr38:
452
+ #line 67 "ext/puma_http11/http11_parser.rl"
453
+ {
454
+ parser->request_path(parser, PTR_TO(mark), LEN(mark,p));
455
+ }
456
+ #line 51 "ext/puma_http11/http11_parser.rl"
457
+ {
458
+ parser->request_uri(parser, PTR_TO(mark), LEN(mark, p));
459
+ }
460
+ goto st20;
461
+ tr42:
462
+ #line 58 "ext/puma_http11/http11_parser.rl"
463
+ { MARK(query_start, p); }
464
+ #line 59 "ext/puma_http11/http11_parser.rl"
465
+ {
466
+ parser->query_string(parser, PTR_TO(query_start), LEN(query_start, p));
467
+ }
468
+ #line 51 "ext/puma_http11/http11_parser.rl"
469
+ {
470
+ parser->request_uri(parser, PTR_TO(mark), LEN(mark, p));
471
+ }
472
+ goto st20;
473
+ tr45:
474
+ #line 59 "ext/puma_http11/http11_parser.rl"
475
+ {
476
+ parser->query_string(parser, PTR_TO(query_start), LEN(query_start, p));
477
+ }
478
+ #line 51 "ext/puma_http11/http11_parser.rl"
479
+ {
480
+ parser->request_uri(parser, PTR_TO(mark), LEN(mark, p));
481
+ }
482
+ goto st20;
483
+ st20:
484
+ if ( ++p == pe )
485
+ goto _test_eof20;
486
+ case 20:
487
+ #line 488 "ext/puma_http11/http11_parser.c"
488
+ switch( (*p) ) {
489
+ case 32: goto tr31;
490
+ case 60: goto st0;
491
+ case 62: goto st0;
492
+ case 127: goto st0;
493
+ }
494
+ if ( (*p) > 31 ) {
495
+ if ( 34 <= (*p) && (*p) <= 35 )
496
+ goto st0;
497
+ } else if ( (*p) >= 0 )
498
+ goto st0;
499
+ goto tr30;
500
+ tr30:
501
+ #line 35 "ext/puma_http11/http11_parser.rl"
502
+ { MARK(mark, p); }
503
+ goto st21;
504
+ st21:
505
+ if ( ++p == pe )
506
+ goto _test_eof21;
507
+ case 21:
508
+ #line 509 "ext/puma_http11/http11_parser.c"
509
+ switch( (*p) ) {
510
+ case 32: goto tr33;
511
+ case 60: goto st0;
512
+ case 62: goto st0;
513
+ case 127: goto st0;
514
+ }
515
+ if ( (*p) > 31 ) {
516
+ if ( 34 <= (*p) && (*p) <= 35 )
517
+ goto st0;
518
+ } else if ( (*p) >= 0 )
519
+ goto st0;
520
+ goto st21;
521
+ tr5:
522
+ #line 35 "ext/puma_http11/http11_parser.rl"
523
+ { MARK(mark, p); }
524
+ goto st22;
525
+ st22:
526
+ if ( ++p == pe )
527
+ goto _test_eof22;
528
+ case 22:
529
+ #line 530 "ext/puma_http11/http11_parser.c"
530
+ switch( (*p) ) {
531
+ case 43: goto st22;
532
+ case 58: goto st23;
533
+ }
534
+ if ( (*p) < 48 ) {
535
+ if ( 45 <= (*p) && (*p) <= 46 )
536
+ goto st22;
537
+ } else if ( (*p) > 57 ) {
538
+ if ( (*p) > 90 ) {
539
+ if ( 97 <= (*p) && (*p) <= 122 )
540
+ goto st22;
541
+ } else if ( (*p) >= 65 )
542
+ goto st22;
543
+ } else
544
+ goto st22;
545
+ goto st0;
546
+ tr7:
547
+ #line 35 "ext/puma_http11/http11_parser.rl"
548
+ { MARK(mark, p); }
549
+ goto st23;
550
+ st23:
551
+ if ( ++p == pe )
552
+ goto _test_eof23;
553
+ case 23:
554
+ #line 555 "ext/puma_http11/http11_parser.c"
555
+ switch( (*p) ) {
556
+ case 32: goto tr8;
557
+ case 34: goto st0;
558
+ case 35: goto tr9;
559
+ case 60: goto st0;
560
+ case 62: goto st0;
561
+ case 127: goto st0;
562
+ }
563
+ if ( 0 <= (*p) && (*p) <= 31 )
564
+ goto st0;
565
+ goto st23;
566
+ tr6:
567
+ #line 35 "ext/puma_http11/http11_parser.rl"
568
+ { MARK(mark, p); }
569
+ goto st24;
570
+ st24:
571
+ if ( ++p == pe )
572
+ goto _test_eof24;
573
+ case 24:
574
+ #line 575 "ext/puma_http11/http11_parser.c"
575
+ switch( (*p) ) {
576
+ case 32: goto tr37;
577
+ case 34: goto st0;
578
+ case 35: goto tr38;
579
+ case 60: goto st0;
580
+ case 62: goto st0;
581
+ case 63: goto tr39;
582
+ case 127: goto st0;
583
+ }
584
+ if ( 0 <= (*p) && (*p) <= 31 )
585
+ goto st0;
586
+ goto st24;
587
+ tr39:
588
+ #line 67 "ext/puma_http11/http11_parser.rl"
589
+ {
590
+ parser->request_path(parser, PTR_TO(mark), LEN(mark,p));
591
+ }
592
+ goto st25;
593
+ st25:
594
+ if ( ++p == pe )
595
+ goto _test_eof25;
596
+ case 25:
597
+ #line 598 "ext/puma_http11/http11_parser.c"
598
+ switch( (*p) ) {
599
+ case 32: goto tr41;
600
+ case 34: goto st0;
601
+ case 35: goto tr42;
602
+ case 60: goto st0;
603
+ case 62: goto st0;
604
+ case 127: goto st0;
605
+ }
606
+ if ( 0 <= (*p) && (*p) <= 31 )
607
+ goto st0;
608
+ goto tr40;
609
+ tr40:
610
+ #line 58 "ext/puma_http11/http11_parser.rl"
611
+ { MARK(query_start, p); }
612
+ goto st26;
613
+ st26:
614
+ if ( ++p == pe )
615
+ goto _test_eof26;
616
+ case 26:
617
+ #line 618 "ext/puma_http11/http11_parser.c"
618
+ switch( (*p) ) {
619
+ case 32: goto tr44;
620
+ case 34: goto st0;
621
+ case 35: goto tr45;
622
+ case 60: goto st0;
623
+ case 62: goto st0;
624
+ case 127: goto st0;
625
+ }
626
+ if ( 0 <= (*p) && (*p) <= 31 )
627
+ goto st0;
628
+ goto st26;
629
+ st27:
630
+ if ( ++p == pe )
631
+ goto _test_eof27;
632
+ case 27:
633
+ switch( (*p) ) {
634
+ case 32: goto tr2;
635
+ case 36: goto st28;
636
+ case 95: goto st28;
637
+ }
638
+ if ( (*p) < 48 ) {
639
+ if ( 45 <= (*p) && (*p) <= 46 )
640
+ goto st28;
641
+ } else if ( (*p) > 57 ) {
642
+ if ( 65 <= (*p) && (*p) <= 90 )
643
+ goto st28;
644
+ } else
645
+ goto st28;
646
+ goto st0;
647
+ st28:
648
+ if ( ++p == pe )
649
+ goto _test_eof28;
650
+ case 28:
651
+ switch( (*p) ) {
652
+ case 32: goto tr2;
653
+ case 36: goto st29;
654
+ case 95: goto st29;
655
+ }
656
+ if ( (*p) < 48 ) {
657
+ if ( 45 <= (*p) && (*p) <= 46 )
658
+ goto st29;
659
+ } else if ( (*p) > 57 ) {
660
+ if ( 65 <= (*p) && (*p) <= 90 )
661
+ goto st29;
662
+ } else
663
+ goto st29;
664
+ goto st0;
665
+ st29:
666
+ if ( ++p == pe )
667
+ goto _test_eof29;
668
+ case 29:
669
+ switch( (*p) ) {
670
+ case 32: goto tr2;
671
+ case 36: goto st30;
672
+ case 95: goto st30;
673
+ }
674
+ if ( (*p) < 48 ) {
675
+ if ( 45 <= (*p) && (*p) <= 46 )
676
+ goto st30;
677
+ } else if ( (*p) > 57 ) {
678
+ if ( 65 <= (*p) && (*p) <= 90 )
679
+ goto st30;
680
+ } else
681
+ goto st30;
682
+ goto st0;
683
+ st30:
684
+ if ( ++p == pe )
685
+ goto _test_eof30;
686
+ case 30:
687
+ switch( (*p) ) {
688
+ case 32: goto tr2;
689
+ case 36: goto st31;
690
+ case 95: goto st31;
691
+ }
692
+ if ( (*p) < 48 ) {
693
+ if ( 45 <= (*p) && (*p) <= 46 )
694
+ goto st31;
695
+ } else if ( (*p) > 57 ) {
696
+ if ( 65 <= (*p) && (*p) <= 90 )
697
+ goto st31;
698
+ } else
699
+ goto st31;
700
+ goto st0;
701
+ st31:
702
+ if ( ++p == pe )
703
+ goto _test_eof31;
704
+ case 31:
705
+ switch( (*p) ) {
706
+ case 32: goto tr2;
707
+ case 36: goto st32;
708
+ case 95: goto st32;
709
+ }
710
+ if ( (*p) < 48 ) {
711
+ if ( 45 <= (*p) && (*p) <= 46 )
712
+ goto st32;
713
+ } else if ( (*p) > 57 ) {
714
+ if ( 65 <= (*p) && (*p) <= 90 )
715
+ goto st32;
716
+ } else
717
+ goto st32;
718
+ goto st0;
719
+ st32:
720
+ if ( ++p == pe )
721
+ goto _test_eof32;
722
+ case 32:
723
+ switch( (*p) ) {
724
+ case 32: goto tr2;
725
+ case 36: goto st33;
726
+ case 95: goto st33;
727
+ }
728
+ if ( (*p) < 48 ) {
729
+ if ( 45 <= (*p) && (*p) <= 46 )
730
+ goto st33;
731
+ } else if ( (*p) > 57 ) {
732
+ if ( 65 <= (*p) && (*p) <= 90 )
733
+ goto st33;
734
+ } else
735
+ goto st33;
736
+ goto st0;
737
+ st33:
738
+ if ( ++p == pe )
739
+ goto _test_eof33;
740
+ case 33:
741
+ switch( (*p) ) {
742
+ case 32: goto tr2;
743
+ case 36: goto st34;
744
+ case 95: goto st34;
745
+ }
746
+ if ( (*p) < 48 ) {
747
+ if ( 45 <= (*p) && (*p) <= 46 )
748
+ goto st34;
749
+ } else if ( (*p) > 57 ) {
750
+ if ( 65 <= (*p) && (*p) <= 90 )
751
+ goto st34;
752
+ } else
753
+ goto st34;
754
+ goto st0;
755
+ st34:
756
+ if ( ++p == pe )
757
+ goto _test_eof34;
758
+ case 34:
759
+ switch( (*p) ) {
760
+ case 32: goto tr2;
761
+ case 36: goto st35;
762
+ case 95: goto st35;
763
+ }
764
+ if ( (*p) < 48 ) {
765
+ if ( 45 <= (*p) && (*p) <= 46 )
766
+ goto st35;
767
+ } else if ( (*p) > 57 ) {
768
+ if ( 65 <= (*p) && (*p) <= 90 )
769
+ goto st35;
770
+ } else
771
+ goto st35;
772
+ goto st0;
773
+ st35:
774
+ if ( ++p == pe )
775
+ goto _test_eof35;
776
+ case 35:
777
+ switch( (*p) ) {
778
+ case 32: goto tr2;
779
+ case 36: goto st36;
780
+ case 95: goto st36;
781
+ }
782
+ if ( (*p) < 48 ) {
783
+ if ( 45 <= (*p) && (*p) <= 46 )
784
+ goto st36;
785
+ } else if ( (*p) > 57 ) {
786
+ if ( 65 <= (*p) && (*p) <= 90 )
787
+ goto st36;
788
+ } else
789
+ goto st36;
790
+ goto st0;
791
+ st36:
792
+ if ( ++p == pe )
793
+ goto _test_eof36;
794
+ case 36:
795
+ switch( (*p) ) {
796
+ case 32: goto tr2;
797
+ case 36: goto st37;
798
+ case 95: goto st37;
799
+ }
800
+ if ( (*p) < 48 ) {
801
+ if ( 45 <= (*p) && (*p) <= 46 )
802
+ goto st37;
803
+ } else if ( (*p) > 57 ) {
804
+ if ( 65 <= (*p) && (*p) <= 90 )
805
+ goto st37;
806
+ } else
807
+ goto st37;
808
+ goto st0;
809
+ st37:
810
+ if ( ++p == pe )
811
+ goto _test_eof37;
812
+ case 37:
813
+ switch( (*p) ) {
814
+ case 32: goto tr2;
815
+ case 36: goto st38;
816
+ case 95: goto st38;
817
+ }
818
+ if ( (*p) < 48 ) {
819
+ if ( 45 <= (*p) && (*p) <= 46 )
820
+ goto st38;
821
+ } else if ( (*p) > 57 ) {
822
+ if ( 65 <= (*p) && (*p) <= 90 )
823
+ goto st38;
824
+ } else
825
+ goto st38;
826
+ goto st0;
827
+ st38:
828
+ if ( ++p == pe )
829
+ goto _test_eof38;
830
+ case 38:
831
+ switch( (*p) ) {
832
+ case 32: goto tr2;
833
+ case 36: goto st39;
834
+ case 95: goto st39;
835
+ }
836
+ if ( (*p) < 48 ) {
837
+ if ( 45 <= (*p) && (*p) <= 46 )
838
+ goto st39;
839
+ } else if ( (*p) > 57 ) {
840
+ if ( 65 <= (*p) && (*p) <= 90 )
841
+ goto st39;
842
+ } else
843
+ goto st39;
844
+ goto st0;
845
+ st39:
846
+ if ( ++p == pe )
847
+ goto _test_eof39;
848
+ case 39:
849
+ switch( (*p) ) {
850
+ case 32: goto tr2;
851
+ case 36: goto st40;
852
+ case 95: goto st40;
853
+ }
854
+ if ( (*p) < 48 ) {
855
+ if ( 45 <= (*p) && (*p) <= 46 )
856
+ goto st40;
857
+ } else if ( (*p) > 57 ) {
858
+ if ( 65 <= (*p) && (*p) <= 90 )
859
+ goto st40;
860
+ } else
861
+ goto st40;
862
+ goto st0;
863
+ st40:
864
+ if ( ++p == pe )
865
+ goto _test_eof40;
866
+ case 40:
867
+ switch( (*p) ) {
868
+ case 32: goto tr2;
869
+ case 36: goto st41;
870
+ case 95: goto st41;
871
+ }
872
+ if ( (*p) < 48 ) {
873
+ if ( 45 <= (*p) && (*p) <= 46 )
874
+ goto st41;
875
+ } else if ( (*p) > 57 ) {
876
+ if ( 65 <= (*p) && (*p) <= 90 )
877
+ goto st41;
878
+ } else
879
+ goto st41;
880
+ goto st0;
881
+ st41:
882
+ if ( ++p == pe )
883
+ goto _test_eof41;
884
+ case 41:
885
+ switch( (*p) ) {
886
+ case 32: goto tr2;
887
+ case 36: goto st42;
888
+ case 95: goto st42;
889
+ }
890
+ if ( (*p) < 48 ) {
891
+ if ( 45 <= (*p) && (*p) <= 46 )
892
+ goto st42;
893
+ } else if ( (*p) > 57 ) {
894
+ if ( 65 <= (*p) && (*p) <= 90 )
895
+ goto st42;
896
+ } else
897
+ goto st42;
898
+ goto st0;
899
+ st42:
900
+ if ( ++p == pe )
901
+ goto _test_eof42;
902
+ case 42:
903
+ switch( (*p) ) {
904
+ case 32: goto tr2;
905
+ case 36: goto st43;
906
+ case 95: goto st43;
907
+ }
908
+ if ( (*p) < 48 ) {
909
+ if ( 45 <= (*p) && (*p) <= 46 )
910
+ goto st43;
911
+ } else if ( (*p) > 57 ) {
912
+ if ( 65 <= (*p) && (*p) <= 90 )
913
+ goto st43;
914
+ } else
915
+ goto st43;
916
+ goto st0;
917
+ st43:
918
+ if ( ++p == pe )
919
+ goto _test_eof43;
920
+ case 43:
921
+ switch( (*p) ) {
922
+ case 32: goto tr2;
923
+ case 36: goto st44;
924
+ case 95: goto st44;
925
+ }
926
+ if ( (*p) < 48 ) {
927
+ if ( 45 <= (*p) && (*p) <= 46 )
928
+ goto st44;
929
+ } else if ( (*p) > 57 ) {
930
+ if ( 65 <= (*p) && (*p) <= 90 )
931
+ goto st44;
932
+ } else
933
+ goto st44;
934
+ goto st0;
935
+ st44:
936
+ if ( ++p == pe )
937
+ goto _test_eof44;
938
+ case 44:
939
+ switch( (*p) ) {
940
+ case 32: goto tr2;
941
+ case 36: goto st45;
942
+ case 95: goto st45;
943
+ }
944
+ if ( (*p) < 48 ) {
945
+ if ( 45 <= (*p) && (*p) <= 46 )
946
+ goto st45;
947
+ } else if ( (*p) > 57 ) {
948
+ if ( 65 <= (*p) && (*p) <= 90 )
949
+ goto st45;
950
+ } else
951
+ goto st45;
952
+ goto st0;
953
+ st45:
954
+ if ( ++p == pe )
955
+ goto _test_eof45;
956
+ case 45:
957
+ if ( (*p) == 32 )
958
+ goto tr2;
959
+ goto st0;
960
+ }
961
+ _test_eof2: cs = 2; goto _test_eof;
962
+ _test_eof3: cs = 3; goto _test_eof;
963
+ _test_eof4: cs = 4; goto _test_eof;
964
+ _test_eof5: cs = 5; goto _test_eof;
965
+ _test_eof6: cs = 6; goto _test_eof;
966
+ _test_eof7: cs = 7; goto _test_eof;
967
+ _test_eof8: cs = 8; goto _test_eof;
968
+ _test_eof9: cs = 9; goto _test_eof;
969
+ _test_eof10: cs = 10; goto _test_eof;
970
+ _test_eof11: cs = 11; goto _test_eof;
971
+ _test_eof12: cs = 12; goto _test_eof;
972
+ _test_eof13: cs = 13; goto _test_eof;
973
+ _test_eof14: cs = 14; goto _test_eof;
974
+ _test_eof15: cs = 15; goto _test_eof;
975
+ _test_eof16: cs = 16; goto _test_eof;
976
+ _test_eof46: cs = 46; goto _test_eof;
977
+ _test_eof17: cs = 17; goto _test_eof;
978
+ _test_eof18: cs = 18; goto _test_eof;
979
+ _test_eof19: cs = 19; goto _test_eof;
980
+ _test_eof20: cs = 20; goto _test_eof;
981
+ _test_eof21: cs = 21; goto _test_eof;
982
+ _test_eof22: cs = 22; goto _test_eof;
983
+ _test_eof23: cs = 23; goto _test_eof;
984
+ _test_eof24: cs = 24; goto _test_eof;
985
+ _test_eof25: cs = 25; goto _test_eof;
986
+ _test_eof26: cs = 26; goto _test_eof;
987
+ _test_eof27: cs = 27; goto _test_eof;
988
+ _test_eof28: cs = 28; goto _test_eof;
989
+ _test_eof29: cs = 29; goto _test_eof;
990
+ _test_eof30: cs = 30; goto _test_eof;
991
+ _test_eof31: cs = 31; goto _test_eof;
992
+ _test_eof32: cs = 32; goto _test_eof;
993
+ _test_eof33: cs = 33; goto _test_eof;
994
+ _test_eof34: cs = 34; goto _test_eof;
995
+ _test_eof35: cs = 35; goto _test_eof;
996
+ _test_eof36: cs = 36; goto _test_eof;
997
+ _test_eof37: cs = 37; goto _test_eof;
998
+ _test_eof38: cs = 38; goto _test_eof;
999
+ _test_eof39: cs = 39; goto _test_eof;
1000
+ _test_eof40: cs = 40; goto _test_eof;
1001
+ _test_eof41: cs = 41; goto _test_eof;
1002
+ _test_eof42: cs = 42; goto _test_eof;
1003
+ _test_eof43: cs = 43; goto _test_eof;
1004
+ _test_eof44: cs = 44; goto _test_eof;
1005
+ _test_eof45: cs = 45; goto _test_eof;
1006
+
1007
+ _test_eof: {}
1008
+ _out: {}
1009
+ }
1010
+
1011
+ #line 115 "ext/puma_http11/http11_parser.rl"
1012
+
1013
+ if (!puma_parser_has_error(parser))
1014
+ parser->cs = cs;
1015
+ parser->nread += p - (buffer + off);
1016
+
1017
+ assert(p <= pe && "buffer overflow after parsing execute");
1018
+ assert(parser->nread <= len && "nread longer than length");
1019
+ assert(parser->body_start <= len && "body starts after buffer end");
1020
+ assert(parser->mark < len && "mark is after buffer end");
1021
+ assert(parser->field_len <= len && "field has length longer than whole buffer");
1022
+ assert(parser->field_start < len && "field starts after buffer end");
1023
+
1024
+ return(parser->nread);
1025
+ }
1026
+
1027
+ int puma_parser_finish(puma_parser *parser)
1028
+ {
1029
+ if (puma_parser_has_error(parser) ) {
1030
+ return -1;
1031
+ } else if (puma_parser_is_finished(parser) ) {
1032
+ return 1;
1033
+ } else {
1034
+ return 0;
1035
+ }
1036
+ }
1037
+
1038
+ int puma_parser_has_error(puma_parser *parser) {
1039
+ return parser->cs == puma_parser_error;
1040
+ }
1041
+
1042
+ int puma_parser_is_finished(puma_parser *parser) {
1043
+ return parser->cs >= puma_parser_first_final;
1044
+ }