}
};
this.settings.on_header_value = new HTTPDataCallback() {
public int cb (http_parser.lolevel.HTTPParser p, ByteBuffer buf, int pos, int len) {
byte[] data = fetchBytes(buf, pos, len);
ThreadContext context = headers.getRuntime().getCurrentContext();
IRubyObject key, val;
int new_field = 0;
if (_current_header != null) {
new_field = 1;
_last_header = _current_header;
_current_header = null;
}
key = (IRubyObject)runtime.newString(_last_header);
val = headers.op_aref(context, key);
if (new_field == 1) {
if (val.isNil()) {
if (header_value_type == runtime.newSymbol("arrays")) {
headers.op_aset(context, key, RubyArray.newArrayLight(runtime, runtime.newString("")));
} else {
headers.op_aset(context, key, runtime.newString(""));
}
} else {
if (header_value_type == runtime.newSymbol("mixed")) {
if (val instanceof RubyString) {
headers.op_aset(context, key, RubyArray.newArrayLight(runtime, val, runtime.newString("")));
} else {
((RubyArray)val).add(runtime.newString(""));
}
} else if (header_value_type == runtime.newSymbol("arrays")) {
((RubyArray)val).add(runtime.newString(""));
} else {
((RubyString)val).cat(", ".getBytes());
}
}
val = headers.op_aref(context, key);
}
if (val instanceof RubyArray) {
val = ((RubyArray)val).entry(-1);
}
((RubyString)val).cat(data);
return 0;
}
};
this.settings.on_message_begin = new HTTPCallback() {
public int cb (http_parser.lolevel.HTTPParser p) {
headers = new RubyHash(runtime);
requestUrl = runtime.newString("");
requestPath = runtime.newString("");
queryString = runtime.newString("");
fragment = runtime.newString("");
upgradeData = runtime.newString("");
IRubyObject ret = runtime.getNil();
if (callback_object != null) {
if (((RubyObject)callback_object).respond_to_p(runtime.newSymbol("on_message_begin")).toJava(Boolean.class) == Boolean.TRUE) {
ThreadContext context = callback_object.getRuntime().getCurrentContext();
ret = callback_object.callMethod(context, "on_message_begin");
}
} else if (on_message_begin != null) {
ThreadContext context = on_message_begin.getRuntime().getCurrentContext();
ret = on_message_begin.callMethod(context, "call");
}
if (ret == runtime.newSymbol("stop")) {
throw new StopException();
} else {
return 0;
}
}
};
this.settings.on_message_complete = new HTTPCallback() {
public int cb (http_parser.lolevel.HTTPParser p) {
IRubyObject ret = runtime.getNil();
if (callback_object != null) {
if (((RubyObject)callback_object).respond_to_p(runtime.newSymbol("on_message_complete")).toJava(Boolean.class) == Boolean.TRUE) {
ThreadContext context = callback_object.getRuntime().getCurrentContext();
ret = callback_object.callMethod(context, "on_message_complete");
}
} else if (on_message_complete != null) {
ThreadContext context = on_message_complete.getRuntime().getCurrentContext();
ret = on_message_complete.callMethod(context, "call");
}
if (ret == runtime.newSymbol("stop")) {
throw new StopException();
} else {
return 0;
}
}
};
this.settings.on_headers_complete = new HTTPCallback() {
public int cb (http_parser.lolevel.HTTPParser p) {
IRubyObject ret = runtime.getNil();
if (callback_object != null) {
if (((RubyObject)callback_object).respond_to_p(runtime.newSymbol("on_headers_complete")).toJava(Boolean.class) == Boolean.TRUE) {
ThreadContext context = callback_object.getRuntime().getCurrentContext();
ret = callback_object.callMethod(context, "on_headers_complete", headers);
}
} else if (on_headers_complete != null) {
ThreadContext context = on_headers_complete.getRuntime().getCurrentContext();
ret = on_headers_complete.callMethod(context, "call", headers);
}
if (ret == runtime.newSymbol("stop")) {
throw new StopException();
} else {
return 0;
}
}
};
this.settings.on_body = new HTTPDataCallback() {
public int cb (http_parser.lolevel.HTTPParser p, ByteBuffer buf, int pos, int len) {
IRubyObject ret = runtime.getNil();
byte[] data = fetchBytes(buf, pos, len);
if (callback_object != null) {
if (((RubyObject)callback_object).respond_to_p(runtime.newSymbol("on_body")).toJava(Boolean.class) == Boolean.TRUE) {
ThreadContext context = callback_object.getRuntime().getCurrentContext();
ret = callback_object.callMethod(context, "on_body", callback_object.getRuntime().newString(new String(data)));
}
} else if (on_body != null) {
ThreadContext context = on_body.getRuntime().getCurrentContext();
ret = on_body.callMethod(context, "call", on_body.getRuntime().newString(new String(data)));
}
if (ret == runtime.newSymbol("stop")) {
throw new StopException();