diff --git a/ext/puma_http11/org/jruby/puma/Http11.java b/ext/puma_http11/org/jruby/puma/Http11.java index 59dde372..682e877c 100644 --- a/ext/puma_http11/org/jruby/puma/Http11.java +++ b/ext/puma_http11/org/jruby/puma/Http11.java @@ -11,7 +11,6 @@ import org.jruby.RubyString; import org.jruby.anno.JRubyMethod; import org.jruby.runtime.ObjectAllocator; -import org.jruby.runtime.ThreadContext; import org.jruby.runtime.builtin.IRubyObject; import org.jruby.exceptions.RaiseException; @@ -37,6 +36,16 @@ public class Http11 extends RubyObject { public final static int MAX_HEADER_LENGTH = 1024 * (80 + 32); public final static String MAX_HEADER_LENGTH_ERR = "HTTP element HEADER is longer than the 114688 allowed length."; + public static final ByteList CONTENT_TYPE_BYTELIST = new ByteList(ByteList.plain("CONTENT_TYPE")); + public static final ByteList CONTENT_LENGTH_BYTELIST = new ByteList(ByteList.plain("CONTENT_LENGTH")); + public static final ByteList HTTP_PREFIX_BYTELIST = new ByteList(ByteList.plain("HTTP_")); + public static final ByteList COMMA_SPACE_BYTELIST = new ByteList(ByteList.plain(", ")); + public static final ByteList REQUEST_METHOD_BYTELIST = new ByteList(ByteList.plain("REQUEST_METHOD")); + public static final ByteList REQUEST_URI_BYTELIST = new ByteList(ByteList.plain("REQUEST_URI")); + public static final ByteList FRAGMENT_BYTELIST = new ByteList(ByteList.plain("FRAGMENT")); + public static final ByteList REQUEST_PATH_BYTELIST = new ByteList(ByteList.plain("REQUEST_PATH")); + public static final ByteList QUERY_STRING_BYTELIST = new ByteList(ByteList.plain("QUERY_STRING")); + public static final ByteList HTTP_VERSION_BYTELIST = new ByteList(ByteList.plain("HTTP_VERSION")); private static ObjectAllocator ALLOCATOR = new ObjectAllocator() { public IRubyObject allocate(Ruby runtime, RubyClass klass) { @@ -75,10 +84,14 @@ public class Http11 extends RubyObject { public void validateMaxLength(int len, int max, String msg) { if(len>max) { - throw new RaiseException(runtime, eHttpParserError, msg, true); + throw newHTTPParserError(msg); } } + private RaiseException newHTTPParserError(String msg) { + return runtime.newRaiseException(eHttpParserError, msg); + } + private Http11Parser.FieldCB http_field = new Http11Parser.FieldCB() { public void call(Object data, int field, int flen, int value, int vlen) { RubyHash req = (RubyHash)data; @@ -87,31 +100,32 @@ public class Http11 extends RubyObject { validateMaxLength(flen, MAX_FIELD_NAME_LENGTH, MAX_FIELD_NAME_LENGTH_ERR); validateMaxLength(vlen, MAX_FIELD_VALUE_LENGTH, MAX_FIELD_VALUE_LENGTH_ERR); - ByteList b = new ByteList(Http11.this.hp.parser.buffer,field,flen); + ByteList buffer = Http11.this.hp.parser.buffer; + + ByteList b = new ByteList(buffer,field,flen); for(int i = 0,j = b.length();i= d.length()) { - throw new RaiseException(runtime, eHttpParserError, "Requested start is after data buffer end.", true); + throw newHTTPParserError("Requested start is after data buffer end."); } else { this.hp.parser.data = req_hash; this.hp.execute(d,from); validateMaxLength(this.hp.parser.nread,MAX_HEADER_LENGTH, MAX_HEADER_LENGTH_ERR); if(this.hp.has_error()) { - throw new RaiseException(runtime, eHttpParserError, "Invalid HTTP format, parsing fails.", true); + throw newHTTPParserError("Invalid HTTP format, parsing fails."); } else { return runtime.newFixnum(this.hp.parser.nread); }