mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
Eliminate callback objects and indirection altogether.
There's only ever one implementation of these, so just call them directly.
This commit is contained in:
parent
080861c025
commit
46709adcd3
3 changed files with 110 additions and 170 deletions
|
@ -22,43 +22,34 @@ public class Http11Parser {
|
|||
|
||||
action start_value { parser.mark = fpc; }
|
||||
action write_value {
|
||||
if(parser.http_field != null) {
|
||||
parser.http_field.call(runtime, parser.data, parser.buffer, parser.field_start, parser.field_len, parser.mark, fpc-parser.mark);
|
||||
}
|
||||
Http11.http_field(runtime, parser.data, parser.buffer, parser.field_start, parser.field_len, parser.mark, fpc-parser.mark);
|
||||
}
|
||||
action request_method {
|
||||
if(parser.request_method != null)
|
||||
parser.request_method.call(runtime, parser.data, parser.buffer, parser.mark, fpc-parser.mark);
|
||||
Http11.request_method(runtime, parser.data, parser.buffer, parser.mark, fpc-parser.mark);
|
||||
}
|
||||
action request_uri {
|
||||
if(parser.request_uri != null)
|
||||
parser.request_uri.call(runtime, parser.data, parser.buffer, parser.mark, fpc-parser.mark);
|
||||
Http11.request_uri(runtime, parser.data, parser.buffer, parser.mark, fpc-parser.mark);
|
||||
}
|
||||
action fragment {
|
||||
if(parser.fragment != null)
|
||||
parser.fragment.call(runtime, parser.data, parser.buffer, parser.mark, fpc-parser.mark);
|
||||
Http11.fragment(runtime, parser.data, parser.buffer, parser.mark, fpc-parser.mark);
|
||||
}
|
||||
|
||||
action start_query {parser.query_start = fpc; }
|
||||
action query_string {
|
||||
if(parser.query_string != null)
|
||||
parser.query_string.call(runtime, parser.data, parser.buffer, parser.query_start, fpc-parser.query_start);
|
||||
Http11.query_string(runtime, parser.data, parser.buffer, parser.query_start, fpc-parser.query_start);
|
||||
}
|
||||
|
||||
action http_version {
|
||||
if(parser.http_version != null)
|
||||
parser.http_version.call(runtime, parser.data, parser.buffer, parser.mark, fpc-parser.mark);
|
||||
Http11.http_version(runtime, parser.data, parser.buffer, parser.mark, fpc-parser.mark);
|
||||
}
|
||||
|
||||
action request_path {
|
||||
if(parser.request_path != null)
|
||||
parser.request_path.call(runtime, parser.data, parser.buffer, parser.mark, fpc-parser.mark);
|
||||
Http11.request_path(runtime, parser.data, parser.buffer, parser.mark, fpc-parser.mark);
|
||||
}
|
||||
|
||||
action done {
|
||||
parser.body_start = fpc + 1;
|
||||
if(parser.header_done != null)
|
||||
parser.header_done.call(runtime, parser.data, parser.buffer, fpc + 1, pe - fpc - 1);
|
||||
http.header_done(runtime, parser.data, parser.buffer, fpc + 1, pe - fpc - 1);
|
||||
fbreak;
|
||||
}
|
||||
|
||||
|
@ -90,15 +81,6 @@ public class Http11Parser {
|
|||
RubyHash data;
|
||||
ByteList buffer;
|
||||
|
||||
public FieldCB http_field;
|
||||
public ElementCB request_method;
|
||||
public ElementCB request_uri;
|
||||
public ElementCB fragment;
|
||||
public ElementCB request_path;
|
||||
public ElementCB query_string;
|
||||
public ElementCB http_version;
|
||||
public ElementCB header_done;
|
||||
|
||||
public void init() {
|
||||
cs = 0;
|
||||
|
||||
|
@ -115,7 +97,7 @@ public class Http11Parser {
|
|||
|
||||
public final HttpParser parser = new HttpParser();
|
||||
|
||||
public int execute(Ruby runtime, ByteList buffer, int off) {
|
||||
public int execute(Ruby runtime, Http11 http, ByteList buffer, int off) {
|
||||
int p, pe;
|
||||
int cs = parser.cs;
|
||||
int len = buffer.length();
|
||||
|
|
|
@ -70,14 +70,6 @@ public class Http11 extends RubyObject {
|
|||
super(runtime,clazz);
|
||||
this.runtime = runtime;
|
||||
this.hp = new Http11Parser();
|
||||
this.hp.parser.http_field = http_field;
|
||||
this.hp.parser.request_method = request_method;
|
||||
this.hp.parser.request_uri = request_uri;
|
||||
this.hp.parser.fragment = fragment;
|
||||
this.hp.parser.request_path = request_path;
|
||||
this.hp.parser.query_string = query_string;
|
||||
this.hp.parser.http_version = http_version;
|
||||
this.hp.parser.header_done = header_done;
|
||||
this.hp.parser.init();
|
||||
}
|
||||
|
||||
|
@ -96,8 +88,7 @@ public class Http11 extends RubyObject {
|
|||
return (RubyClass)runtime.getModule("Puma").getConstant("HttpParserError");
|
||||
}
|
||||
|
||||
private static Http11Parser.FieldCB http_field = new Http11Parser.FieldCB() {
|
||||
public void call(Ruby runtime, RubyHash req, ByteList buffer, int field, int flen, int value, int vlen) {
|
||||
public static void http_field(Ruby runtime, RubyHash req, ByteList buffer, int field, int flen, int value, int vlen) {
|
||||
RubyString f;
|
||||
IRubyObject v;
|
||||
validateMaxLength(runtime, flen, MAX_FIELD_NAME_LENGTH, MAX_FIELD_NAME_LENGTH_ERR);
|
||||
|
@ -130,59 +121,44 @@ public class Http11 extends RubyObject {
|
|||
vs.cat(b);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private static Http11Parser.ElementCB request_method = new Http11Parser.ElementCB() {
|
||||
public void call(Ruby runtime, RubyHash req, ByteList buffer, int at, int length) {
|
||||
public static void request_method(Ruby runtime, RubyHash req, ByteList buffer, int at, int length) {
|
||||
RubyString val = RubyString.newString(runtime,new ByteList(buffer,at,length));
|
||||
req.fastASet(RubyString.newStringShared(runtime, REQUEST_METHOD_BYTELIST),val);
|
||||
}
|
||||
};
|
||||
|
||||
private static Http11Parser.ElementCB request_uri = new Http11Parser.ElementCB() {
|
||||
public void call(Ruby runtime, RubyHash req, ByteList buffer, int at, int length) {
|
||||
public static void request_uri(Ruby runtime, RubyHash req, ByteList buffer, int at, int length) {
|
||||
validateMaxLength(runtime, length, MAX_REQUEST_URI_LENGTH, MAX_REQUEST_URI_LENGTH_ERR);
|
||||
RubyString val = RubyString.newString(runtime,new ByteList(buffer,at,length));
|
||||
req.fastASet(RubyString.newStringShared(runtime, REQUEST_URI_BYTELIST),val);
|
||||
}
|
||||
};
|
||||
|
||||
private static Http11Parser.ElementCB fragment = new Http11Parser.ElementCB() {
|
||||
public void call(Ruby runtime, RubyHash req, ByteList buffer, int at, int length) {
|
||||
public static void fragment(Ruby runtime, RubyHash req, ByteList buffer, int at, int length) {
|
||||
validateMaxLength(runtime, length, MAX_FRAGMENT_LENGTH, MAX_FRAGMENT_LENGTH_ERR);
|
||||
RubyString val = RubyString.newString(runtime,new ByteList(buffer,at,length));
|
||||
req.fastASet(RubyString.newStringShared(runtime, FRAGMENT_BYTELIST),val);
|
||||
}
|
||||
};
|
||||
|
||||
private static Http11Parser.ElementCB request_path = new Http11Parser.ElementCB() {
|
||||
public void call(Ruby runtime, RubyHash req, ByteList buffer, int at, int length) {
|
||||
public static void request_path(Ruby runtime, RubyHash req, ByteList buffer, int at, int length) {
|
||||
validateMaxLength(runtime, length, MAX_REQUEST_PATH_LENGTH, MAX_REQUEST_PATH_LENGTH_ERR);
|
||||
RubyString val = RubyString.newString(runtime,new ByteList(buffer,at,length));
|
||||
req.fastASet(RubyString.newStringShared(runtime, REQUEST_PATH_BYTELIST),val);
|
||||
}
|
||||
};
|
||||
|
||||
private static Http11Parser.ElementCB query_string = new Http11Parser.ElementCB() {
|
||||
public void call(Ruby runtime, RubyHash req, ByteList buffer, int at, int length) {
|
||||
public static void query_string(Ruby runtime, RubyHash req, ByteList buffer, int at, int length) {
|
||||
validateMaxLength(runtime, length, MAX_QUERY_STRING_LENGTH, MAX_QUERY_STRING_LENGTH_ERR);
|
||||
RubyString val = RubyString.newString(runtime,new ByteList(buffer,at,length));
|
||||
req.fastASet(RubyString.newStringShared(runtime, QUERY_STRING_BYTELIST),val);
|
||||
}
|
||||
};
|
||||
|
||||
private static Http11Parser.ElementCB http_version = new Http11Parser.ElementCB() {
|
||||
public void call(Ruby runtime, RubyHash req, ByteList buffer, int at, int length) {
|
||||
public static void http_version(Ruby runtime, RubyHash req, ByteList buffer, int at, int length) {
|
||||
RubyString val = RubyString.newString(runtime,new ByteList(buffer,at,length));
|
||||
req.fastASet(RubyString.newStringShared(runtime, HTTP_VERSION_BYTELIST),val);
|
||||
}
|
||||
};
|
||||
|
||||
private Http11Parser.ElementCB header_done = new Http11Parser.ElementCB() {
|
||||
public void call(Ruby runtime, RubyHash req, ByteList buffer, int at, int length) {
|
||||
public void header_done(Ruby runtime, RubyHash req, ByteList buffer, int at, int length) {
|
||||
body = RubyString.newStringShared(runtime, new ByteList(buffer, at, length));
|
||||
}
|
||||
};
|
||||
|
||||
@JRubyMethod
|
||||
public IRubyObject initialize() {
|
||||
|
@ -214,7 +190,7 @@ public class Http11 extends RubyObject {
|
|||
|
||||
parser.data = (RubyHash) req_hash;
|
||||
|
||||
hp.execute(runtime, d,from);
|
||||
hp.execute(runtime, this, d,from);
|
||||
|
||||
validateMaxLength(runtime, parser.nread,MAX_HEADER_LENGTH, MAX_HEADER_LENGTH_ERR);
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ public class Http11Parser {
|
|||
/** Machine **/
|
||||
|
||||
|
||||
// line 67 "ext/puma_http11/http11_parser.java.rl"
|
||||
// line 58 "ext/puma_http11/http11_parser.java.rl"
|
||||
|
||||
|
||||
/** Data **/
|
||||
|
@ -185,7 +185,7 @@ static final int puma_parser_error = 0;
|
|||
static final int puma_parser_en_main = 1;
|
||||
|
||||
|
||||
// line 71 "ext/puma_http11/http11_parser.java.rl"
|
||||
// line 62 "ext/puma_http11/http11_parser.java.rl"
|
||||
|
||||
public static interface ElementCB {
|
||||
public void call(Ruby runtime, RubyHash data, ByteList buffer, int at, int length);
|
||||
|
@ -208,25 +208,16 @@ static final int puma_parser_en_main = 1;
|
|||
RubyHash data;
|
||||
ByteList buffer;
|
||||
|
||||
public FieldCB http_field;
|
||||
public ElementCB request_method;
|
||||
public ElementCB request_uri;
|
||||
public ElementCB fragment;
|
||||
public ElementCB request_path;
|
||||
public ElementCB query_string;
|
||||
public ElementCB http_version;
|
||||
public ElementCB header_done;
|
||||
|
||||
public void init() {
|
||||
cs = 0;
|
||||
|
||||
|
||||
// line 225 "ext/puma_http11/org/jruby/puma/Http11Parser.java"
|
||||
// line 218 "ext/puma_http11/org/jruby/puma/Http11Parser.java"
|
||||
{
|
||||
cs = puma_parser_start;
|
||||
}
|
||||
|
||||
// line 106 "ext/puma_http11/http11_parser.java.rl"
|
||||
// line 90 "ext/puma_http11/http11_parser.java.rl"
|
||||
|
||||
body_start = 0;
|
||||
content_len = 0;
|
||||
|
@ -239,7 +230,7 @@ static final int puma_parser_en_main = 1;
|
|||
|
||||
public final HttpParser parser = new HttpParser();
|
||||
|
||||
public int execute(Ruby runtime, ByteList buffer, int off) {
|
||||
public int execute(Ruby runtime, Http11 http, ByteList buffer, int off) {
|
||||
int p, pe;
|
||||
int cs = parser.cs;
|
||||
int len = buffer.length();
|
||||
|
@ -253,7 +244,7 @@ static final int puma_parser_en_main = 1;
|
|||
parser.buffer = buffer;
|
||||
|
||||
|
||||
// line 257 "ext/puma_http11/org/jruby/puma/Http11Parser.java"
|
||||
// line 250 "ext/puma_http11/org/jruby/puma/Http11Parser.java"
|
||||
{
|
||||
int _klen;
|
||||
int _trans = 0;
|
||||
|
@ -358,67 +349,58 @@ case 1:
|
|||
case 5:
|
||||
// line 24 "ext/puma_http11/http11_parser.java.rl"
|
||||
{
|
||||
if(parser.http_field != null) {
|
||||
parser.http_field.call(runtime, parser.data, parser.buffer, parser.field_start, parser.field_len, parser.mark, p-parser.mark);
|
||||
}
|
||||
Http11.http_field(runtime, parser.data, parser.buffer, parser.field_start, parser.field_len, parser.mark, p-parser.mark);
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
// line 29 "ext/puma_http11/http11_parser.java.rl"
|
||||
// line 27 "ext/puma_http11/http11_parser.java.rl"
|
||||
{
|
||||
if(parser.request_method != null)
|
||||
parser.request_method.call(runtime, parser.data, parser.buffer, parser.mark, p-parser.mark);
|
||||
Http11.request_method(runtime, parser.data, parser.buffer, parser.mark, p-parser.mark);
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
// line 33 "ext/puma_http11/http11_parser.java.rl"
|
||||
// line 30 "ext/puma_http11/http11_parser.java.rl"
|
||||
{
|
||||
if(parser.request_uri != null)
|
||||
parser.request_uri.call(runtime, parser.data, parser.buffer, parser.mark, p-parser.mark);
|
||||
Http11.request_uri(runtime, parser.data, parser.buffer, parser.mark, p-parser.mark);
|
||||
}
|
||||
break;
|
||||
case 8:
|
||||
// line 37 "ext/puma_http11/http11_parser.java.rl"
|
||||
// line 33 "ext/puma_http11/http11_parser.java.rl"
|
||||
{
|
||||
if(parser.fragment != null)
|
||||
parser.fragment.call(runtime, parser.data, parser.buffer, parser.mark, p-parser.mark);
|
||||
Http11.fragment(runtime, parser.data, parser.buffer, parser.mark, p-parser.mark);
|
||||
}
|
||||
break;
|
||||
case 9:
|
||||
// line 42 "ext/puma_http11/http11_parser.java.rl"
|
||||
// line 37 "ext/puma_http11/http11_parser.java.rl"
|
||||
{parser.query_start = p; }
|
||||
break;
|
||||
case 10:
|
||||
// line 43 "ext/puma_http11/http11_parser.java.rl"
|
||||
// line 38 "ext/puma_http11/http11_parser.java.rl"
|
||||
{
|
||||
if(parser.query_string != null)
|
||||
parser.query_string.call(runtime, parser.data, parser.buffer, parser.query_start, p-parser.query_start);
|
||||
Http11.query_string(runtime, parser.data, parser.buffer, parser.query_start, p-parser.query_start);
|
||||
}
|
||||
break;
|
||||
case 11:
|
||||
// line 48 "ext/puma_http11/http11_parser.java.rl"
|
||||
// line 42 "ext/puma_http11/http11_parser.java.rl"
|
||||
{
|
||||
if(parser.http_version != null)
|
||||
parser.http_version.call(runtime, parser.data, parser.buffer, parser.mark, p-parser.mark);
|
||||
Http11.http_version(runtime, parser.data, parser.buffer, parser.mark, p-parser.mark);
|
||||
}
|
||||
break;
|
||||
case 12:
|
||||
// line 53 "ext/puma_http11/http11_parser.java.rl"
|
||||
// line 46 "ext/puma_http11/http11_parser.java.rl"
|
||||
{
|
||||
if(parser.request_path != null)
|
||||
parser.request_path.call(runtime, parser.data, parser.buffer, parser.mark, p-parser.mark);
|
||||
Http11.request_path(runtime, parser.data, parser.buffer, parser.mark, p-parser.mark);
|
||||
}
|
||||
break;
|
||||
case 13:
|
||||
// line 58 "ext/puma_http11/http11_parser.java.rl"
|
||||
// line 50 "ext/puma_http11/http11_parser.java.rl"
|
||||
{
|
||||
parser.body_start = p + 1;
|
||||
if(parser.header_done != null)
|
||||
parser.header_done.call(runtime, parser.data, parser.buffer, p + 1, pe - p - 1);
|
||||
http.header_done(runtime, parser.data, parser.buffer, p + 1, pe - p - 1);
|
||||
{ p += 1; _goto_targ = 5; if (true) continue _goto;}
|
||||
}
|
||||
break;
|
||||
// line 422 "ext/puma_http11/org/jruby/puma/Http11Parser.java"
|
||||
// line 406 "ext/puma_http11/org/jruby/puma/Http11Parser.java"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -438,7 +420,7 @@ case 5:
|
|||
break; }
|
||||
}
|
||||
|
||||
// line 132 "ext/puma_http11/http11_parser.java.rl"
|
||||
// line 116 "ext/puma_http11/http11_parser.java.rl"
|
||||
|
||||
parser.cs = cs;
|
||||
parser.nread += (p - off);
|
||||
|
|
Loading…
Reference in a new issue