Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Started utils.parseRange()

  • Loading branch information...
commit 903f67a154e5ee72b815606b027ac951c9da7755 1 parent 9a89dab
@tj tj authored
Showing with 26 additions and 4 deletions.
  1. +4 −1 Makefile
  2. +5 −1 lib/express/response.js
  3. +17 −2 lib/express/utils.js
View
5 Makefile
@@ -45,6 +45,7 @@ test:
-I support/ejs/lib \
$(TESTFLAGS) \
test/*.test.js
+
test-cov:
@TESTFLAGS=--cov $(MAKE) test
@@ -53,7 +54,9 @@ docs: docs/api.html $(MANPAGES) $(HTMLDOCS)
@./support/toc.js docs/guide.html
docs/api.html: lib/express/*.js
- dox --title Express \
+ dox \
+ --private \
+ --title Express \
--desc "High performance web framework for [node](http://nodejs.org)." \
$(shell find lib/express/* -type f) > $@
View
6 lib/express/response.js
@@ -15,6 +15,7 @@ var fs = require('fs'),
pump = require('sys').pump,
utils = require('connect/utils'),
mime = require('connect/utils').mime,
+ parseRange = require('./utils').parseRange,
Buffer = require('buffer').Buffer;
/**
@@ -132,7 +133,8 @@ http.ServerResponse.prototype.send = function(body, headers, status){
http.ServerResponse.prototype.sendfile = function(path, fn){
var self = this,
- streamThreshold = this.app.set('stream threshold') || 32 * 1024;
+ streamThreshold = this.app.set('stream threshold') || 32 * 1024,
+ ranges = self.req.headers.range;
if (~path.indexOf('..')) this.send(403);
@@ -145,6 +147,8 @@ http.ServerResponse.prototype.sendfile = function(path, fn){
}
}
+ if (ranges) ranges = parseRange(ranges);
+
fs.stat(path, function(err, stat){
if (err) return error(err);
if (stat.size >= streamThreshold) {
View
19 lib/express/utils.js
@@ -16,7 +16,7 @@
*
* @param {String} str
* @return {String}
- * @api public
+ * @api private
*/
exports.miniMarkdown = function(str){
@@ -31,7 +31,7 @@ exports.miniMarkdown = function(str){
*
* @param {String} html
* @return {String}
- * @api public
+ * @api private
*/
exports.htmlEscape = function(html) {
@@ -40,4 +40,19 @@ exports.htmlEscape = function(html) {
.replace(/"/g, '"')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
+};
+
+/**
+ * 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] };
+ });
};
Please sign in to comment.
Something went wrong with that request. Please try again.