using v8::String;
using v8::Value;
-static Cached<String> on_headers_sym;
-static Cached<String> on_headers_complete_sym;
-static Cached<String> on_body_sym;
-static Cached<String> on_message_complete_sym;
+const uint32_t kOnHeaders = 0;
+const uint32_t kOnHeadersComplete = 1;
+const uint32_t kOnBody = 2;
+const uint32_t kOnMessageComplete = 3;
static Cached<String> method_sym;
static Cached<String> status_code_sym;
HTTP_CB(on_headers_complete) {
Local<Object> obj = handle(node_isolate);
- Local<Value> cb = obj->Get(on_headers_complete_sym);
+ Local<Value> cb = obj->Get(kOnHeadersComplete);
if (!cb->IsFunction())
return 0;
HandleScope scope(node_isolate);
Local<Object> obj = handle(node_isolate);
- Local<Value> cb = obj->Get(on_body_sym);
+ Local<Value> cb = obj->Get(kOnBody);
if (!cb->IsFunction())
return 0;
Flush(); // Flush trailing HTTP headers.
Local<Object> obj = handle(node_isolate);
- Local<Value> cb = obj->Get(on_message_complete_sym);
+ Local<Value> cb = obj->Get(kOnMessageComplete);
if (!cb->IsFunction())
return 0;
HandleScope scope(node_isolate);
Local<Object> obj = handle(node_isolate);
- Local<Value> cb = obj->Get(on_headers_sym);
+ Local<Value> cb = obj->Get(kOnHeaders);
if (!cb->IsFunction())
return;
Integer::New(HTTP_REQUEST, node_isolate));
t->Set(FIXED_ONE_BYTE_STRING(node_isolate, "RESPONSE"),
Integer::New(HTTP_RESPONSE, node_isolate));
+ t->Set(FIXED_ONE_BYTE_STRING(node_isolate, "kOnHeaders"),
+ Integer::NewFromUnsigned(kOnHeaders, node_isolate));
+ t->Set(FIXED_ONE_BYTE_STRING(node_isolate, "kOnHeadersComplete"),
+ Integer::NewFromUnsigned(kOnHeadersComplete, node_isolate));
+ t->Set(FIXED_ONE_BYTE_STRING(node_isolate, "kOnBody"),
+ Integer::NewFromUnsigned(kOnBody, node_isolate));
+ t->Set(FIXED_ONE_BYTE_STRING(node_isolate, "kOnMessageComplete"),
+ Integer::NewFromUnsigned(kOnMessageComplete, node_isolate));
NODE_SET_PROTOTYPE_METHOD(t, "execute", Parser::Execute);
NODE_SET_PROTOTYPE_METHOD(t, "finish", Parser::Finish);
target->Set(FIXED_ONE_BYTE_STRING(node_isolate, "HTTPParser"),
t->GetFunction());
- on_headers_sym =
- FIXED_ONE_BYTE_STRING(node_isolate, "onHeaders");
- on_headers_complete_sym =
- FIXED_ONE_BYTE_STRING(node_isolate, "onHeadersComplete");
- on_body_sym =
- FIXED_ONE_BYTE_STRING(node_isolate, "onBody");
- on_message_complete_sym =
- FIXED_ONE_BYTE_STRING(node_isolate, "onMessageComplete");
-
#define X(num, name, string) \
name ## _sym = OneByteString(node_isolate, #string);
HTTP_METHOD_MAP(X)
var REQUEST = HTTPParser.REQUEST;
var RESPONSE = HTTPParser.RESPONSE;
+var kOnHeaders = HTTPParser.kOnHeaders | 0;
+var kOnHeadersComplete = HTTPParser.kOnHeadersComplete | 0;
+var kOnBody = HTTPParser.kOnBody | 0;
+var kOnMessageComplete = HTTPParser.kOnMessageComplete | 0;
+
// The purpose of this test is not to check HTTP compliance but to test the
// binding. Tests for pathological http messages should be submitted
// upstream to https://github.com/joyent/http-parser for inclusion into
parser.headers = [];
parser.url = '';
- parser.onHeaders = function(headers, url) {
+ parser[kOnHeaders] = function(headers, url) {
parser.headers = parser.headers.concat(headers);
parser.url += url;
};
- parser.onHeadersComplete = function(info) {
+ parser[kOnHeadersComplete] = function(info) {
};
- parser.onBody = function(b, start, len) {
+ parser[kOnBody] = function(b, start, len) {
assert.ok(false, 'Function should not be called.');
};
- parser.onMessageComplete = function() {
+ parser[kOnMessageComplete] = function() {
};
return parser;
var parser = newParser(REQUEST);
- parser.onHeadersComplete = mustCall(function(info) {
+ parser[kOnHeadersComplete] = mustCall(function(info) {
assert.equal(info.method, 'GET');
assert.equal(info.url || parser.url, '/hello');
assert.equal(info.versionMajor, 1);
// thrown from parser.execute()
//
- parser.onHeadersComplete = function(info) {
+ parser[kOnHeadersComplete] = function(info) {
throw new Error('hello world');
};
var parser = newParser(RESPONSE);
- parser.onHeadersComplete = mustCall(function(info) {
+ parser[kOnHeadersComplete] = mustCall(function(info) {
assert.equal(info.method, undefined);
assert.equal(info.versionMajor, 1);
assert.equal(info.versionMinor, 1);
assert.equal(info.statusCode, 200);
});
- parser.onBody = mustCall(function(buf, start, len) {
+ parser[kOnBody] = mustCall(function(buf, start, len) {
var body = '' + buf.slice(start, start + len);
assert.equal(body, 'pong');
});
var parser = newParser(RESPONSE);
- parser.onHeadersComplete = mustCall(function(info) {
+ parser[kOnHeadersComplete] = mustCall(function(info) {
assert.equal(info.method, undefined);
assert.equal(info.versionMajor, 1);
assert.equal(info.versionMinor, 0);
var parser = newParser(REQUEST);
- parser.onHeadersComplete = mustCall(function(info) {
+ parser[kOnHeadersComplete] = mustCall(function(info) {
assert.equal(info.method, 'POST');
assert.equal(info.url || parser.url, '/it');
assert.equal(info.versionMajor, 1);
assert.equal(info.versionMinor, 1);
// expect to see trailing headers now
- parser.onHeaders = mustCall(onHeaders);
+ parser[kOnHeaders] = mustCall(onHeaders);
});
- parser.onBody = mustCall(function(buf, start, len) {
+ parser[kOnBody] = mustCall(function(buf, start, len) {
var body = '' + buf.slice(start, start + len);
assert.equal(body, 'ping');
seen_body = true;
var parser = newParser(REQUEST);
- parser.onHeadersComplete = mustCall(function(info) {
+ parser[kOnHeadersComplete] = mustCall(function(info) {
assert.equal(info.method, 'GET');
assert.equal(info.versionMajor, 1);
assert.equal(info.versionMinor, 0);
var parser = newParser(REQUEST);
- parser.onHeadersComplete = mustCall(function(info) {
+ parser[kOnHeadersComplete] = mustCall(function(info) {
assert.equal(info.method, 'GET');
assert.equal(info.url || parser.url, '/foo/bar/baz?quux=42#1337');
assert.equal(info.versionMajor, 1);
var parser = newParser(REQUEST);
- parser.onHeadersComplete = mustCall(function(info) {
+ parser[kOnHeadersComplete] = mustCall(function(info) {
assert.equal(info.method, 'POST');
assert.equal(info.url || parser.url, '/it');
assert.equal(info.versionMajor, 1);
assert.equal(info.versionMinor, 1);
});
- parser.onBody = mustCall(function(buf, start, len) {
+ parser[kOnBody] = mustCall(function(buf, start, len) {
var body = '' + buf.slice(start, start + len);
assert.equal(body, 'foo=42&bar=1337');
});
var parser = newParser(REQUEST);
- parser.onHeadersComplete = mustCall(function(info) {
+ parser[kOnHeadersComplete] = mustCall(function(info) {
assert.equal(info.method, 'POST');
assert.equal(info.url || parser.url, '/it');
assert.equal(info.versionMajor, 1);
assert.equal(body, body_parts[body_part++]);
}
- parser.onBody = mustCall(onBody, body_parts.length);
+ parser[kOnBody] = mustCall(onBody, body_parts.length);
parser.execute(request, 0, request.length);
})();
var parser = newParser(REQUEST);
- parser.onHeadersComplete = mustCall(function(info) {
+ parser[kOnHeadersComplete] = mustCall(function(info) {
assert.equal(info.method, 'POST');
assert.equal(info.url || parser.url, '/it');
assert.equal(info.versionMajor, 1);
assert.equal(body, body_parts[body_part++]);
}
- parser.onBody = mustCall(onBody, body_parts.length);
+ parser[kOnBody] = mustCall(onBody, body_parts.length);
parser.execute(request, 0, request.length);
request = Buffer(
function test(a, b) {
var parser = newParser(REQUEST);
- parser.onHeadersComplete = mustCall(function(info) {
+ parser[kOnHeadersComplete] = mustCall(function(info) {
assert.equal(info.method, 'POST');
assert.equal(info.url || parser.url, '/helpme');
assert.equal(info.versionMajor, 1);
var expected_body = '123123456123456789123456789ABC123456789ABCDEF';
- parser.onBody = function(buf, start, len) {
+ parser[kOnBody] = function(buf, start, len) {
var chunk = '' + buf.slice(start, start + len);
assert.equal(expected_body.indexOf(chunk), 0);
expected_body = expected_body.slice(chunk.length);
var parser = newParser(REQUEST);
- parser.onHeadersComplete = mustCall(function(info) {
+ parser[kOnHeadersComplete] = mustCall(function(info) {
assert.equal(info.method, 'POST');
assert.equal(info.url || parser.url, '/it');
assert.equal(info.versionMajor, 1);
var expected_body = '123123456123456789123456789ABC123456789ABCDEF';
- parser.onBody = function(buf, start, len) {
+ parser[kOnBody] = function(buf, start, len) {
var chunk = '' + buf.slice(start, start + len);
assert.equal(expected_body.indexOf(chunk), 0);
expected_body = expected_body.slice(chunk.length);
};
var parser = newParser(REQUEST);
- parser.onHeadersComplete = onHeadersComplete1;
- parser.onBody = expectBody('ping');
+ parser[kOnHeadersComplete] = onHeadersComplete1;
+ parser[kOnBody] = expectBody('ping');
parser.execute(req1, 0, req1.length);
parser.reinitialize(REQUEST);
- parser.onBody = expectBody('pong');
- parser.onHeadersComplete = onHeadersComplete2;
+ parser[kOnBody] = expectBody('pong');
+ parser[kOnHeadersComplete] = onHeadersComplete2;
parser.execute(req2, 0, req2.length);
})();