piesync-puma 3.12.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/History.md +1429 -0
- data/LICENSE +26 -0
- data/README.md +280 -0
- data/bin/puma +10 -0
- data/bin/puma-wild +31 -0
- data/bin/pumactl +12 -0
- data/docs/architecture.md +36 -0
- data/docs/deployment.md +91 -0
- data/docs/images/puma-connection-flow-no-reactor.png +0 -0
- data/docs/images/puma-connection-flow.png +0 -0
- data/docs/images/puma-general-arch.png +0 -0
- data/docs/nginx.md +80 -0
- data/docs/plugins.md +28 -0
- data/docs/restart.md +39 -0
- data/docs/signals.md +96 -0
- data/docs/systemd.md +272 -0
- data/ext/puma_http11/PumaHttp11Service.java +17 -0
- data/ext/puma_http11/ext_help.h +15 -0
- data/ext/puma_http11/extconf.rb +15 -0
- data/ext/puma_http11/http11_parser.c +1071 -0
- data/ext/puma_http11/http11_parser.h +65 -0
- data/ext/puma_http11/http11_parser.java.rl +161 -0
- data/ext/puma_http11/http11_parser.rl +149 -0
- data/ext/puma_http11/http11_parser_common.rl +54 -0
- data/ext/puma_http11/io_buffer.c +155 -0
- data/ext/puma_http11/mini_ssl.c +494 -0
- data/ext/puma_http11/org/jruby/puma/Http11.java +234 -0
- data/ext/puma_http11/org/jruby/puma/Http11Parser.java +470 -0
- data/ext/puma_http11/org/jruby/puma/MiniSSL.java +352 -0
- data/ext/puma_http11/puma_http11.c +500 -0
- data/lib/puma.rb +23 -0
- data/lib/puma/accept_nonblock.rb +23 -0
- data/lib/puma/app/status.rb +74 -0
- data/lib/puma/binder.rb +413 -0
- data/lib/puma/cli.rb +235 -0
- data/lib/puma/client.rb +480 -0
- data/lib/puma/cluster.rb +531 -0
- data/lib/puma/commonlogger.rb +108 -0
- data/lib/puma/compat.rb +14 -0
- data/lib/puma/configuration.rb +361 -0
- data/lib/puma/const.rb +239 -0
- data/lib/puma/control_cli.rb +264 -0
- data/lib/puma/convenient.rb +25 -0
- data/lib/puma/daemon_ext.rb +33 -0
- data/lib/puma/delegation.rb +13 -0
- data/lib/puma/detect.rb +15 -0
- data/lib/puma/dsl.rb +518 -0
- data/lib/puma/events.rb +153 -0
- data/lib/puma/io_buffer.rb +9 -0
- data/lib/puma/java_io_buffer.rb +47 -0
- data/lib/puma/jruby_restart.rb +84 -0
- data/lib/puma/launcher.rb +433 -0
- data/lib/puma/minissl.rb +285 -0
- data/lib/puma/null_io.rb +44 -0
- data/lib/puma/plugin.rb +117 -0
- data/lib/puma/plugin/tmp_restart.rb +34 -0
- data/lib/puma/rack/backports/uri/common_193.rb +33 -0
- data/lib/puma/rack/builder.rb +299 -0
- data/lib/puma/rack/urlmap.rb +91 -0
- data/lib/puma/rack_default.rb +7 -0
- data/lib/puma/reactor.rb +347 -0
- data/lib/puma/runner.rb +184 -0
- data/lib/puma/server.rb +1072 -0
- data/lib/puma/single.rb +123 -0
- data/lib/puma/state_file.rb +31 -0
- data/lib/puma/tcp_logger.rb +41 -0
- data/lib/puma/thread_pool.rb +346 -0
- data/lib/puma/util.rb +129 -0
- data/lib/rack/handler/puma.rb +115 -0
- data/tools/jungle/README.md +19 -0
- data/tools/jungle/init.d/README.md +61 -0
- data/tools/jungle/init.d/puma +421 -0
- data/tools/jungle/init.d/run-puma +18 -0
- data/tools/jungle/rc.d/README.md +74 -0
- data/tools/jungle/rc.d/puma +61 -0
- data/tools/jungle/rc.d/puma.conf +10 -0
- data/tools/jungle/upstart/README.md +61 -0
- data/tools/jungle/upstart/puma-manager.conf +31 -0
- data/tools/jungle/upstart/puma.conf +69 -0
- data/tools/trickletest.rb +45 -0
- metadata +131 -0
@@ -0,0 +1,234 @@
|
|
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.ObjectAllocator;
|
14
|
+
import org.jruby.runtime.ThreadContext;
|
15
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
16
|
+
|
17
|
+
import org.jruby.exceptions.RaiseException;
|
18
|
+
|
19
|
+
import org.jruby.util.ByteList;
|
20
|
+
|
21
|
+
/**
|
22
|
+
* @author <a href="mailto:ola.bini@ki.se">Ola Bini</a>
|
23
|
+
*/
|
24
|
+
public class Http11 extends RubyObject {
|
25
|
+
public final static int MAX_FIELD_NAME_LENGTH = 256;
|
26
|
+
public final static String MAX_FIELD_NAME_LENGTH_ERR = "HTTP element FIELD_NAME is longer than the 256 allowed length.";
|
27
|
+
public final static int MAX_FIELD_VALUE_LENGTH = 80 * 1024;
|
28
|
+
public final static String MAX_FIELD_VALUE_LENGTH_ERR = "HTTP element FIELD_VALUE is longer than the 81920 allowed length.";
|
29
|
+
public final static int MAX_REQUEST_URI_LENGTH = 1024 * 12;
|
30
|
+
public final static String MAX_REQUEST_URI_LENGTH_ERR = "HTTP element REQUEST_URI is longer than the 12288 allowed length.";
|
31
|
+
public final static int MAX_FRAGMENT_LENGTH = 1024;
|
32
|
+
public final static String MAX_FRAGMENT_LENGTH_ERR = "HTTP element REQUEST_PATH is longer than the 1024 allowed length.";
|
33
|
+
public final static int MAX_REQUEST_PATH_LENGTH = 2048;
|
34
|
+
public final static String MAX_REQUEST_PATH_LENGTH_ERR = "HTTP element REQUEST_PATH is longer than the 2048 allowed length.";
|
35
|
+
public final static int MAX_QUERY_STRING_LENGTH = 1024 * 10;
|
36
|
+
public final static String MAX_QUERY_STRING_LENGTH_ERR = "HTTP element QUERY_STRING is longer than the 10240 allowed length.";
|
37
|
+
public final static int MAX_HEADER_LENGTH = 1024 * (80 + 32);
|
38
|
+
public final static String MAX_HEADER_LENGTH_ERR = "HTTP element HEADER is longer than the 114688 allowed length.";
|
39
|
+
|
40
|
+
|
41
|
+
private static ObjectAllocator ALLOCATOR = new ObjectAllocator() {
|
42
|
+
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
|
43
|
+
return new Http11(runtime, klass);
|
44
|
+
}
|
45
|
+
};
|
46
|
+
|
47
|
+
public static void createHttp11(Ruby runtime) {
|
48
|
+
RubyModule mPuma = runtime.defineModule("Puma");
|
49
|
+
mPuma.defineClassUnder("HttpParserError",runtime.getClass("IOError"),runtime.getClass("IOError").getAllocator());
|
50
|
+
|
51
|
+
RubyClass cHttpParser = mPuma.defineClassUnder("HttpParser",runtime.getObject(),ALLOCATOR);
|
52
|
+
cHttpParser.defineAnnotatedMethods(Http11.class);
|
53
|
+
}
|
54
|
+
|
55
|
+
private Ruby runtime;
|
56
|
+
private RubyClass eHttpParserError;
|
57
|
+
private Http11Parser hp;
|
58
|
+
private RubyString body;
|
59
|
+
|
60
|
+
public Http11(Ruby runtime, RubyClass clazz) {
|
61
|
+
super(runtime,clazz);
|
62
|
+
this.runtime = runtime;
|
63
|
+
this.eHttpParserError = (RubyClass)runtime.getModule("Puma").getConstant("HttpParserError");
|
64
|
+
this.hp = new Http11Parser();
|
65
|
+
this.hp.parser.http_field = http_field;
|
66
|
+
this.hp.parser.request_method = request_method;
|
67
|
+
this.hp.parser.request_uri = request_uri;
|
68
|
+
this.hp.parser.fragment = fragment;
|
69
|
+
this.hp.parser.request_path = request_path;
|
70
|
+
this.hp.parser.query_string = query_string;
|
71
|
+
this.hp.parser.http_version = http_version;
|
72
|
+
this.hp.parser.header_done = header_done;
|
73
|
+
this.hp.parser.init();
|
74
|
+
}
|
75
|
+
|
76
|
+
public void validateMaxLength(int len, int max, String msg) {
|
77
|
+
if(len>max) {
|
78
|
+
throw new RaiseException(runtime, eHttpParserError, msg, true);
|
79
|
+
}
|
80
|
+
}
|
81
|
+
|
82
|
+
private Http11Parser.FieldCB http_field = new Http11Parser.FieldCB() {
|
83
|
+
public void call(Object data, int field, int flen, int value, int vlen) {
|
84
|
+
RubyHash req = (RubyHash)data;
|
85
|
+
RubyString f;
|
86
|
+
IRubyObject v;
|
87
|
+
validateMaxLength(flen, MAX_FIELD_NAME_LENGTH, MAX_FIELD_NAME_LENGTH_ERR);
|
88
|
+
validateMaxLength(vlen, MAX_FIELD_VALUE_LENGTH, MAX_FIELD_VALUE_LENGTH_ERR);
|
89
|
+
|
90
|
+
ByteList b = new ByteList(Http11.this.hp.parser.buffer,field,flen);
|
91
|
+
for(int i = 0,j = b.length();i<j;i++) {
|
92
|
+
if((b.get(i) & 0xFF) == '-') {
|
93
|
+
b.set(i, (byte)'_');
|
94
|
+
} else {
|
95
|
+
b.set(i, (byte)Character.toUpperCase((char)b.get(i)));
|
96
|
+
}
|
97
|
+
}
|
98
|
+
|
99
|
+
String as = b.toString();
|
100
|
+
|
101
|
+
if(as.equals("CONTENT_LENGTH") || as.equals("CONTENT_TYPE")) {
|
102
|
+
f = RubyString.newString(runtime, b);
|
103
|
+
} else {
|
104
|
+
f = RubyString.newString(runtime, "HTTP_");
|
105
|
+
f.cat(b);
|
106
|
+
}
|
107
|
+
|
108
|
+
b = new ByteList(Http11.this.hp.parser.buffer, value, vlen);
|
109
|
+
v = req.op_aref(req.getRuntime().getCurrentContext(), f);
|
110
|
+
if (v.isNil()) {
|
111
|
+
req.op_aset(req.getRuntime().getCurrentContext(), f, RubyString.newString(runtime, b));
|
112
|
+
} else {
|
113
|
+
RubyString vs = v.convertToString();
|
114
|
+
vs.cat(RubyString.newString(runtime, ", "));
|
115
|
+
vs.cat(b);
|
116
|
+
}
|
117
|
+
}
|
118
|
+
};
|
119
|
+
|
120
|
+
private Http11Parser.ElementCB request_method = new Http11Parser.ElementCB() {
|
121
|
+
public void call(Object data, int at, int length) {
|
122
|
+
RubyHash req = (RubyHash)data;
|
123
|
+
RubyString val = RubyString.newString(runtime,new ByteList(hp.parser.buffer,at,length));
|
124
|
+
req.op_aset(req.getRuntime().getCurrentContext(), runtime.newString("REQUEST_METHOD"),val);
|
125
|
+
}
|
126
|
+
};
|
127
|
+
|
128
|
+
private Http11Parser.ElementCB request_uri = new Http11Parser.ElementCB() {
|
129
|
+
public void call(Object data, int at, int length) {
|
130
|
+
RubyHash req = (RubyHash)data;
|
131
|
+
validateMaxLength(length, MAX_REQUEST_URI_LENGTH, MAX_REQUEST_URI_LENGTH_ERR);
|
132
|
+
RubyString val = RubyString.newString(runtime,new ByteList(hp.parser.buffer,at,length));
|
133
|
+
req.op_aset(req.getRuntime().getCurrentContext(), runtime.newString("REQUEST_URI"),val);
|
134
|
+
}
|
135
|
+
};
|
136
|
+
|
137
|
+
private Http11Parser.ElementCB fragment = new Http11Parser.ElementCB() {
|
138
|
+
public void call(Object data, int at, int length) {
|
139
|
+
RubyHash req = (RubyHash)data;
|
140
|
+
validateMaxLength(length, MAX_FRAGMENT_LENGTH, MAX_FRAGMENT_LENGTH_ERR);
|
141
|
+
RubyString val = RubyString.newString(runtime,new ByteList(hp.parser.buffer,at,length));
|
142
|
+
req.op_aset(req.getRuntime().getCurrentContext(), runtime.newString("FRAGMENT"),val);
|
143
|
+
}
|
144
|
+
};
|
145
|
+
|
146
|
+
private Http11Parser.ElementCB request_path = new Http11Parser.ElementCB() {
|
147
|
+
public void call(Object data, int at, int length) {
|
148
|
+
RubyHash req = (RubyHash)data;
|
149
|
+
validateMaxLength(length, MAX_REQUEST_PATH_LENGTH, MAX_REQUEST_PATH_LENGTH_ERR);
|
150
|
+
RubyString val = RubyString.newString(runtime,new ByteList(hp.parser.buffer,at,length));
|
151
|
+
req.op_aset(req.getRuntime().getCurrentContext(), runtime.newString("REQUEST_PATH"),val);
|
152
|
+
}
|
153
|
+
};
|
154
|
+
|
155
|
+
private Http11Parser.ElementCB query_string = new Http11Parser.ElementCB() {
|
156
|
+
public void call(Object data, int at, int length) {
|
157
|
+
RubyHash req = (RubyHash)data;
|
158
|
+
validateMaxLength(length, MAX_QUERY_STRING_LENGTH, MAX_QUERY_STRING_LENGTH_ERR);
|
159
|
+
RubyString val = RubyString.newString(runtime,new ByteList(hp.parser.buffer,at,length));
|
160
|
+
req.op_aset(req.getRuntime().getCurrentContext(), runtime.newString("QUERY_STRING"),val);
|
161
|
+
}
|
162
|
+
};
|
163
|
+
|
164
|
+
private Http11Parser.ElementCB http_version = new Http11Parser.ElementCB() {
|
165
|
+
public void call(Object data, int at, int length) {
|
166
|
+
RubyHash req = (RubyHash)data;
|
167
|
+
RubyString val = RubyString.newString(runtime,new ByteList(hp.parser.buffer,at,length));
|
168
|
+
req.op_aset(req.getRuntime().getCurrentContext(), runtime.newString("HTTP_VERSION"),val);
|
169
|
+
}
|
170
|
+
};
|
171
|
+
|
172
|
+
private Http11Parser.ElementCB header_done = new Http11Parser.ElementCB() {
|
173
|
+
public void call(Object data, int at, int length) {
|
174
|
+
body = RubyString.newString(runtime, new ByteList(hp.parser.buffer, at, length));
|
175
|
+
}
|
176
|
+
};
|
177
|
+
|
178
|
+
@JRubyMethod
|
179
|
+
public IRubyObject initialize() {
|
180
|
+
this.hp.parser.init();
|
181
|
+
return this;
|
182
|
+
}
|
183
|
+
|
184
|
+
@JRubyMethod
|
185
|
+
public IRubyObject reset() {
|
186
|
+
this.hp.parser.init();
|
187
|
+
return runtime.getNil();
|
188
|
+
}
|
189
|
+
|
190
|
+
@JRubyMethod
|
191
|
+
public IRubyObject finish() {
|
192
|
+
this.hp.finish();
|
193
|
+
return this.hp.is_finished() ? runtime.getTrue() : runtime.getFalse();
|
194
|
+
}
|
195
|
+
|
196
|
+
@JRubyMethod
|
197
|
+
public IRubyObject execute(IRubyObject req_hash, IRubyObject data, IRubyObject start) {
|
198
|
+
int from = 0;
|
199
|
+
from = RubyNumeric.fix2int(start);
|
200
|
+
ByteList d = ((RubyString)data).getByteList();
|
201
|
+
if(from >= d.length()) {
|
202
|
+
throw new RaiseException(runtime, eHttpParserError, "Requested start is after data buffer end.", true);
|
203
|
+
} else {
|
204
|
+
this.hp.parser.data = req_hash;
|
205
|
+
this.hp.execute(d,from);
|
206
|
+
validateMaxLength(this.hp.parser.nread,MAX_HEADER_LENGTH, MAX_HEADER_LENGTH_ERR);
|
207
|
+
if(this.hp.has_error()) {
|
208
|
+
throw new RaiseException(runtime, eHttpParserError, "Invalid HTTP format, parsing fails.", true);
|
209
|
+
} else {
|
210
|
+
return runtime.newFixnum(this.hp.parser.nread);
|
211
|
+
}
|
212
|
+
}
|
213
|
+
}
|
214
|
+
|
215
|
+
@JRubyMethod(name = "error?")
|
216
|
+
public IRubyObject has_error() {
|
217
|
+
return this.hp.has_error() ? runtime.getTrue() : runtime.getFalse();
|
218
|
+
}
|
219
|
+
|
220
|
+
@JRubyMethod(name = "finished?")
|
221
|
+
public IRubyObject is_finished() {
|
222
|
+
return this.hp.is_finished() ? runtime.getTrue() : runtime.getFalse();
|
223
|
+
}
|
224
|
+
|
225
|
+
@JRubyMethod
|
226
|
+
public IRubyObject nread() {
|
227
|
+
return runtime.newFixnum(this.hp.parser.nread);
|
228
|
+
}
|
229
|
+
|
230
|
+
@JRubyMethod
|
231
|
+
public IRubyObject body() {
|
232
|
+
return body;
|
233
|
+
}
|
234
|
+
}// Http11
|
@@ -0,0 +1,470 @@
|
|
1
|
+
|
2
|
+
// line 1 "ext/puma_http11/http11_parser.java.rl"
|
3
|
+
package org.jruby.puma;
|
4
|
+
|
5
|
+
import org.jruby.util.ByteList;
|
6
|
+
|
7
|
+
public class Http11Parser {
|
8
|
+
|
9
|
+
/** Machine **/
|
10
|
+
|
11
|
+
|
12
|
+
// line 65 "ext/puma_http11/http11_parser.java.rl"
|
13
|
+
|
14
|
+
|
15
|
+
/** Data **/
|
16
|
+
|
17
|
+
// line 18 "ext/puma_http11/org/jruby/puma/Http11Parser.java"
|
18
|
+
private static byte[] init__puma_parser_actions_0()
|
19
|
+
{
|
20
|
+
return new byte [] {
|
21
|
+
0, 1, 0, 1, 2, 1, 3, 1, 4, 1, 5, 1,
|
22
|
+
6, 1, 7, 1, 8, 1, 9, 1, 11, 1, 12, 1,
|
23
|
+
13, 2, 0, 8, 2, 1, 2, 2, 4, 5, 2, 10,
|
24
|
+
7, 2, 12, 7, 3, 9, 10, 7
|
25
|
+
};
|
26
|
+
}
|
27
|
+
|
28
|
+
private static final byte _puma_parser_actions[] = init__puma_parser_actions_0();
|
29
|
+
|
30
|
+
|
31
|
+
private static short[] init__puma_parser_key_offsets_0()
|
32
|
+
{
|
33
|
+
return new short [] {
|
34
|
+
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
|
38
|
+
};
|
39
|
+
}
|
40
|
+
|
41
|
+
private static final short _puma_parser_key_offsets[] = init__puma_parser_key_offsets_0();
|
42
|
+
|
43
|
+
|
44
|
+
private static char[] init__puma_parser_trans_keys_0()
|
45
|
+
{
|
46
|
+
return new char [] {
|
47
|
+
36, 95, 45, 46, 48, 57, 65, 90, 32, 36, 95, 45,
|
48
|
+
46, 48, 57, 65, 90, 42, 43, 47, 58, 45, 57, 65,
|
49
|
+
90, 97, 122, 32, 35, 72, 84, 84, 80, 47, 48, 57,
|
50
|
+
46, 48, 57, 48, 57, 13, 48, 57, 10, 13, 33, 124,
|
51
|
+
126, 35, 39, 42, 43, 45, 46, 48, 57, 65, 90, 94,
|
52
|
+
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,
|
58
|
+
0, 31, 32, 34, 35, 60, 62, 127, 0, 31, 32, 34,
|
59
|
+
35, 60, 62, 127, 0, 31, 32, 36, 95, 45, 46, 48,
|
60
|
+
57, 65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90,
|
61
|
+
32, 36, 95, 45, 46, 48, 57, 65, 90, 32, 36, 95,
|
62
|
+
45, 46, 48, 57, 65, 90, 32, 36, 95, 45, 46, 48,
|
63
|
+
57, 65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90,
|
64
|
+
32, 36, 95, 45, 46, 48, 57, 65, 90, 32, 36, 95,
|
65
|
+
45, 46, 48, 57, 65, 90, 32, 36, 95, 45, 46, 48,
|
66
|
+
57, 65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90,
|
67
|
+
32, 36, 95, 45, 46, 48, 57, 65, 90, 32, 36, 95,
|
68
|
+
45, 46, 48, 57, 65, 90, 32, 36, 95, 45, 46, 48,
|
69
|
+
57, 65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90,
|
70
|
+
32, 36, 95, 45, 46, 48, 57, 65, 90, 32, 36, 95,
|
71
|
+
45, 46, 48, 57, 65, 90, 32, 36, 95, 45, 46, 48,
|
72
|
+
57, 65, 90, 32, 36, 95, 45, 46, 48, 57, 65, 90,
|
73
|
+
32, 0
|
74
|
+
};
|
75
|
+
}
|
76
|
+
|
77
|
+
private static final char _puma_parser_trans_keys[] = init__puma_parser_trans_keys_0();
|
78
|
+
|
79
|
+
|
80
|
+
private static byte[] init__puma_parser_single_lengths_0()
|
81
|
+
{
|
82
|
+
return new byte [] {
|
83
|
+
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
|
87
|
+
};
|
88
|
+
}
|
89
|
+
|
90
|
+
private static final byte _puma_parser_single_lengths[] = init__puma_parser_single_lengths_0();
|
91
|
+
|
92
|
+
|
93
|
+
private static byte[] init__puma_parser_range_lengths_0()
|
94
|
+
{
|
95
|
+
return new byte [] {
|
96
|
+
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
|
100
|
+
};
|
101
|
+
}
|
102
|
+
|
103
|
+
private static final byte _puma_parser_range_lengths[] = init__puma_parser_range_lengths_0();
|
104
|
+
|
105
|
+
|
106
|
+
private static short[] init__puma_parser_index_offsets_0()
|
107
|
+
{
|
108
|
+
return new short [] {
|
109
|
+
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
|
113
|
+
};
|
114
|
+
}
|
115
|
+
|
116
|
+
private static final short _puma_parser_index_offsets[] = init__puma_parser_index_offsets_0();
|
117
|
+
|
118
|
+
|
119
|
+
private static byte[] init__puma_parser_indicies_0()
|
120
|
+
{
|
121
|
+
return new byte [] {
|
122
|
+
0, 0, 0, 0, 0, 1, 2, 3, 3, 3, 3, 3,
|
123
|
+
1, 4, 5, 6, 7, 5, 5, 5, 1, 8, 9, 1,
|
124
|
+
10, 1, 11, 1, 12, 1, 13, 1, 14, 1, 15, 1,
|
125
|
+
16, 15, 1, 17, 1, 18, 17, 1, 19, 1, 20, 21,
|
126
|
+
21, 21, 21, 21, 21, 21, 21, 21, 1, 22, 1, 23,
|
127
|
+
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
|
145
|
+
};
|
146
|
+
}
|
147
|
+
|
148
|
+
private static final byte _puma_parser_indicies[] = init__puma_parser_indicies_0();
|
149
|
+
|
150
|
+
|
151
|
+
private static byte[] init__puma_parser_trans_targs_0()
|
152
|
+
{
|
153
|
+
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
|
+
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
|
160
|
+
};
|
161
|
+
}
|
162
|
+
|
163
|
+
private static final byte _puma_parser_trans_targs[] = init__puma_parser_trans_targs_0();
|
164
|
+
|
165
|
+
|
166
|
+
private static byte[] init__puma_parser_trans_actions_0()
|
167
|
+
{
|
168
|
+
return new byte [] {
|
169
|
+
1, 0, 11, 0, 1, 1, 1, 1, 13, 13, 1, 0,
|
170
|
+
0, 0, 0, 0, 0, 0, 19, 0, 0, 28, 23, 3,
|
171
|
+
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
|
175
|
+
};
|
176
|
+
}
|
177
|
+
|
178
|
+
private static final byte _puma_parser_trans_actions[] = init__puma_parser_trans_actions_0();
|
179
|
+
|
180
|
+
|
181
|
+
static final int puma_parser_start = 1;
|
182
|
+
static final int puma_parser_first_final = 47;
|
183
|
+
static final int puma_parser_error = 0;
|
184
|
+
|
185
|
+
// line 69 "ext/puma_http11/http11_parser.java.rl"
|
186
|
+
|
187
|
+
public static interface ElementCB {
|
188
|
+
public void call(Object data, int at, int length);
|
189
|
+
}
|
190
|
+
|
191
|
+
public static interface FieldCB {
|
192
|
+
public void call(Object data, int field, int flen, int value, int vlen);
|
193
|
+
}
|
194
|
+
|
195
|
+
public static class HttpParser {
|
196
|
+
int cs;
|
197
|
+
int body_start;
|
198
|
+
int content_len;
|
199
|
+
int nread;
|
200
|
+
int mark;
|
201
|
+
int field_start;
|
202
|
+
int field_len;
|
203
|
+
int query_start;
|
204
|
+
|
205
|
+
Object data;
|
206
|
+
ByteList buffer;
|
207
|
+
|
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
|
+
public void init() {
|
218
|
+
cs = 0;
|
219
|
+
|
220
|
+
|
221
|
+
// line 225 "ext/puma_http11/org/jruby/puma/Http11Parser.java"
|
222
|
+
{
|
223
|
+
cs = puma_parser_start;
|
224
|
+
}
|
225
|
+
|
226
|
+
// line 104 "ext/puma_http11/http11_parser.java.rl"
|
227
|
+
|
228
|
+
body_start = 0;
|
229
|
+
content_len = 0;
|
230
|
+
mark = 0;
|
231
|
+
nread = 0;
|
232
|
+
field_len = 0;
|
233
|
+
field_start = 0;
|
234
|
+
}
|
235
|
+
}
|
236
|
+
|
237
|
+
public final HttpParser parser = new HttpParser();
|
238
|
+
|
239
|
+
public int execute(ByteList buffer, int off) {
|
240
|
+
int p, pe;
|
241
|
+
int cs = parser.cs;
|
242
|
+
int len = buffer.length();
|
243
|
+
assert off<=len : "offset past end of buffer";
|
244
|
+
|
245
|
+
p = off;
|
246
|
+
pe = len;
|
247
|
+
// get a copy of the bytes, since it may not start at 0
|
248
|
+
// FIXME: figure out how to just use the bytes in-place
|
249
|
+
byte[] data = buffer.bytes();
|
250
|
+
parser.buffer = buffer;
|
251
|
+
|
252
|
+
|
253
|
+
// line 257 "ext/puma_http11/org/jruby/puma/Http11Parser.java"
|
254
|
+
{
|
255
|
+
int _klen;
|
256
|
+
int _trans = 0;
|
257
|
+
int _acts;
|
258
|
+
int _nacts;
|
259
|
+
int _keys;
|
260
|
+
int _goto_targ = 0;
|
261
|
+
|
262
|
+
_goto: while (true) {
|
263
|
+
switch ( _goto_targ ) {
|
264
|
+
case 0:
|
265
|
+
if ( p == pe ) {
|
266
|
+
_goto_targ = 4;
|
267
|
+
continue _goto;
|
268
|
+
}
|
269
|
+
if ( cs == 0 ) {
|
270
|
+
_goto_targ = 5;
|
271
|
+
continue _goto;
|
272
|
+
}
|
273
|
+
case 1:
|
274
|
+
_match: do {
|
275
|
+
_keys = _puma_parser_key_offsets[cs];
|
276
|
+
_trans = _puma_parser_index_offsets[cs];
|
277
|
+
_klen = _puma_parser_single_lengths[cs];
|
278
|
+
if ( _klen > 0 ) {
|
279
|
+
int _lower = _keys;
|
280
|
+
int _mid;
|
281
|
+
int _upper = _keys + _klen - 1;
|
282
|
+
while (true) {
|
283
|
+
if ( _upper < _lower )
|
284
|
+
break;
|
285
|
+
|
286
|
+
_mid = _lower + ((_upper-_lower) >> 1);
|
287
|
+
if ( data[p] < _puma_parser_trans_keys[_mid] )
|
288
|
+
_upper = _mid - 1;
|
289
|
+
else if ( data[p] > _puma_parser_trans_keys[_mid] )
|
290
|
+
_lower = _mid + 1;
|
291
|
+
else {
|
292
|
+
_trans += (_mid - _keys);
|
293
|
+
break _match;
|
294
|
+
}
|
295
|
+
}
|
296
|
+
_keys += _klen;
|
297
|
+
_trans += _klen;
|
298
|
+
}
|
299
|
+
|
300
|
+
_klen = _puma_parser_range_lengths[cs];
|
301
|
+
if ( _klen > 0 ) {
|
302
|
+
int _lower = _keys;
|
303
|
+
int _mid;
|
304
|
+
int _upper = _keys + (_klen<<1) - 2;
|
305
|
+
while (true) {
|
306
|
+
if ( _upper < _lower )
|
307
|
+
break;
|
308
|
+
|
309
|
+
_mid = _lower + (((_upper-_lower) >> 1) & ~1);
|
310
|
+
if ( data[p] < _puma_parser_trans_keys[_mid] )
|
311
|
+
_upper = _mid - 2;
|
312
|
+
else if ( data[p] > _puma_parser_trans_keys[_mid+1] )
|
313
|
+
_lower = _mid + 2;
|
314
|
+
else {
|
315
|
+
_trans += ((_mid - _keys)>>1);
|
316
|
+
break _match;
|
317
|
+
}
|
318
|
+
}
|
319
|
+
_trans += _klen;
|
320
|
+
}
|
321
|
+
} while (false);
|
322
|
+
|
323
|
+
_trans = _puma_parser_indicies[_trans];
|
324
|
+
cs = _puma_parser_trans_targs[_trans];
|
325
|
+
|
326
|
+
if ( _puma_parser_trans_actions[_trans] != 0 ) {
|
327
|
+
_acts = _puma_parser_trans_actions[_trans];
|
328
|
+
_nacts = (int) _puma_parser_actions[_acts++];
|
329
|
+
while ( _nacts-- > 0 )
|
330
|
+
{
|
331
|
+
switch ( _puma_parser_actions[_acts++] )
|
332
|
+
{
|
333
|
+
case 0:
|
334
|
+
// line 13 "ext/puma_http11/http11_parser.java.rl"
|
335
|
+
{parser.mark = p; }
|
336
|
+
break;
|
337
|
+
case 1:
|
338
|
+
// line 15 "ext/puma_http11/http11_parser.java.rl"
|
339
|
+
{ parser.field_start = p; }
|
340
|
+
break;
|
341
|
+
case 2:
|
342
|
+
// line 16 "ext/puma_http11/http11_parser.java.rl"
|
343
|
+
{ /* FIXME stub */ }
|
344
|
+
break;
|
345
|
+
case 3:
|
346
|
+
// line 17 "ext/puma_http11/http11_parser.java.rl"
|
347
|
+
{
|
348
|
+
parser.field_len = p-parser.field_start;
|
349
|
+
}
|
350
|
+
break;
|
351
|
+
case 4:
|
352
|
+
// line 21 "ext/puma_http11/http11_parser.java.rl"
|
353
|
+
{ parser.mark = p; }
|
354
|
+
break;
|
355
|
+
case 5:
|
356
|
+
// line 22 "ext/puma_http11/http11_parser.java.rl"
|
357
|
+
{
|
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
|
+
}
|
361
|
+
}
|
362
|
+
break;
|
363
|
+
case 6:
|
364
|
+
// line 27 "ext/puma_http11/http11_parser.java.rl"
|
365
|
+
{
|
366
|
+
if(parser.request_method != null)
|
367
|
+
parser.request_method.call(parser.data, parser.mark, p-parser.mark);
|
368
|
+
}
|
369
|
+
break;
|
370
|
+
case 7:
|
371
|
+
// line 31 "ext/puma_http11/http11_parser.java.rl"
|
372
|
+
{
|
373
|
+
if(parser.request_uri != null)
|
374
|
+
parser.request_uri.call(parser.data, parser.mark, p-parser.mark);
|
375
|
+
}
|
376
|
+
break;
|
377
|
+
case 8:
|
378
|
+
// line 35 "ext/puma_http11/http11_parser.java.rl"
|
379
|
+
{
|
380
|
+
if(parser.fragment != null)
|
381
|
+
parser.fragment.call(parser.data, parser.mark, p-parser.mark);
|
382
|
+
}
|
383
|
+
break;
|
384
|
+
case 9:
|
385
|
+
// line 40 "ext/puma_http11/http11_parser.java.rl"
|
386
|
+
{parser.query_start = p; }
|
387
|
+
break;
|
388
|
+
case 10:
|
389
|
+
// line 41 "ext/puma_http11/http11_parser.java.rl"
|
390
|
+
{
|
391
|
+
if(parser.query_string != null)
|
392
|
+
parser.query_string.call(parser.data, parser.query_start, p-parser.query_start);
|
393
|
+
}
|
394
|
+
break;
|
395
|
+
case 11:
|
396
|
+
// line 46 "ext/puma_http11/http11_parser.java.rl"
|
397
|
+
{
|
398
|
+
if(parser.http_version != null)
|
399
|
+
parser.http_version.call(parser.data, parser.mark, p-parser.mark);
|
400
|
+
}
|
401
|
+
break;
|
402
|
+
case 12:
|
403
|
+
// line 51 "ext/puma_http11/http11_parser.java.rl"
|
404
|
+
{
|
405
|
+
if(parser.request_path != null)
|
406
|
+
parser.request_path.call(parser.data, parser.mark, p-parser.mark);
|
407
|
+
}
|
408
|
+
break;
|
409
|
+
case 13:
|
410
|
+
// line 56 "ext/puma_http11/http11_parser.java.rl"
|
411
|
+
{
|
412
|
+
parser.body_start = p + 1;
|
413
|
+
if(parser.header_done != null)
|
414
|
+
parser.header_done.call(parser.data, p + 1, pe - p - 1);
|
415
|
+
{ p += 1; _goto_targ = 5; if (true) continue _goto;}
|
416
|
+
}
|
417
|
+
break;
|
418
|
+
// line 422 "ext/puma_http11/org/jruby/puma/Http11Parser.java"
|
419
|
+
}
|
420
|
+
}
|
421
|
+
}
|
422
|
+
|
423
|
+
case 2:
|
424
|
+
if ( cs == 0 ) {
|
425
|
+
_goto_targ = 5;
|
426
|
+
continue _goto;
|
427
|
+
}
|
428
|
+
if ( ++p != pe ) {
|
429
|
+
_goto_targ = 1;
|
430
|
+
continue _goto;
|
431
|
+
}
|
432
|
+
case 4:
|
433
|
+
case 5:
|
434
|
+
}
|
435
|
+
break; }
|
436
|
+
}
|
437
|
+
|
438
|
+
// line 130 "ext/puma_http11/http11_parser.java.rl"
|
439
|
+
|
440
|
+
parser.cs = cs;
|
441
|
+
parser.nread += (p - off);
|
442
|
+
|
443
|
+
assert p <= pe : "buffer overflow after parsing execute";
|
444
|
+
assert parser.nread <= len : "nread longer than length";
|
445
|
+
assert parser.body_start <= len : "body starts after buffer end";
|
446
|
+
assert parser.mark < len : "mark is after buffer end";
|
447
|
+
assert parser.field_len <= len : "field has length longer than whole buffer";
|
448
|
+
assert parser.field_start < len : "field starts after buffer end";
|
449
|
+
|
450
|
+
return parser.nread;
|
451
|
+
}
|
452
|
+
|
453
|
+
public int finish() {
|
454
|
+
if(has_error()) {
|
455
|
+
return -1;
|
456
|
+
} else if(is_finished()) {
|
457
|
+
return 1;
|
458
|
+
} else {
|
459
|
+
return 0;
|
460
|
+
}
|
461
|
+
}
|
462
|
+
|
463
|
+
public boolean has_error() {
|
464
|
+
return parser.cs == puma_parser_error;
|
465
|
+
}
|
466
|
+
|
467
|
+
public boolean is_finished() {
|
468
|
+
return parser.cs == puma_parser_first_final;
|
469
|
+
}
|
470
|
+
}
|