Provide buffer in HTTPParser callbacks.

v0.7.4-release
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; \
\
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); \
if (!cb_value->IsFunction()) return 0; \
Local<Function> cb = Local<Function>::Cast(cb_value); \
\
Local<Integer> off = Integer::New(at - base); \
Local<Integer> len = Integer::New(length); \
Local<Value> argv[2] = { off, len }; \
\
Local<Value> ret = cb->Call(parser->handle_, 2, argv); \
Local<Value> argv[3] = { Local<Value>::New(root->handle) \
, Integer::New(at - base) \
, Integer::New(length) \
}; \
Local<Value> ret = cb->Call(parser->handle_, 3, argv); \
return ret.IsEmpty() ? -1 : 0; \
}

View File

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