Started utils.parseRange()
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent 9a89dab · Browse files · 3 files·+26 added−4 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+26 added−4 removed
- other:+26 added−4 removed
Provenance
- Commit
903f67a- Tree
628be9e- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
9a89dab
3 files changed+26 added−4 removed
modified:lib/express/response.js+5 added-1 removed
13 unmodified lines14 path = require('path'),15 pump = require('sys').pump,16 utils = require('connect/utils'),17 mime = require('connect/utils').mime,18+ parseRange = require('./utils').parseRange,19 Buffer = require('buffer').Buffer;20 21 /**22 * Header fields supporting multiple values.109 unmodified lines132 */133 134 http.ServerResponse.prototype.sendfile = function(path, fn){135 var self = this,135- streamThreshold = this.app.set('stream threshold') || 32 * 1024;136+ streamThreshold = this.app.set('stream threshold') || 32 * 1024,137+ ranges = self.req.headers.range;138 139 if (~path.indexOf('..')) this.send(403);140 141 function error(err) {4 unmodified lines146 self.req.next(err);147 }148 }149 150+ if (ranges) ranges = parseRange(ranges);151+152 fs.stat(path, function(err, stat){153 if (err) return error(err);154 if (stat.size >= streamThreshold) {155 var stream = fs.createReadStream(path);191 unmodified linesmodified:lib/express/utils.js+17 added-2 removed
14 unmodified lines151617181919202122236 unmodified lines30313233343435363738394041424344454647484950515253545556575814 unmodified lines * [A](B) becomes <a href="B">A</a> * * @param {String} str * @return {String} * @api public * @api private */
exports.miniMarkdown = function(str){ return String(str)6 unmodified lines * Escape special characters in the given string of html. * * @param {String} html * @return {String} * @api public * @api private */
exports.htmlEscape = function(html) { return String(html) .replace(/&/g, '&') .replace(/"/g, '"') .replace(/</g, '<') .replace(/>/g, '>');};
/** * Parse "Range" header `str`. * * @param {String} str * @return {Array} * @api private */
exports.parseRange = function(str){ return str.replace('bytes=', '').split(',').map(function(range){ range = range.split('-'); return { start: range[0], end: range[1] }; });};No newline at end of fileNo newline at end of filemodified:Makefile+4 added-1 removed
43 unmodified lines44 -I support/jade/lib \45 -I support/ejs/lib \46 $(TESTFLAGS) \47 test/*.test.js48+49 test-cov:50 @TESTFLAGS=--cov $(MAKE) test51 52 docs: docs/api.html $(MANPAGES) $(HTMLDOCS)53 @ echo "... generating TOC"54 @./support/toc.js docs/guide.html55 56 docs/api.html: lib/express/*.js57+ dox \58+ --private \56- dox --title Express \59+ --title Express \60 --desc "High performance web framework for [node](http://nodejs.org)." \61 $(shell find lib/express/* -type f) > $@62 63 %.1: %.md14 unmodified lines