Skip to content

Commit

Permalink
protect payload stream from replay. Closes hapijs#1252
Browse files Browse the repository at this point in the history
  • Loading branch information
Eran Hammer committed Dec 21, 2013
1 parent 2c301d0 commit b1e5d27
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/response/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ internals.File.prototype._prepare = function (request, callback) {

var fileName = Path.basename(filePath);

self.bytes(stat.size);
self._headers['content-type'] = Mime.lookup(filePath) || 'application/octet-stream';
self._headers['content-length'] = stat.size;
self._headers['last-modified'] = stat.mtime;

// Use stat info for an LRU cache key.
Expand Down
12 changes: 9 additions & 3 deletions lib/response/payload.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,22 @@ exports = module.exports = internals.Payload = function (payload) {
this._prefix = null;
this._suffix = null;
this._sizeOffset = 0;
this._played = false;
};

Utils.inherits(internals.Payload, Stream.Readable);


internals.Payload.prototype._read = function (size) {

this._prefix && this.push(this._prefix);
this.push(this._data);
this._suffix && this.push(this._suffix);
if (!this._played) {
this._played = true;

this._prefix && this.push(this._prefix);
this.push(this._data);
this._suffix && this.push(this._suffix);
}

this.push(null);
};

Expand Down

0 comments on commit b1e5d27

Please sign in to comment.