mirror of https://github.com/nodejs/node.git
Provide buffer in HTTPParser callbacks.
parent
bffa18befc
commit
dda1d681f7
|
@ -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; \
|
||||
}
|
||||
|
||||
|
|
|
@ -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");
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue