Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

.upgrade()

  • Loading branch information...
commit 538e5859f4f78a7e65b799a0e8b29f5553da6414 1 parent 68f4ae0
@substack substack authored
Showing with 38 additions and 4 deletions.
  1. +31 −0 index.js
  2. +5 −2 lib/modes.js
  3. +2 −2 package.json
View
31 index.js
@@ -29,4 +29,35 @@ Parser.prototype.execute = function (buf, start, len) {
}
};
+Parser.prototype.upgrade = function () {
+ var self = this;
+ if (self.request
+ && (self.mode === 'begin' || self.mode === 'method'
+ || self.mode === 'url' || self.mode === 'versionBegin'
+ || self.mode === 'version' || self.mode === 'headerField'
+ || self.mode === 'headerValue')) {
+
+ self.mode = 'upgrade';
+ self.request.emit('upgrade');
+ }
+ else if (self.request) {
+ self.request.once('headers', function () {
+ self.mode = 'upgrade';
+ self.request.emit('upgrade');
+ });
+ }
+ else {
+ var cb = self.cb;
+ self.cb = function () {
+ cb.apply(this, arguments);
+ self.upgrade();
+ };
+ }
+
+ var ended = false;
+ self.stream.on('end', function () {
+ if (self.request) self.request.emit('end');
+ });
+};
+
Parser.prototype.modes = require('./lib/modes');
View
7 lib/modes.js
@@ -219,7 +219,10 @@ exports.body = function (buf, start, len) {
var req = this.request;
var enc = req.headers['transfer-encoding'];
- if (req.method === 'POST' || req.method === 'PUT') {
+ if (this.mode === 'upgrade') {
+ /* ... */
+ }
+ else if (req.method === 'POST' || req.method === 'PUT') {
if (this._useChunkedEncoding) {
this.mode = 'chunk';
}
@@ -236,7 +239,7 @@ exports.body = function (buf, start, len) {
this.mode = 'upgrade';
}
else {
- req.emit('end')
+ if (!this._ended) req.emit('end')
this.mode = this._shouldKeepAlive ? 'begin' : 'finished';
}
View
4 package.json
@@ -1,7 +1,7 @@
{
"name" : "parsley",
"description" : "pure javascript http parser",
- "version" : "0.0.2",
+ "version" : "0.1.0",
"repository" : {
"type" : "git",
"url" : "git://github.com/substack/node-parsley.git"
@@ -21,7 +21,7 @@
},
"dependencies" : {},
"devDependencies" : {
- "tap" : "0.0.x",
+ "tap" : "0.1.x",
"chunky" : "0.0.x"
},
"engines" : {
Please sign in to comment.
Something went wrong with that request. Please try again.