Provide buffer in HTTPParser callbacks.

This commit is contained in:
Ryan Dahl 2010-01-24 14:12:15 -08:00
parent bffa18befc
commit dda1d681f7
2 changed files with 11 additions and 10 deletions

View File

@ -81,17 +81,18 @@ static Persistent<String> should_keep_alive_sym;
HandleScope scope; \ HandleScope scope; \
\ \
assert(parser->buffer_); \ assert(parser->buffer_); \
char * base = buffer_p(parser->buffer_, 0); \ struct buffer * root = buffer_root(parser->buffer_); \
char * base = buffer_p(root, 0); \
\ \
Local<Value> cb_value = parser->handle_->Get(name##_sym); \ Local<Value> cb_value = parser->handle_->Get(name##_sym); \
if (!cb_value->IsFunction()) return 0; \ if (!cb_value->IsFunction()) return 0; \
Local<Function> cb = Local<Function>::Cast(cb_value); \ Local<Function> cb = Local<Function>::Cast(cb_value); \
\ \
Local<Integer> off = Integer::New(at - base); \ Local<Value> argv[3] = { Local<Value>::New(root->handle) \
Local<Integer> len = Integer::New(length); \ , Integer::New(at - base) \
Local<Value> argv[2] = { off, len }; \ , Integer::New(length) \
\ }; \
Local<Value> ret = cb->Call(parser->handle_, 2, argv); \ Local<Value> ret = cb->Call(parser->handle_, 3, argv); \
return ret.IsEmpty() ? -1 : 0; \ return ret.IsEmpty() ? -1 : 0; \
} }

View File

@ -29,14 +29,14 @@ parser.onHeadersComplete = function (info) {
callbacks++; callbacks++;
}; };
parser.onURL = function (off, len) { parser.onURL = function (b, off, len) {
//throw new Error("hello world"); //throw new Error("hello world");
callbacks++; callbacks++;
}; };
parser.onPath = function (off, length) { parser.onPath = function (b, off, length) {
puts("path [" + off + ", " + length + "]"); puts("path [" + off + ", " + length + "]");
var path = buffer.asciiSlice(off, off+length); var path = b.asciiSlice(off, off+length);
puts("path = '" + path + "'"); puts("path = '" + path + "'");
assert.equal('/hello', path); assert.equal('/hello', path);
callbacks++; callbacks++;
@ -50,7 +50,7 @@ assert.equal(4, callbacks);
// thrown from parser.execute() // thrown from parser.execute()
// //
parser.onURL = function (off, len) { parser.onURL = function (b, off, len) {
throw new Error("hello world"); throw new Error("hello world");
}; };