Skip to content
Myr

Removed old cruft

Before adoption: this commit came in with the history the project adopted, so no landing records it.

wow express is light now! haha.. go connect go

authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent 3043d1e · Browse files · 25 files+1 added−3054 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

25 files+1 added−3054 removed

  • other:+1 added−3054 removed

25 files+1 added−3054 removed

modified:examples/hello-world/app.js+1 added-1 removed
deleted:lib/express/pages/not-found.js-30 removed
deleted:lib/express/pages/show-exceptions.js-138 removed
12// Express - Pages - Show Exceptions - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)34/**5 * Module dependencies.6 */78var sys = require('sys'),9 style = require('./style').style10 1112/**13 * Return list items for exception _e_'s stack.14 *15 * @param {Error} e16 * @return {string}17 * @api private18 */1920function stack(e) {21 if (e.stack)22 return e.stack.split('\n').slice(1).map(function(val, i){23 if (!i)24 return '<li>' + val.replace(/^(.*?):/, '<span class="path">$1</span>:') + '</li>'25 return '<li>' + val26 .replace(/\(([^:]+)/, '(<span class="path">$1</span>')27 .replace(/(:\d+:\d+)/, '<span class="line">$1</span>') + 28 '</li>'29 }).join('\n')30}3132/**33 * Return table rows for _hash_.34 *35 * @param {object} hash36 * @return {string}37 * @api private38 */3940function hash(hash) {41 var keys = Object.keys(hash),42 buf = []43 if (!keys.length) return '<tr><td class="empty" colspan="2">Empty</td></tr>'44 for (var i = 0, len = keys.length; i < len; ++i)45 buf.push('<tr><td>' + keys[i] + ':</td><td>' + sys.inspect(hash[keys[i]]) + '</td></tr>')46 return buf.join('\n')47}4849/**50 * Return plain-text list items for exception _e_'s stack.51 *52 * @param {Error} e53 * @return {string}54 * @api private55 */5657function stackText(e) {58 if (e.stack)59 return e.stack.split('\n').slice(1).map(function(val, i){60 return '\n ' + val.strip61 }).join('')62}6364/**65 * Return an ascii table for _hash_.66 *67 * @param {object} hash68 * @return {string}69 * @api private70 */7172function hashText(hash) {73 var keys = Object.keys(hash),74 buf = ''75 if (!keys.length) return '\n Empty'76 for (var i = 0, len = keys.length; i < len; ++i)77 buf += '\n ' + keys[i] + ': ' + sys.inspect(hash[keys[i]])78 return buf79}8081exports.render = function(request, e) {82 request.charset = 'UTF-8'83 request.contentType('html')84 return '<html> \n\85 <head> \n\86 <title>Express -- ' + e + '</title> \n\87 ' + style + ' \n\88 </head> \n\89 <body> \n\90 <div id="wrapper"> \n\91   <h1>Express</h1> \n\92   <h2><em>500</em> ' + e + '</h2> \n\93   <ul id="stacktrace"> \n\94   ' + stack(e) + ' \n\95   </ul> \n\96 <h3>Request</h3> \n\97 <table id="request-headers"> \n\98 ' + hash(request.headers) + ' \n\99 </table> \n\100 <h3>Response</h3> \n\101 <table id="response-headers"> \n\102 ' + hash(request.response.headers) + ' \n\103 </table> \n\104 <h3>Params</h3> \n\105 <table id="route-params"> \n\106 ' + hash(request.params.path) + ' \n\107 </table> \n\108 <h3>GET</h3> \n\109 <table id="get-params"> \n\110 ' + hash(request.params.get) + ' \n\111 </table> \n\112 <h3>POST</h3> \n\113 <table id="post-params"> \n\114 ' + hash(request.params.post) + ' \n\115 </table> \n\116 </div> \n\117 </body> \n\118 </html>'119}120121exports.renderText = function(request, e) {122 request.contentType('text')123 return '\124 \n Express \125 \n\n 500 ' + e + ' \126 \n' + stackText(e) + ' \127 \n\n Request\n ' + hashText(request.headers) + '\128 \n\n Response\n ' + hashText(request.response.headers) + '\129 \n\n Params\n ' + hashText(request.params.path) + '\130 \n\n GET\n ' + hashText(request.params.get) + '\131 \n\n POST\n ' + hashText(request.params.post) + '\n'132}133134exports.renderJSON = function(request, e) {135 request.contentType('json')136 delete e.stack137 return JSON.encode({ error: e })138}
deleted:lib/express/pages/style.js-99 removed
12// Express - Pages - Style - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)34exports.style = '<style> \n\5 body { \n\6 font-family: "Helvetica Neue", "Lucida Grande", "Arial"; \n\7 font-size: 13px; \n\8 text-align: center; \n\9 background: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#fff), to(#ECE9E9)); \n\10 color: #555; \n\11 -webkit-text-stroke: 1px rgba(255, 255, 255, 0.1); \n\12 } \n\13 h1, h2, h3 { \n\14 margin: 0; \n\15 font-size: 22px; \n\16 color: #343434; \n\17 } \n\18 h1 em, h2 em { \n\19 padding: 0 5px; \n\20 font-weight: normal; \n\21 } \n\22 h1 { \n\23 text-shadow: 1px 2px 2px #ddd; \n\24 font-size: 60px; \n\25 } \n\26 h3 { \n\27 margin: 5px 0 10px 0; \n\28 padding-bottom: 5px; \n\29 border-bottom: 1px solid #eee; \n\30 font-size: 18px; \n\31 } \n\32 #wrapper { \n\33 margin: 50px auto; \n\34 width: 750px; \n\35 text-align: left; \n\36 } \n\37 ul { \n\38 margin: 0; \n\39 padding: 0; \n\40 } \n\41 ul li { \n\42 margin: 5px 0; \n\43 padding: 3px 8px; \n\44 list-style: none; \n\45 border: 1px solid #eee; \n\46 -webkit-border-radius: 3px; \n\47 -mox-border-radius: 3px; \n\48 -webkit-transition-property: color, padding; \n\49 -webkit-transition-duration: 0.1s; \n\50 } \n\51 ul li:hover { \n\52 padding: 3px 20px; \n\53 cursor: pointer; \n\54 color: #2E2E2E; \n\55 } \n\56 ul li .path { \n\57 padding-left: 5px; \n\58 font-weight: bold; \n\59 } \n\60 ul li .line { \n\61 padding-right: 5px; \n\62 font-style: italic; \n\63 } \n\64 ul li:first-child .path { \n\65 padding-left: 0; \n\66 } \n\67 p { \n\68 line-height: 1.5; \n\69 } \n\70 pre { \n\71 margin: 0; \n\72 padding: 10px; \n\73 border: 1px solid #eee; \n\74 -webkit-border-radius: 10px; \n\75 -moz-border-radius: 10px; \n\76 -webkit-box-shadow: 1px 1px 6px #ddd; \n\77 -moz-box-shadow: 1px 1px 6px #ddd; \n\78 } \n\79 table { \n\80 margin-bottom: 35px; \n\81 width: 100%; \n\82 border-collapse: collapse; \n\83 } \n\84 table td { \n\85 padding: 5px 10px; \n\86 font-size: 14px; \n\87 } \n\88 table tr { \n\89 border-bottom: 1px solid #fff; \n\90 } \n\91 table tr:last-child { \n\92 border-bottom: none; \n\93 } \n\94 table td:first-child { \n\95 width: 150px; \n\96 color: #343434; \n\97 } \n\98 </style> \n\99 '
deleted:lib/express/plugins/body-decoder.js-28 removed
deleted:lib/express/plugins/cache.js-234 removed
12// Express - Cache - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)34/**5 * Module dependencies.6 */7 8var Request = require('./../request').Request910// --- Cache1112var Cache = new Class({13 14 /**15 * Initialize cache with _key_ and _val_.16 */17 18 constructor: function(key, val) {19 this.key = key20 this.val = val21 this.created = Date.now()22 }23})2425// --- Store2627exports.Store = new Class({28 29 /**30 * Ensure that the given _key_ is a string.31 * Override in subclass to provide data-store specific functionality.32 *33 * @param {string} key34 * @param {string} val35 * @param {function} callback36 * @api public37 */38 39 set: function(key, val, callback) {40 if (typeof key !== 'string')41 throw new Error(this.name + ' store #set() key must be a string')42 },43 44 /**45 * Ensure that the given _key_ is a string.46 * Override in subclass to provide data-store specific functionality.47 *48 * @param {string} key49 * @param {function} callback50 * @api public51 */52 53 get: function(key, callback) {54 if (typeof key !== 'string')55 throw new Error(this.name + 'store #get() key must be a string')56 },57 58 /**59 * Convert to '[NAME Store]'.60 *61 * @return {string}62 * @api public63 */64 65 toString: function() {66 return '[' + this.name + ' Store]'67 }68})6970// --- Store.Memory7172exports.Store.Memory = exports.Store.extend({73 74 /**75 * Datastore name.76 */77 78 name: 'Memory',79 80 /**81 * Initialize data.82 */83 84 constructor: function() {85 this.data = {}86 },87 88 /**89 * Set the given _key_ to _val_.90 *91 * @param {string} key92 * @param {string} val93 * @param {function} callback94 * @return {string}95 * @api public96 */97 98 set: function(key, val, callback) {99 exports.Store.prototype.set.apply(this, arguments)100 this.data[key] = new Cache(key, val)101 if (callback) callback(val)102 },103 104 /**105 * Get data found matching the given _key_.106 *107 * Examples:108 *109 * cache.get('page:front', function(val){})110 * // => '<html>...</html>'111 *112 * cache.get('page:*', function(vals){})113 * // => { 'page:front': '<html>...</html>', 114 * 'page:users': '<html>...</html>',115 * ... }116 *117 * @param {string} key118 * @param {function} callback119 * @return {mixed}120 * @api public121 */122 123 get: function(key, callback) {124 exports.Store.prototype.get.apply(this, arguments)125 if (key.indexOf('*') === -1)126 return callback(this.data[key] instanceof Cache127 ? this.data[key].val128 : null)129 var regexp = this.normalize(key),130 keys = Object.keys(this.data),131 matches = {}132 for (var i = 0, len = keys.length; i < len; ++i)133 if (regexp.test(keys[i]))134 matches[keys[i]] = this.data[keys[i]].val135 callback(matches)136 },137 138 /**139 * Clear data matching the given _key_.140 *141 * Examples:142 *143 * cache.clear('page:front', function(){})144 * cache.clear('page:*', function(){})145 *146 * @param {string} key147 * @param {function} callback148 * @api public149 */150 151 clear: function(key, callback) {152 if (key.indexOf('*') === -1)153 delete this.data[key]154 else {155 var regexp = this.normalize(key),156 keys = Object.keys(this.data)157 for (var i = 0, len = keys.length; i < len; ++i)158 if (regexp.test(keys[i]))159 delete this.data[keys[i]]160 }161 callback()162 },163 164 /**165 * Reap caches older than _ms_ or caches which166 * have been "cleared" (null).167 *168 * @param {int} ms169 * @api private170 */171 172 reap: function(ms) {173 var threshold = +new Date(Date.now() - ms),174 keys = Object.keys(this.data)175 for (var i = 0, len = keys.length; i < len; ++i)176 if (this.data[keys[i]].created < threshold ||177 this.data[keys[i]].val === null)178 this.clear(keys[i], function(){})179 },180 181 /**182 * Convert the given key matching _pattern_ 183 * into a RegExp.184 *185 * - * is converted to (.*?)186 *187 * @param {string} pattern188 * @return {regexp}189 * @api private190 */191 192 normalize: function(pattern) {193 return new RegExp('^' + pattern.replace(/[*]/g, '(.*?)') + '$')194 }195})196197// --- Cache198199exports.Cache = Plugin.extend({200 extend: {201 202 /**203 * Initialize memory store and start reaper.204 *205 * Options:206 *207 * - dataStore constructor name of cache data store, defaults to Store.Memory208 * - lifetime lifetime of cache in milliseconds, defaults to one day209 * - reapInterval, reapEvery interval in milliseconds in which to reap old caches, defaults to one hour210 * 211 * @param {hash} options212 * @api private213 */214 215 init: function(options) {216 Object.merge(this, options)217 this.store = new (this.dataStore || exports.Store.Memory)(options)218 Request.include({ cache: this.store })219 this.startReaper()220 },221 222 /**223 * Start reaper.224 *225 * @api private226 */227 228 startReaper: function() {229 setInterval(function(self){230 self.store.reap(self.lifetime || (1).day)231 }, this.reapInterval || this.reapEvery || (1).hour, this)232 }233 }234})
deleted:lib/express/plugins/content-length.js-18 removed
deleted:lib/express/plugins/cookie.js-134 removed
12// Express - Cookie - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)34/**5 * Module dependencies.6 */7 8var Request = require('./../request').Request,9 queryString = require('querystring')1011/**12 * Parse an HTTP _cookie_ string into a hash.13 *14 * @param {string} cookie15 * @return {hash}16 * @api public17 */1819exports.parseCookie = function(cookie) {20 return cookie.split(/[;,] */).reduce(function(cookies, pair) {21 var eql = pair.indexOf('=')22 if (eql === -1) return cookies23 var key = queryString.unescape(pair.slice(0, eql).trim(), true)24 var val = queryString.unescape(pair.slice(eql + 1).trim(), true)25 var captures = val.match(/^("|')([^\1]*)\1$/)26 if (captures) val = captures[2].replace('\\' + captures[1], captures[1])27 //RFC2109 states the most specific path will be28 //listed first29 if (cookies[key] === undefined)30 cookies[key] = val31 return cookies32 }, {})33}3435/**36 * Compile cookie _name_, _val_ and _options_ to a string.37 *38 * @param {string} name39 * @param {string} val40 * @param {hash} options41 * @return {string}42 * @api public43 */4445exports.compileCookie = function(name, val, options) {46 if (!options) return name + '=' + val47 var val,48 buf = [queryString.escape(name) + '=' + queryString.escape(val)],49 keys = Object.keys(options)50 for (var i = 0, len = keys.length; i < len; ++i) {51 val = options[keys[i]]52 if (val instanceof Date)53 val = val.toGMTString()54 buf.push(val === true 55 ? keys[i]56 : keys[i] + '=' + val)57 }58 return buf.join('; ')59}6061// --- Cookie6263exports.Cookie = Plugin.extend({64 extend: {65 66 /**67 * Initialize extensions.68 */69 70 init: function() {71 Request.include({7273 /**74 * Get or set cookie values. To delete a cookie75 * simply pass a null _val_.76 *77 * Options:78 *79 * - path Cookie path, defaults to '/'80 * - domain Tail matched domain name such as 'vision-media.ca' or 'blog.vision-media.ca' etc81 * - expires Date object converted to 'Wdy, DD-Mon-YYYY HH:MM:SS GMT'82 * when undefined the cookie will last the duration of a the83 * client's session.84 * - secure When true the cookie will be sent by the client only when transfering data via HTTPS85 * - httpOnly When true the cookie will be sent to the server only and will not be accessable via86 * client-side scripting.87 *88 * @param {string} name89 * @param {string} val90 * @param {hash} options91 * @return {string}92 * @api public93 */9495 cookie: function(name, val, options) {96 options = options || {}97 options.path = options.path || '/'98 if (null === val)99 val = "delete",100 options.expires = new Date(10000000)101 return val102 ? this.response.cookies.push(exports.compileCookie(name, val, options))103 : this.cookies[name]104 }105 })106 }107 },108 109 // --- Events110 111 on: {112 113 /**114 * Parse request cookie data.115 */116 117 request: function(event) {118 event.request.response.cookies = []119 event.request.cookies = event.request.headers.cookie120 ? exports.parseCookie(event.request.headers.cookie)121 : {}122 },123 124 /**125 * Set the Set-Cookie header when response cookies are available.126 */127 128 response: function(event) {129 if (event.response.cookies && 130 event.response.cookies.length)131 event.request.header('Set-Cookie', event.response.cookies.join('\r\nSet-Cookie: '))132 }133 }134})
deleted:lib/express/plugins/flash.js-67 removed
deleted:lib/express/plugins/hooks.js-73 removed
deleted:lib/express/plugins/logger.js-83 removed
12// Express - Logger - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)34/**5 * Module dependencies.6 */7 8var sys = require('sys'),9 printf = require('ext').printf1011/**12 * Log formats13 */14 15var formats = {16 common: function(event, start) {17 printf('%s - - [%s] "%s %s HTTP/%d.%d" %s %d %0.4f',18 event.request.socket.remoteAddress,19 (new Date).format('%d/%b/%Y %H:%M:%S'),20 event.request.method.uppercase,21 event.request.url.pathname || '/',22 event.request.httpVersionMajor,23 event.request.httpVersionMinor,24 event.request.response.status,25 event.request.response.headers['Content-Length'] || 0,26 (Date.now() - start) / 1000)27 },28 combined: function(event, start) {29 formats.common(event, start)30 printf(' "%s" "%s"', 31 event.request.headers['referrer'] || event.request.headers['referer'] || '-',32 event.request.headers['user-agent'])33 },34 plot: function(event, start) {35 sys.print(Date.now() - start)36 }37}3839// --- Logger4041exports.Logger = Plugin.extend({ 42 extend: {43 44 /**45 * Initialize logger options.46 *47 * Options:48 *49 * - format50 * 'common' outputs log in CommonLog format (DEFAULT)51 * 'combined' outputs log in Apache Combined format52 * 'request' outputs the HTTP request for debugging53 * 'plot' outputs request duration in milliseconds only54 *55 * @param {hash} options56 * @api private57 */5859 init: function(options) {60 Object.merge(this, options)61 }62 },63 64 on: {65 66 /**67 * Start timer.68 */69 70 request: function(event) {71 this.start = Date.now()72 },73 74 /**75 * Output log data.76 */77 78 response: function(event) {79 formats[exports.Logger.format || 'common'](event, this.start || Date.now())80 sys.print('\n')81 }82 }83})
deleted:lib/express/plugins/method-override.js-16 removed
deleted:lib/express/plugins/redirect.js-65 removed
deleted:lib/express/plugins/session.js-233 removed
12// Express - Session - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)34/**5 * Module dependencies.6 */7 8var Request = require('./../request').Request,9 utils = require('./../utils')1011// --- Session1213exports.Base = new Class({14 15 /**16 * Initialize session _sid_.17 */18 19 constructor: function(sid) {20 this.id = sid21 this.touch()22 },23 24 /**25 * Update last access time.26 *27 * @api private28 */29 30 touch: function() {31 this.lastAccess = Date.now()32 }33})3435// --- Store3637exports.Store = new Class({38 39 /**40 * Convert to '[NAME Store]'.41 *42 * @return {string}43 * @api public44 */45 46 toString: function() {47 return '[' + this.name + ' Store]'48 }49})5051// --- Store.Memory5253exports.Store.Memory = exports.Store.extend({54 55 /**56 * Datastore name.57 */58 59 name: 'Memory',60 61 /**62 * Initialize in-memory session store.63 */64 65 constructor: function() {66 this.store = {}67 },68 69 /**70 * Fetch session with the given _sid_ or 71 * a new Session is created.72 *73 * @param {number} sid74 * @param {function} callback75 * @api private76 */77 78 fetch: function(sid, callback) {79 if (sid && this.store[sid])80 callback(null, this.store[sid])81 else82 this.generate(callback)83 },84 85 /**86 * Commit _session_ data.87 *88 * @param {Session} session89 * @param {function} callback90 * @api private91 */92 93 commit: function(session, callback) {94 this.store[session.id] = session 95 if (callback) callback(null, session)96 },97 98 /**99 * Clear all sessions.100 *101 * @param {function} callback102 * @api public103 */104 105 clear: function(callback) {106 this.store = {}107 if (callback) callback()108 },109 110 /**111 * Destroy session using the given _sid_.112 *113 * @param {int} sid114 * @param {function} callback115 * @api public116 */117 118 destroy: function(sid, callback) {119 delete this.store[sid]120 if (callback) callback(sid)121 },122 123 /**124 * Pass the number of sessions currently stored.125 *126 * @param {function} callback127 * @api public128 */129 130 length: function(callback) {131 callback(null, Object.keys(this.store).length)132 },133 134 /**135 * Reap sessions older than _ms_.136 *137 * @param {int} ms138 * @api private139 */140 141 reap: function(ms) {142 var threshold = +new Date(Date.now() - ms),143 sids = Object.keys(this.store)144 for (var i = 0, len = sids.length; i < len; ++i)145 if (this.store[sids[i]].lastAccess < threshold)146 this.destroy(sids[i])147 },148149 /**150 * Creates and passes a shiny new session.151 *152 * @param {function} callback153 * @api public154 */155 156 generate: function(callback) {157 callback(null, new exports.Base(utils.uid()))158 }159})160161// --- Session162163exports.Session = Plugin.extend({164 extend: {165 166 /**167 * Initialize memory store and start reaper.168 *169 * Options:170 *171 * - dataStore   constructor name of session data store, defaults to Store.Memory172 * - lifetime lifetime of session in milliseconds, defaults to one day173 * - reapInterval, reapEvery interval in milliseconds in which to reap old sessions, defaults to one hour174 * - cookie session specific cookie options passed to Request#cookie()175 * 176 * @param {hash} options177 * @api private178 */179 180 init: function(options) {181 this.cookie = {}182 Object.merge(this, options)183 this.cookie.httpOnly = true184 this.store = new (this.dataStore || exports.Store.Memory)(options)185 this.startReaper()186 },187 188 /**189 * Start reaper.190 *191 * @api private192 */193 194 startReaper: function() {195 setInterval(function(self) {196 self.store.reap(self.lifetime || (1).day) 197 }, this.reapInterval || this.reapEvery || (1).hour, this)198 }199 },200 201 // --- Events202 203 on: {204 205 /**206 * Create session id when not found; delegate to store.207 */208 209 request: function(event, callback) {210 var sid = event.request.cookie('sid')211 if (!sid && event.request.url.pathname === '/favicon.ico') return212 exports.Session.store.fetch(sid, function(err, session) {213 if (err) return callback(err)214 if (session.id != sid) 215 event.request.cookie('sid', session.id, exports.Session.cookie)216 event.request.session = session217 event.request.session.touch()218 callback()219 })220 return true221 },222 223 /**224 * Delegate to store, allowing it to save sessions changes.225 */226 227 response: function(event, callback) {228 if (event.request.session)229 return exports.Session.store.commit(event.request.session, callback),230 true231 }232 }233})
deleted:lib/express/plugins/static.js-106 removed
12// Express - Static - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)34/**5 * Module dependencies.6 */78var Request = require('./../request').Request,9 path = require('path'),10 fs = require('fs')11 12// --- Static1314exports.Static = Plugin.extend({15 extend: {16 17 /**18 * Initialize routes and request extensions.19 *20 * Options:21 *22 * - path path from which to serve static files. Defaults to <root>/public23 * - bufferSize buffers size to use for streaming files. Defaults to 65536 (8kb)24 * 25 * @param {hash} options26 * @api private27 */28 29 init: function(config) {30 config = config || {}31 config.path = config.path || set('root') + '/public'32 33 // Routes34 35 get('/public/*', function(file){36 this.sendfile(config.path + '/' + file)37 })38 39 // Request40 41 Request.include({42 43 /**44 * Transfer static file at the given _path_ with optional _callback_.45 * _options_ are passed to fs.createReadStream().46 *47 * @param {string} path48 * @param {object} options49 * @param {function} callback50 * @return {Request}51 * @api public52 */5354 sendfile: function(path, options, callback) {55 var self = this56 if (options instanceof Function)57 callback = options,58 options = {}59 else60 options = options || {}61 if (path.indexOf('..') !== -1)62 Error.raise('InvalidPathError', "`" + path + "' is not a valid path")63 fs.stat(path, function(err, stat){64 if (err)65 return 'errno' in err && err.errno === 266 ? self.notFound()67 : self.error(err, callback)68 var etag = Number(stat.mtime)69 if (self.header('If-None-Match') && 70 self.header('If-None-Match') == etag)71 return self.respond(304, null)72 self.header('Content-Length', stat.size)73 self.header('ETag', etag)74 options.bufferSize = options.bufferSize75 || config.bufferSize76 || 6553677 if (stat.size > options.bufferSize)78 return self.stream(fs.createReadStream(path, options))79 fs.readFile(path, function(err, content){80 if (err) return self.error(err, callback)81 self.contentType(path)82 self.respond(200, content)83 })84 })85 return this86 },87 88 /**89 * Transfer static _file_ as an attachment.90 *91 * The basename of _file_ is used as the attachment _filename_ when92 * not explicitly passed.93 *94 * @param {string} file95 * @param {string} filename96 * @return {Request}97 * @api public98 */99100 download: function(file, filename) {101 return this.attachment(filename || path.basename(file)).sendfile(file)102 }103 })104 }105 }106})
deleted:lib/express/plugins/view.js-194 removed
12// Express - View - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)34/**5 * Module dependencies.6 */78var Request = require('./../request').Request,9 extname = require('path').extname,10 fs = require('fs')1112/**13 * Cache supported template engine exports.14 */1516var engines = {}1718/**19 * View cache.20 */21 22var cache = { views: {}, partials: {} }232425/**26 * View helpers (merged with locals).27 */2829var helpers = exports.helpers = {}3031/**32 * Cache view files where _type_ is33 * "partials" or "views".34 *35 * @param {string} type36 * @api public37 */3839function cacheFiles(type) { 40 (function cacheDir(dir) {41 try {42 fs.readdirSync(dir).each(function(file){43 file = dir + '/' + file44 var stat = fs.statSync(file)45 if (stat.isDirectory() && file != set('partials')) 46 cacheDir(file)47 else if (stat.isFile())48 cache[type][file] = fs.readFileSync(file, 'utf8')49 })50 } catch (err) {51 if (err.errno !== process.ENOENT) throw e52 }53 })(set(type))54}5556// --- View5758exports.View = Plugin.extend({59 extend: {60 61 /**62 * Initialize extensions.63 */64 65 init: function() {66 67 // Settings68 69 if (!set('views'))70 set('views', function(){ return set('root') + '/views' })71 72 if (!set('partials'))73 set('partials', function(){ return set('views') + '/partials' })74 75 // Cache views in memory76 77 if (set('cache view contents'))78 cacheFiles('views')79 80 if (set('cache view partials'))81 cacheFiles('partials')82 83 // Request84 85 Request.include({86 87 /**88 * Render _view_ partial with _options_.89 * View Request#render() for additional options.90 *91 * Options:92 * - as: String name for the id used to which "collection" assign it's current value.93 * - collection: Array of objects, the name is derived from94 * the view name itself. For example 'video.haml.html'95 * will have an object "video" available to it.96 *97 * @param {string} view98 * @param {hash} options99 * @settings 'partials', 'cache view partials'100 * @return {string}101 * @api public102 */103 104 partial: function(view, options) {105 var options = options || {}106 options.partial = true107 options.layout = false108 if (options.collection) {109 var name = options.as || view.split('.').first,110 len = options.collection.length111 options.locals = options.locals || {}112 options.locals.__length__ = len113 return options.collection.map(function(val, i){114 options.locals.__isFirst__ = i === 0115 options.locals.__index__ = i116 options.locals.__isLast__ = i === len - 1117 options.locals[name] = val118 return this.render(view, options)119 }, this).join('')120 } else121 return this.render(view, options)122 },123124 /**125 * Render _view_ with _options_.126 *127 * Views are looked up relative to the'views' path setting. 128 * View filenames should conform to NAME.TYPE.ENGINE so for example129 * 'layout.html.ejs', 'ejs' represents the template engine, 'html'130 * represents the type of content being rendered, which is then passed131 * to contentType().132 *133 * Engines must export a render() method accepting the template string134 * and a hash of options. Engines can respond to the options listed below135 * as well as their own arbitrary ones. The "filename" option is always136 * passed as the path to the given _view_, allowing engines to perform137 * better error reporting.138 *139 * Options:140 *141 * - encoding: Passed to Request#respond()142 * - layout: The layout to use, none when falsey. Defaults to 'layout'143 * - locals: Most engines support a hash of local variable names / values.144 * - context: Most engines support an evaluation context (the 'this' keyword). 145 * Defaults to the current Request instance.146 *147 * Optionally you may also pass a _callback_ function which148 * will be called instead of responding with the 200 status code.149 *150 * @param {string} view151 * @param {object} options152 * @param {function} callback153 * @settings 'views', 'cache view contents'154 * @api public155 */156157 render: function(view, options, callback) {158 var options = options || {},159 type = options.partial ? 'partials' : 'views',160 path = set(type) + '/' + view,161 parts = view.split('.'),162 engine = parts.last,163 contentType = parts.slice(-2)[0],164 layout = options.layout === undefined165 ? 'layout'166 : options.layout167 options.locals = options.locals || {}168 Object.merge(options.locals, helpers)169 options.filename = path170 if (set('cache view contents'))171 options.cache = true172 var content = cache[type][path] || fs.readFileSync(path).toString(options.encoding || 'utf8')173 options.context = options.context || this174 content = (engines[engine] = engines[engine] || require(engine)).render(content, options)175 if (type === 'views') this.contentType(contentType)176 if (layout) {177 layout = layout.indexOf('.') !== -1178 ? layout179 : [layout, contentType, engine].join('.')180 this.render(layout, Object.mergeDeep(options, {181 layout: false,182 locals: { body: content }183 }), callback)184 } else if (type === 'partials')185 return content186 else if (callback)187 callback.call(this, null, content)188 else189 this.respond(200, content, options.encoding)190 }191 })192 }193 }194})
deleted:lib/express/core.js-289 removed
12// Express - Core - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)34/**5 * Module dependencies.6 */78var Request = require('./request').Request,9 normalizePath = require('./request').normalizePath,10 multipart = require('old'),11 utils = require('./utils'),12 http = require('http'),13 sys = require('sys'),14 fs = require('fs')1516Object.merge(global, require('./plugin'))17Object.merge(global, require('./dsl'))1819// --- Route2021Route = new Class({22 23 /**24 * Initialize a route with the given _method_,25 * _path_, and _callback_.26 *27 * The given _path_ becomes #originalPath, 28 * #path is then a normalized version converted29 * to a regular expression for routing.30 *31 * @param {string} method32 * @param {string} path33 * @param {function} callback34 * @param {hash} options35 * @api private36 */37 38 constructor: function(method, path, callback, options){39 this.method = method40 this.originalPath = path41 this.path = this.normalize(path)42 this.callback = callback43 },44 45 /**46 * Normalize _path_. When a RegExp it is simply returned,47 * otherwise a string is converted to a regular expression48 * surrounded by ^$. So /user/:id/edit would become:49 *50 * /^\/user\/([^\/]+)\/edit$/i51 *52 * Each param key (:id) will be captured and placed in the53 * params array, so param('id') would give the string captured.54 *55 * The following are valid routes:56 *57 * - /user/:id Ex: '/user/12'58 * - /user/:id? Ex: '/user', '/user/12'59 * - /report.:format Ex: '/report.pdf', 'report.csv'60 * - /public/* Ex: '/public/app.js', '/public/javascripts/app.js'61 * - /public/*.* Ex: '/public/app.js', '/public/javascripts/app.js'62 *63 * @param {string} path64 * @return {regexp}65 * @api private66 */6768 normalize: function(path) {69 var self = this70 this.keys = []71 if (path instanceof RegExp) return path72 return new RegExp('^' + RegExp.escape(normalizePath(path), '.')73 .replace(/\*/g, '(.+)')74 .replace(/(\/|\\\.):(\w+)\?/g, function(_, c, key){75 self.keys.push(key)76 return '(?:' + c + '([^\/]+))?'77 })78 .replace(/:(\w+)/g, function(_, key){79 self.keys.push(key)80 return '([^\/]+)'81 }) + '$', 'i')82 }83})8485// --- Router8687Router = new Class({88 89 /**90 * Initialize with _request_ and parse url.91 *92 * @param {Request} request93 * @api private94 */95 96 constructor: function(request) {97 this.request = request98 this.method = request.method.lowercase99 },100 101 /**102 * Evaluate the matched route against #request.103 *104 * @return {mixed}105 * @api private106 */107 108 route: function() { 109 var body, 110 route = this.matchingRoute()111 if (route) {112 body = route.callback.apply(this.request, this.request.captures.slice(1));113 if (this.request.passed) {114 if (typeof this.request.passed === 'string')115 this.request.url.pathname = this.request.passed116 this.request.passed = false117 return this.route()118 }119 return body120 }121 else122 this.request.notFound()123 },124 125 /**126 * Attempt to match a route from Express.routes.127 *128 * @return {Route}129 * @api private130 */131 132 matchingRoute: function() {133 this.lastMatchingRoute = this.lastMatchingRoute || 0134 var routes = Express.routes, route135 while (route = routes[this.lastMatchingRoute++]) 136 if (this.match(route))137 break138 return route139 },140 141 /**142 * Check if _route_ matches the current request.143 * If so populate #captures and #params.144 *145 * @param {object} route146 * @return {bool}147 * @api private148 */149150 match: function(route) {151 if (this.method === route.method)152 if (this.request.captures = this.request.url.pathname.match(route.path)) {153 this.mapParams(route)154 return true155 }156 },157 158 /**159 * Map #request.captures to #request.params.path based on the160 * given _route_ params.161 *162 * @param {Route} route163 * @api private164 */165 166 mapParams: function(route) {167 route.keys.each(function(key, i){168 var val = this.request.captures[++i]169 if (key in Express.params)170 if ((val = Express.params[key].call(this.request, val)) === false)171 this.request.passed = true172 this.request.params.path[key] = this.request.captures[i] = val173 }, this)174 }175})176177// --- Server178179Server = new Class({180 181 /**182 * Default port number.183 */184 185 port: 3000,186 187 /**188 * Default host ip, when null node will accept requests on 189 * all network addresses.190 */191 192 host: null,193 194 /**195 * Run Express with optional _port_ defaulting to 3000,196 * and host defaulting to null (INADDR_ANY).197 *198 * @param {int} port199 * @param {string} host200 * @return {Server}201 * @see run()202 * @api private203 */204 205 run: function(port, host){206 var self = this207 if (host !== undefined) this.host = host208 if (port !== undefined) this.port = port209 var server = http210 .createServer(function(req, response){211 var request, pendingFiles = 0212 req.setEncoding('binary')213 request = new Request(req, response)214 request.body = ''215 function callback(err) {216 if (err)217 request.error(err)218 else if (!pendingFiles)219 self.route(request)220 }221 if (request.header('Content-Type') &&222 request.header('Content-Type').includes('multipart/form-data')) {223 var stream,224 contentLength = parseInt(request.header('Content-Length')),225 maxBodyLength = set('max upload size')226 if (maxBodyLength && contentLength > maxBodyLength)227 return callback(new Error('upload size limit exceeded'))228 stream = multipart.parse(req)229 stream230 .addListener('partBegin', function(part) {231 if (part.filename)232 ++pendingFiles,233 part.tempfile = '/tmp/express-' + Date.now() + utils.uid(),234 part.fileStream = fs.createWriteStream(part.tempfile),235 part.fileStream.addListener('error', callback)236 else237 part.buf = ''238 })239 .addListener('body', function(chunk) {240 if (stream.part.fileStream)241 stream.part.fileStream.write(chunk, 'binary')242 else243 stream.part.buf += chunk244 })245 .addListener('partEnd', function(part) {246 if (!part.name) return247 if (part.fileStream)248 part.fileStream.end(function(){249 --pendingFiles250 callback()251 }),252 utils.mergeParam(part.name, { filename: part.filename, tempfile: part.tempfile }, request.params.post) 253 else254 utils.mergeParam(part.name, part.buf, request.params.post) 255 })256 .addListener('error', callback)257 .addListener('complete', callback)258 }259 else260 req261 .addListener('data', function(chunk){ request.body += chunk })262 .addListener('end', callback)263 })264 server.listen(this.port, this.host)265 sys.puts('Express started at http://' + (this.host || '*') + ':' + this.port + '/ in ' + Express.environment + ' mode')266 return server267 },268 269 /**270 * Route the given _request_.271 *272 * @param {Request} request273 * @api private274 */275 276 route: function(request){ 277 var self = this278 request.trigger('request', function(err) {279 try { 280 if (err) throw err281 if (request.response.finished) return282 if (typeof (body = (new Router(request)).route()) === 'string')283 request.respond(200, body)284 } catch (err) {285 request.error(err)286 }287 })288 }289})
deleted:lib/express/dsl.js-161 removed
12// Express - DSL - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)34/**5 * Return a routing function for _method_.6 *7 * @param {string} method8 * @return {function}9 * @api private10 */1112function route(method) {13 return function(path, options, callback){14 if (options instanceof Function)15 callback = options, options = {}16 Express.routes.push(new Route(method, path, callback, options))17 }18}1920/**21 * Set _option_ to _val_. When only _option_ is22 * present its current value will be returned.23 *24 * @param {string} option25 * @param {mixed} val26 * @return {mixed}27 * @api public28 */2930exports.set = function(option, val) {31 return val === undefined32 ? Express.settings[option] instanceof Function33 ? Express.settings[option]()34 : Express.settings[option]35 : Express.settings[option] = val36}3738/**39 * Enable _options_.40 *41 * @param {string} option42 * @api public43 */4445exports.enable = function(option) {46 set(option, true)47}4849/**50 * Disable _option_.51 *52 * @param {string} option53 * @api public54 */5556exports.disable = function(option) {57 set(option, false)58}5960/**61 * Run Express, view Server#run() for parameters.62 *63 * All configuration handlers for EXPRESS_ENV or 'development'64 * are called before starting the server.65 *66 * @see Server#run()67 * @api public68 */6970exports.run = function() {71 configure(Express.environment = process.env.EXPRESS_ENV || 'development')72 Express.plugins.each(function(plugin){73 if ('init' in plugin.klass)74 plugin.klass.init(plugin.options)75 })76 return Express.server.run.apply(Express.server, arguments)77}7879/**80 * Configure _env_ with _callback_.81 *82 * Global configuration, disregards which83 * environment is active:84 *85 * configure(function(){86 * // ...87 * })88 *89 * Environment specific configuration:90 *91 * configure('development', function(){92 * // ...93 * })94 *95 * Running configurations:96 * 97 * configure('development')98 *99 * @param {string, function} env100 * @param {function} callback101 * @api public102 */103104exports.configure = function(env, callback) {105 if (env instanceof Function)106 callback = env, env = 'all'107 if (callback instanceof Function)108 return Express.config.push([env, callback])109 if (typeof env !== 'string')110 throw new TypeError('environment required')111 Express.config.each(function(conf){112 if (conf[0] === env ||113 conf[0] === 'all')114 conf[1].call(Express)115 })116}117118/**119 * Pre-process param _key_ with _callback_.120 *121 * @param {string} key122 * @param {function} callback123 * @api public124 */125126exports.param = function(key, callback) {127 if (typeof key !== 'string')128 throw new TypeError('param key must be a string')129 if (typeof callback !== 'function')130 throw new TypeError('param must pass a function to process "' + key + '"')131 Express.params[key] = callback132}133134/**135 * Register a "Not Found" route with the given _callback_.136 *137 * @param {function} callback138 * @api public139 */140141exports.notFound = function(callback) {142 Express.notFound = callback143}144145/**146 * Register an "error" route with the given _callback_.147 *148 * @param {function} callback149 * @api public150 */151152exports.error = function(callback) {153 Express.error = callback154}155156// --- Routing API157158exports.get = exports.view = route('get')159exports.post = exports.create = route('post')160exports.del = exports.destroy = route('delete')161exports.put = exports.update = route('put')
deleted:lib/express/event.js-29 removed
12// Express - Event - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)34exports.Event = new Class({5 6 /**7 * Initialize with event _name_ and optional _data_.8 *9 * @param {string} name10 * @param {hash} data11 * @api private12 */13 14 constructor: function(name, data) {15 this.name = name16 Object.merge(this, data)17 },18 19 /**20 * Return event string.21 *22 * @return {string}23 * @api public24 */25 26 toString: function() {27 return '[Event ' + this.name + ']'28 }29})
deleted:lib/express/http.js-115 removed
12// Express - HTTP - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)34/**5 * Module dependencies.6 */78var http = require('http'),9 parse = require('url').parse,10 queryString = require('querystring')11 12/**13 * Mega super awesome private request utility.14 *15 * @param {string} method16 * @param {string} url17 * @param {hash} data18 * @param {hash} headers19 * @param {function} callback20 * @param {number} redirects21 * @api private22 */23 24function request(method, url, data, headers, callback, redirects, first) {25 var buf = '',26 redirects = typeof redirects !== 'number' ? 3 : redirects,27 url = parse(url),28 path = url.pathname || '/',29 search = url.search || '',30 hash = url.hash || '',31 port = url.port || 80,32 headers = Object.merge(headers || {}, { Host: url.hostname }),33 client = http.createClient(port, url.hostname)34 if (typeof data === 'object' && 'redirects' in data)35 redirects = data.redirects,36 delete data.redirects37 if (first && data) {38 if (typeof data !== 'string')39 data = queryString.stringify(data)40 if (method === 'GET')41 search += (search ? '&' : '?') + data42 else {43 if (!headers['Content-Length'])44 headers['Content-Length'] = data.length45 if (!headers['Content-Type'])46 headers['Content-Type'] = 'application/x-www-form-urlencoded'47 }48 }49 var req = client.request(method, path + search + hash, headers)50 if (data && method !== 'GET') req.write(data)51 req.addListener('response', function(res){52 if (res.statusCode < 200 || res.statusCode >= 400)53 callback(new Error('request failed with status ' + res.statusCode + ' "' + http.STATUS_CODES[res.statusCode] + '"'), '', res)54 else if (res.statusCode >= 300 && res.statusCode < 400)55 if (redirects--)56 request(method, res.headers.location, data, headers, callback, redirects, false)57 else58 callback(new Error('maximum number of redirects reached'), '', res)59 else {60 res.setBodyEncoding('utf8')61 res62 .addListener('data', function(chunk){ buf += chunk })63 .addListener('end', function(){ callback(null, buf, res) })64 }65 })66 req.end()67}6869/**70 * Return HTTP Client function for the given _method_.71 *72 * @param {string} method73 * @return {function}74 * @api private75 */7677function client(method) {78 return function() {79 var redirects,80 args = Array.prototype.slice.call(arguments),81 url = args.shift(),82 callback = args.pop(),83 data = args.shift(),84 headers = args.shift()85 if (typeof callback !== 'function')86 throw new TypeError('http client requires a callback function')87 return request(method.toUpperCase(), url, data, headers, callback, redirects, true)88 }89}9091// --- Public API9293/**94 * Examples:95 *96 * var http = require('express/http')97 *98 * http.get('http://google.com/search', { q: 'foobar' }, function(err, body, response){99 * if (!err) sys.puts(body)100 * })101 *102 * http.get('http://google.com/search?lang=en', { q: 'foobar' }, function(){103 * // ...104 * })105 *106 * http.post('http://localhost:8000', '<user>tj</user>', { 'Content-Type': 'text/xml' }, function(err, body){107 * // ...108 * })109 *110 */111112exports.get = exports.view = client('get')113exports.post = exports.create = client('post')114exports.put = exports.update = client('put')115exports.del = exports.destroy = client('delete')
deleted:lib/express/mime.js-369 removed
12// Express - Mime - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)34/**5 * Module dependencies.6 */7 8var extname = require('path').extname910/**11 * Mime type lookup table.12 */1314exports.types = {15 '323' : 'text/h323',16 '3gp' : 'video/3gpp',17 'a' : 'application/octet-stream',18 'acx' : 'application/internet-property-stream',19 'ai' : 'application/postscript',20 'aif' : 'audio/x-aiff',21 'aifc' : 'audio/x-aiff',22 'aiff' : 'audio/x-aiff',23 'asc' : 'application/pgp-signature',24 'asf' : 'video/x-ms-asf',25 'asr' : 'video/x-ms-asf',26 'asm' : 'text/x-asm',27 'asx' : 'video/x-ms-asf',28 'atom' : 'application/atom+xml',29 'au' : 'audio/basic',30 'avi' : 'video/x-msvideo',31 'axs' : 'application/olescript',32 'bas' : 'text/plain',33 'bat' : 'application/x-msdownload',34 'bcpio' : 'application/x-bcpio',35 'bin' : 'application/octet-stream',36 'bmp' : 'image/bmp',37 'bz2' : 'application/x-bzip2',38 'c' : 'text/x-c',39 'cab' : 'application/vnd.ms-cab-compressed',40 'cat' : 'application/vnd.ms-pkiseccat',41 'cc' : 'text/x-c',42 'cdf' : 'application/x-netcdf',43 'cer' : 'application/x-x509-ca-cert',44 'cgm' : 'image/cgm',45 'chm' : 'application/vnd.ms-htmlhelp',46 'class' : 'application/octet-stream',47 'clp' : 'application/x-msclip',48 'cmx' : 'image/x-cmx',49 'cod' : 'image/cis-cod',50 'com' : 'application/x-msdownload',51 'conf' : 'text/plain',52 'cpio' : 'application/x-cpio',53 'cpp' : 'text/x-c',54 'cpt' : 'application/mac-compactpro',55 'crd' : 'application/x-mscardfile',56 'crl' : 'application/pkix-crl',57 'crt' : 'application/x-x509-ca-cert',58 'csh' : 'application/x-csh',59 'css' : 'text/css',60 'csv' : 'text/csv',61 'cxx' : 'text/x-c',62 'dcr' : 'application/x-director',63 'deb' : 'application/x-debian-package',64 'der' : 'application/x-x509-ca-cert',65 'diff' : 'text/x-diff',66 'dir' : 'application/x-director',67 'djv' : 'image/vnd.djvu',68 'djvu' : 'image/vnd.djvu',69 'dll' : 'application/x-msdownload',70 'dmg' : 'application/octet-stream',71 'dms' : 'application/octet-stream',72 'doc' : 'application/msword',73 'dot' : 'application/msword',74 'dtd' : 'application/xml-dtd',75 'dv' : 'video/x-dv',76 'dvi' : 'application/x-dvi',77 'dxr' : 'application/x-director',78 'ear' : 'application/java-archive',79 'eml' : 'message/rfc822',80 'eps' : 'application/postscript',81 'etx' : 'text/x-setext',82 'evy' : 'application/envoy',83 'exe' : 'application/x-msdownload',84 'ez' : 'application/andrew-inset',85 'f' : 'text/x-fortran',86 'f77' : 'text/x-fortran',87 'f90' : 'text/x-fortran',88 'fif' : 'application/fractals',89 'flr' : 'x-world/x-vrml',90 'flv' : 'video/x-flv',91 'for' : 'text/x-fortran',92 'gem' : 'application/octet-stream',93 'gemspec' : 'text/x-script.ruby',94 'gif' : 'image/gif',95 'gram' : 'application/srgs',96 'grxml' : 'application/srgs+xml',97 'gtar' : 'application/x-gtar',98 'gz' : 'application/x-gzip',99 'h' : 'text/x-c',100 'hdf' : 'application/x-hdf',101 'hh' : 'text/x-c',102 'hlp' : 'application/winhlp',103 'hqx' : 'application/mac-binhex40',104 'hta' : 'application/hta',105 'htc' : 'text/x-component',106 'htm' : 'text/html',107 'html' : 'text/html',108 'htt' : 'text/webviewhtml',109 'ice' : 'x-conference/x-cooltalk',110 'ico' : 'image/vnd.microsoft.icon',111 'ics' : 'text/calendar',112 'ief' : 'image/ief',113 'ifb' : 'text/calendar',114 'iges' : 'model/iges',115 'igs' : 'model/iges',116 'iii' : 'application/x-iphone',117 'ins' : 'application/x-internet-signup',118 'isp' : 'application/x-internet-signup',119 'iso' : 'application/octet-stream',120 'jar' : 'application/java-archive',121 'java' : 'text/x-java-source',122 'jfif' : 'image/pipeg',123 'jnlp' : 'application/x-java-jnlp-file',124 'jp2' : 'image/jp2',125 'jpe' : 'image/jpeg',126 'jpeg' : 'image/jpeg',127 'jpg' : 'image/jpeg',128 'js' : 'application/javascript',129 'json' : 'application/json',130 'kar' : 'audio/midi',131 'latex' : 'application/x-latex',132 'lha' : 'application/octet-stream',133 'lsf' : 'video/x-la-asf',134 'lsx' : 'video/x-la-asf',135 'lzh' : 'application/octet-stream',136 'log' : 'text/plain',137 'm13' : 'application/x-msmediaview',138 'm14' : 'application/x-msmediaview',139 'm3u' : 'audio/x-mpegurl',140 'm4a' : 'audio/mp4a-latm',141 'm4b' : 'audio/mp4a-latm',142 'm4p' : 'audio/mp4a-latm',143 'm4u' : 'video/vnd.mpegurl',144 'm4v' : 'video/mp4',145 'mac' : 'image/x-macpaint',146 'man' : 'text/troff',147 'mathml' : 'application/mathml+xml',148 'mbox' : 'application/mbox',149 'mdb' : 'application/x-msaccess',150 'mdoc' : 'text/troff',151 'me' : 'text/troff',152 'mesh' : 'model/mesh',153 'mht' : 'message/rfc822',154 'mhtml' : 'message/rfc822',155 'mid' : 'audio/midi',156 'midi' : 'audio/midi',157 'mif' : 'application/vnd.mif',158 'mime' : 'message/rfc822',159 'mml' : 'application/mathml+xml',160 'mng' : 'video/x-mng',161 'mny' : 'application/x-msmoney',162 'mov' : 'video/quicktime',163 'movie' : 'video/x-sgi-movie',164 'mp2' : 'video/mpeg',165 'mp3' : 'audio/mpeg',166 'mp4' : 'video/mp4',167 'mp4v' : 'video/mp4',168 'mpa' : 'video/mpeg',169 'mpe' : 'video/mpeg',170 'mpeg' : 'video/mpeg',171 'mpg' : 'video/mpeg',172 'mpga' : 'audio/mpeg',173 'mpp' : 'application/vnd.ms-project',174 'mpv2' : 'video/mpeg',175 'ms' : 'text/troff',176 'msh' : 'model/mesh',177 'msi' : 'application/x-msdownload',178 'mvb' : 'application/x-msmediaview',179 'mxu' : 'video/vnd.mpegurl',180 'nc' : 'application/x-netcdf',181 'nws' : 'message/rfc822',182 'oda' : 'application/oda',183 'odp' : 'application/vnd.oasis.opendocument.presentation',184 'ods' : 'application/vnd.oasis.opendocument.spreadsheet',185 'odt' : 'application/vnd.oasis.opendocument.text',186 'ogg' : 'application/ogg',187 'p' : 'text/x-pascal',188 'p10' : 'application/pkcs10',189 'p12' : 'application/x-pkcs12',190 'p7b' : 'application/x-pkcs7-certificates',191 'p7c' : 'application/x-pkcs7-mime',192 'p7m' : 'application/x-pkcs7-mime',193 'p7r' : 'application/x-pkcs7-certreqresp',194 'p7s' : 'application/x-pkcs7-signature',195 'pas' : 'text/x-pascal',196 'pbm' : 'image/x-portable-bitmap',197 'pct' : 'image/pict',198 'pdb' : 'chemical/x-pdb',199 'pdf' : 'application/pdf',200 'pem' : 'application/x-x509-ca-cert',201 'pfx' : 'application/x-pkcs12',202 'pgm' : 'image/x-portable-graymap',203 'pgn' : 'application/x-chess-pgn',204 'pgp' : 'application/pgp-encrypted',205 'pic' : 'image/pict',206 'pict' : 'image/pict',207 'pkg' : 'application/octet-stream',208 'pko' : 'application/ynd.ms-pkipko',209 'pl' : 'text/x-script.perl',210 'pm' : 'text/x-script.perl-module',211 'pma' : 'application/x-perfmon',212 'pmc' : 'application/x-perfmon',213 'pml' : 'application/x-perfmon',214 'pmr' : 'application/x-perfmon',215 'pmw' : 'application/x-perfmon',216 'png' : 'image/png',217 'pnm' : 'image/x-portable-anymap',218 'pnt' : 'image/x-macpaint',219 'pntg' : 'image/x-macpaint',220 'pot' : 'application/vnd.ms-powerpoint',221 'ppm' : 'image/x-portable-pixmap',222 'pps' : 'application/vnd.ms-powerpoint',223 'ppt' : 'application/vnd.ms-powerpoint',224 'prf' : 'application/pics-rules',225 'ps' : 'application/postscript',226 'psd' : 'image/vnd.adobe.photoshop',227 'pub' : 'application/x-mspublisher',228 'py' : 'text/x-script.python',229 'qt' : 'video/quicktime',230 'qti' : 'image/x-quicktime',231 'qtif' : 'image/x-quicktime',232 'ra' : 'audio/x-pn-realaudio',233 'rake' : 'text/x-script.ruby',234 'ram' : 'audio/x-pn-realaudio',235 'rar' : 'application/x-rar-compressed',236 'ras' : 'image/x-cmu-raster',237 'rb' : 'text/x-script.ruby',238 'rdf' : 'application/rdf+xml',239 'rgb' : 'image/x-rgb',240 'rm' : 'application/vnd.rn-realmedia',241 'rmi' : 'audio/mid',242 'roff' : 'text/troff',243 'rpm' : 'application/x-redhat-package-manager',244 'rss' : 'application/rss+xml',245 'rtf' : 'application/rtf',246 'rtx' : 'text/richtext',247 'ru' : 'text/x-script.ruby',248 's' : 'text/x-asm',249 'scd' : 'application/x-msschedule',250 'sct' : 'text/scriptlet',251 'setpay' : 'application/set-payment-initiation',252 'setreg' : 'application/set-registration-initiation',253 'sgm' : 'text/sgml',254 'sgml' : 'text/sgml',255 'sh' : 'application/x-sh',256 'shar' : 'application/x-shar',257 'sig' : 'application/pgp-signature',258 'silo' : 'model/mesh',259 'sit' : 'application/x-stuffit',260 'skd' : 'application/x-koan',261 'skm' : 'application/x-koan',262 'skp' : 'application/x-koan',263 'skt' : 'application/x-koan',264 'smi' : 'application/smil',265 'smil' : 'application/smil',266 'snd' : 'audio/basic',267 'so' : 'application/octet-stream',268 'spc' : 'application/x-pkcs7-certificates',269 'spl' : 'application/x-futuresplash',270 'src' : 'application/x-wais-source',271 'sst' : 'application/vnd.ms-pkicertstore',272 'stl' : 'application/vnd.ms-pkistl',273 'stm' : 'text/html',274 'sv4cpio' : 'application/x-sv4cpio',275 'sv4crc' : 'application/x-sv4crc',276 'svg' : 'image/svg+xml',277 'svgz' : 'image/svg+xml',278 'swf' : 'application/x-shockwave-flash',279 't' : 'text/troff',280 'tar' : 'application/x-tar',281 'tbz' : 'application/x-bzip-compressed-tar',282 'tcl' : 'application/x-tcl',283 'tex' : 'application/x-tex',284 'texi' : 'application/x-texinfo',285 'texinfo' : 'application/x-texinfo',286 'text' : 'text/plain',287 'tgz' : 'application/x-compressed',288 'tif' : 'image/tiff',289 'tiff' : 'image/tiff',290 'torrent' : 'application/x-bittorrent',291 'tr' : 'text/troff',292 'trm' : 'application/x-msterminal',293 'tsv' : 'text/tab-seperated-values',294 'txt' : 'text/plain',295 'uls' : 'text/iuls',296 'ustar' : 'application/x-ustar',297 'vcd' : 'application/x-cdlink',298 'vcf' : 'text/x-vcard',299 'vcs' : 'text/x-vcalendar',300 'vrml' : 'model/vrml',301 'vxml' : 'application/voicexml+xml',302 'war' : 'application/java-archive',303 'wav' : 'audio/x-wav',304 'wbmp' : 'image/vnd.wap.wbmp',305 'wbxml' : 'application/vnd.wap.wbxml',306 'wcm' : 'application/vnd.ms-works',307 'wdb' : 'application/vnd.ms-works',308 'wks' : 'application/vnd.ms-works',309 'wma' : 'audio/x-ms-wma',310 'wmf' : 'application/x-msmetafile',311 'wml' : 'text/vnd.wap.wml',312 'wmls' : 'text/vnd.wap.wmlscript',313 'wmlsc' : 'application/vnd.wap.wmlscriptc',314 'wmv' : 'video/x-ms-wmv',315 'wmx' : 'video/x-ms-wmx',316 'wps' : 'application/vnd.ms-works',317 'wri' : 'application/x-mswrite',318 'wrl' : 'model/vrml',319 'wrz' : 'x-world/x-vrml',320 'wsdl' : 'application/wsdl+xml',321 'xaf' : 'x-world/x-vrml',322 'xbm' : 'image/x-xbitmap',323 'xht' : 'application/xhtml+xml',324 'xhtml' : 'application/xhtml+xml',325 'xla' : 'application/vnd.ms-excel',326 'xlc' : 'application/vnd.ms-excel',327 'xlm' : 'application/vnd.ms-excel',328 'xls' : 'application/vnd.ms-excel',329 'xlt' : 'application/vnd.ms-excel',330 'xml' : 'application/xml',331 'xof' : 'x-world/x-vrml',332 'xpm' : 'image/x-xpixmap',333 'xsl' : 'application/xml',334 'xslt' : 'application/xslt+xml',335 'xul' : 'application/vnd.mozilla.xul+xml',336 'xwd' : 'image/x-xwindowdump',337 'xyz' : 'chemical/x-xyz',338 'yaml' : 'text/yaml',339 'yml' : 'text/yaml',340 'z' : 'application/x-compress',341 'zip' : 'application/zip'342}343344/**345 * Return the mime type associated with _path_,346 * where _path_ may be a file path or the type of file347 * such as "png".348 *349 * By default 'application/octet-stream' is returned,350 * however this can be altered using the 'default mime type'351 * setting.352 *353 * var mime = require('express/mime')354 * mime.type('png') // => 'image/png'355 * mime.type('image.png') // => 'image/png'356 * mime.type('path/to/image.png') // => 'image/png'357 *358 * @param {string} path359 * @return {string}360 * @settings 'default mime type'361 * @api public362 */363364exports.type = function(path) {365 return exports.types[path] || 366 exports.types[extname(path).substr(1)] || 367 set('default mime type') || 368 'application/octet-stream' 369}
deleted:lib/express/plugin.js-43 removed
12// Express - Plugin - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)34/**5 * Push _plugin_ with _options_ to the plugin stack.6 * If _plugin_ has already been pushed, then it's options7 * will override any previously set.8 *9 * @param {Plugin} plugin10 * @param {hash} options11 * @api public12 */1314exports.use = function(plugin, options) {15 if (Express.environment === 'test' && 'init' in plugin)16 plugin.init(options)17 Express.plugins.each(function(other, i){18 if (other.klass === plugin)19 delete Express.plugins[i]20 })21 Express.plugins.push({22 klass: plugin,23 options: options 24 })25}2627// --- Plugin2829exports.Plugin = new Class({30 31 /**32 * Trigger handler for the given _event_.33 *34 * @param {Event} event35 * @api private36 */37 38 trigger: function(event, callback) {39 if ('on' in this)40 if (event.name in this.on)41 return this.on[event.name].call(this, event, callback)42 }43})
deleted:lib/express/plugins.js-12 removed
12// Express - Plugins - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)34Object.merge(global, require('./plugins/hooks'))5Object.merge(global, require('./plugins/static'))6Object.merge(global, require('./plugins/flash'))7Object.merge(global, require('./plugins/cache'))8Object.merge(global, require('./plugins/cookie'))9Object.merge(global, require('./plugins/session'))10Object.merge(global, require('./plugins/logger'))11Object.merge(global, require('./plugins/content-length'))12Object.merge(global, require('./plugins/method-override'))
deleted:lib/express/request.js-441 removed
12// Express - Request - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)34/**5 * Module dependencies.6 */78var Event = require('./event').Event,9 showExceptions = require('./pages/show-exceptions'),10 notFound = require('./pages/not-found'),11 statusBodies = require('http').STATUS_CODES,12 queryString = require('querystring'),13 mime = require('./mime'),14 url = require('url'),15 ext = require('ext'),16 sys = require('sys')1718// --- Helpers1920/**21 * Normalize the given _path_.22 * Strips trailing slashes and whitespace.23 *24 * @param {string} path25 * @return {string}26 * @api public27 */2829exports.normalizePath = function(path) {30 return path.replace(/[\s\/]*$/g, '')31}3233// --- Request3435exports.Request = new Class({36 37 /**38 * Initialize with node's _request_ and _response_ objects.39 *40 * - Defaults headers to {}41 * - Parses request url42 * - Normalizes url pathname43 * - Parses GET params when available44 * - Initializes plugins45 *46 * @param {object} request47 * @param {object} response48 * @api private49 */50 51 constructor: function(request, response) {52 Object.merge(this, request)53 response.headers = {}54 this.response = response 55 this.url = url.parse(this.url)56 this.url.pathname = exports.normalizePath(this.url.pathname) 57 this.params = {}58 this.params.path = {}59 this.params.get = this.url.query ? queryString.parse(this.url.query) : {}60 this.params.post = this.params.post || {}61 this.plugins = Express.plugins.map(function(plugin){62 return new plugin.klass(plugin.options) 63 })64 this.reversedPlugins = this.plugins.slice(0).reverse()65 },66 67 /**68 * Set response header _key_ and _val_ or get69 * request header value by _key_.70 *71 * @param {string} key72 * @param {string} val73 * @return {string}74 * @api public75 */7677 header: function(key, val) {78 return val === undefined79 ? this.headers[key.lowercase]80 : this.response.headers[key] = val81 },82 83 /**84 * Return the param _key_ value or undefined.85 *86 * - Checks GET parameters87 * - Checks POST parameters88 * - Checks route populated path parameters89 *90 * @param {string} key91 * @return {string}92 * @api public93 */9495 param: function(key) {96 if (key in this.params.get)97 return this.params.get[key]98 if (key in this.params.post)99 return this.params.post[key]100 if (key in this.params.path)101 return this.params.path[key]102 },103 104 /**105 * Check if Accept header includes the mime type106 * for any of the given paths, which calls mime.type().107 *108 * When no Accept header is present true will be109 * returned as stated in the HTTP specification.110 *111 * Example:112 *113 * this.accepts('png')114 * this.accepts('png', 'jpg', 'gif')115 * this.accepts('image.png')116 * this.accepts('path/to/image.png')117 *118 * @param {mixed} ...119 * @return {bool}120 * @api public121 */122123 accepts: function() {124 var accept = this.header('accept')125 if (!accept || accept === '*/*') return true126 return Object.values(arguments).any(function(path){127 var type = mime.type(path)128 return accept.indexOf(type) !== -1 ||129 accept.indexOf(type.split('/')[0] + '/*') !== -1130 })131 },132 133 /**134 * Check if the request was an xmlHttpRequest (ajax).135 *136 * @return {bool}137 * @api public138 */139140 get isXHR() {141 return (this.header('X-Requested-With') || '').lowercase === 'xmlhttprequest'142 },143144 /**145 * Set response status to _code_.146 *147 * @param {int} code148 * @return {Request}149 * @api public150 */151152 status: function(code) {153 this.response.status = code154 return this155 },156 157 /**158 * Respond with response _code_, and optional _body_.159 *160 * The status _code_ defaults to to 404, and _body_ will161 * default to the default body associated with the response162 * _code_.163 *164 * The _callback_ may be given as the 3rd or 4th argument,165 * which is then called when an error occurs OR when the response166 * has been completed.167 *168 * Examples:169 *170 * request.respond()171 * // 404 "Not Found"172 * 173 * request.respond(500)174 * // 500 "Internal Server Error"175 * 176 * request.respond(200, "im ok")177 * // 200 "im ok"178 *179 * request.respond(200, "√ woot", "utf8")180 * // "utf8" will set Request#charset to 'UTF-8'181 *182 * @param {int} code183 * @param {string} body184 * @param {string|function} encoding185 * @param {function} callback186 * @see statusBodies187 * @api public188 */189190 respond: function(code, body, encoding, callback) {191 var self = this192 this.status(code = code || 404)193 if (encoding instanceof Function)194 callback = encoding,195 encoding = null196 if (204 === code)197 body = null198 else if (body !== null)199 body = body || statusBodies[code]200 if (encoding === 'utf8' ||201 encoding === 'utf-8')202 this.charset = 'UTF-8'203 this.response.body = body204 this.trigger('response', function(err) {205 if (err) return self.error(err, callback)206 self.sendHead()207 if (body) self.response.write(self.response.body, encoding)208 self.response.end()209 if (callback) callback()210 }, true)211 },212 213 // >>> DEPRECATED: remove in 1.0214 215 halt: function(){216 ext.warn('Request#halt() has been renamed Request#respond()')217 this.respond.apply(this, arguments)218 },219 220 // <<< DEPRECATED221 222 /**223 * Transfer the given _stream_ with optional _callback_.224 *225 * @param {Stream} stream226 * @param {function} callback227 * @return {Request}228 * @api public229 */230 231 stream: function(stream, callback) {232 var self = this,233 first = true234 stream235 .addListener('error', function(err){236 if (first)237 return self.error(err, callback)238 stream.destroy()239 self.response.end()240 })241 .addListener('data', function(data){242 if (first) {243 first = false244 self.header('Transfer-Encoding', 'chunked')245 self.status(200)246 self.contentType(stream.path)247 self.sendHead()248 }249 self.response.write(data, 'binary')250 })251 .addListener('end', function(){252 self.trigger('response', function(err){253 if (err)254 return self.error(err, callback)255 self.response.end()256 }, true)257 })258 },259 260 /**261 * Send the response header.262 *263 * If Request#charset is defined, and the264 * "Content-Type" header, then "; charset=CHARSET" is265 * appended.266 *267 * @return {Request}268 * @api public269 */270 271 sendHead: function(){272 if (this.charset && this.response.headers['Content-Type'])273 this.response.headers['Content-Type'] += '; charset=' + this.charset274 this.response.writeHead(this.response.status, this.response.headers)275 return this276 },277 278 /**279 * Pass control to the next matching route, or280 * the given _path_.281 *282 * NOTE: _path_ may be the request pathname only,283 * and may not contain a query string etc.284 *285 * @param {string} path286 * @api public287 */288 289 pass: function(path) {290 this.passed = path || true291 return this292 },293 294 /**295 * Set Content-Type header to the mime type296 * for the given _path_, which calls mime.type().297 *298 * @param {string} path299 * @return {Request}300 * @api public301 */302303 contentType: function(path) {304 this.header('Content-Type', mime.type(path))305 return this306 },307 308 /**309 * Trigger event _name_ with optional _data_ and _callback_ function.310 * The _callback_ function may be the second or third argument.311 *312 * @param {string} name313 * @param {object} data314 * @param {function} callback315 * @param {bool} reverse316 * @return {Request}317 * @api public318 */319320 trigger: function(name, data, callback, reverse) { 321 if (data instanceof Function)322 reverse = callback,323 callback = data,324 data = null325 data = Object.merge({ request: this, response: this.response }, data)326 var self = this,327 complete = 0,328 total = this.plugins.length,329 plugins = reverse330 ? self.reversedPlugins331 : self.plugins332 ;(function next(err) {333 if (err || complete === total)334 callback(err)335 else {336 if (plugins[complete] === undefined)337 ++complete,338 next()339 else if (plugins[complete++].trigger(new Event(name, data), next) !== true)340 next()341 }342 })()343 return this344 },345 346 /**347 * Set Content-Disposition header to 'attachment',348 * with optional file _filename_.349 *350 * @param {string} filename351 * @return {Request}352 * @api public353 */354 355 attachment: function(filename) {356 this.header('Content-Disposition', filename357 ? 'attachment; filename="' + filename + '"'358 : 'attachment')359 return this360 },361 362 /**363 * Handle exceptions.364 *365 * When an error route is defined via the DSL it366 * will then be called regardless of any setting that367 * may be present. ("throw exceptions" will still work)368 *369 * error(function(err){370 * this.respond(500, 'your app sucks!')371 * })372 *373 * When "show exceptions" is enabled the show-exceptions page will be shown for "text/html",374 * a plain-text representation of the error for "text/plain" and JSON for "application/json".375 * Otherwise the request will halt with default 500 status body.376 *377 * When "throw exceptions" is enabled the error will be378 * re-thrown, terminating the process (unless otherwise caught).379 *380 * Also a _callback_ function may be supplied, which when defined381 * will be called, by-passing the process mentioned above.382 *383 * @param {Error} err384 * @param {function} callback385 * @return {Request}386 * @settings 'throw exceptions', 'show exceptions'387 * @api public388 */389 390 error: function(err, callback) {391 if (callback)392 return callback(err)393 if (Express.error)394 Express.error.call(this, err)395 else if (set('show exceptions'))396 if (this.accepts('html'))397 this.respond(500, showExceptions.render(this, err))398 else if (this.accepts('json'))399 this.respond(500, showExceptions.renderJSON(this, err))400 else if (this.accepts('text'))401 this.respond(500, showExceptions.renderText(this, err))402 else403 this.respond(500)404 else405 this.respond(500)406 if (set('dump exceptions'))407 sys.puts(err.stack)408 if (set('throw exceptions'))409 throw err410 return this411 },412 413 /**414 * Halt with 404 Not Found.415 *416 * When a notFound route is defined via the DSL it417 * will then be called regardless of any settings that418 * may be present.419 *420 * notFound(function(){421 * this.respond(404, 'Sorry your page cannot be found')422 * })423 *424 * When "html" is accepted, and "helpful 404" is enabled425 * the not-found page will be shown, otherwise the 426 * request will halt with default 404 status body.427 *428 * @return {Request}429 * @api public430 */431 432 notFound: function() {433 if (Express.notFound)434 Express.notFound.call(this)435 else if (this.accepts('html') && set('helpful 404'))436 this.respond(404, notFound.render(this))437 else438 this.respond()439 return this440 }441})
deleted:lib/express/utils.js-76 removed
12// Express - Helpers - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)34/**5 * Module dependencies.6 */7 8var queryString = require('querystring')910/**11 * JSON aliases.12 */1314JSON.encode = JSON.stringify15JSON.decode = JSON.parse1617/**18 * Return a unique identifier.19 *20 * @return {string}21 * @api public22 */2324exports.uid = function() {25 var uid = ''26 for (var n = 4; n; --n)27 uid += (Math.abs((Math.random() * 0xFFFFFFF) | 0)).toString(16)28 return uid29}3031/**32 * Escape special characters in _html_.33 *34 * @param {string} html35 * @return {string}36 * @api public37 */3839exports.escape = function(html) {40 return String(html)41 .replace(/&/g, '&amp;')42 .replace(/"/g, '&quot;')43 .replace(/</g, '&lt;')44 .replace(/>/g, '&gt;')45}4647/**48 * Merge param _key_ and _val_ into _params_. Key49 * should be a query string key such as 'user[name]',50 * and _val_ is it's associated object. The root _params_51 * object is returned.52 *53 * @param {string} key54 * @param {mixed} val55 * @return {hash}56 * @api public57 */5859exports.mergeParam = function(key, val, params) {60 var orig = params,61 keys = key.trim().match(/\w+/g),62 array = /\[\]$/.test(key)63 keys.reduce(function(parts, key, i){64 if (i === keys.length - 1)65 if (key in params)66 params[key] instanceof Array67 ? params[key].push(val)68 : params[key] = [params[key], val]69 else70 params[key] = array ? [val] : val71 if (!(key in params)) params[key] = {}72 params = params[key]73 return parts[key]74 }, queryString.parse(key))75 return orig76}