Re-organizing lib directory
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parent 9fa5a0b · Browse files · 17 files·+1067 added−1068 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
17 files+1067 added−1068 removed
- tests:+114 added−7 removed
- other:+953 added−1061 removed
Provenance
- Commit
dca7e9b- Tree
6160966- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
9fa5a0b
17 files changed+1067 added−1068 removed
added:lib/express/spec/mocks.js+113 added
1+2+// Express - Mocks - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)3+4+/**5+ * Mock _request_ object. Optionally pass hash of properties.6+ *7+ * @param {hash} request8+ * @return {hash}9+ * @api public10+ */11+12+function mockRequest(request) {13+ var mock = {14+ listeners: [],15+ method: 'GET',16+ headers: {},17+ uri: {18+ path: '/',19+ params: {}20+ },21+ setBodyEncoding : function(type) {22+ this.bodyEncoding = type 23+ },24+ addListener : function(event, callback) {25+ this.listeners.push({ event : event, callback : callback })26+ if (event == 'body') {27+ var body = this.body28+ this.body = ''29+ callback(body)30+ }31+ else32+ callback()33+ }34+ }35+ JSpec.extend(mock, request)36+ mock.uri.params = mock.uri.params || {}37+ return mock38+}39+40+/**41+ * Mock _response_ object. Optionally pass hash of properties.42+ *43+ * @param {hash} response44+ * @return {hash}45+ * @api public46+ */47+ 48+function mockResponse(response) {49+ var mock = {50+ body: null,51+ status: 200,52+ headers: [],53+ sendHeader: function(){},54+ sendBody: function(){},55+ finish: function(){ this.finished = true }56+ }57+ JSpec.extend(mock, response)58+ return mock59+}60+61+/**62+ * Mock server callback.63+ *64+ * @param {object} request65+ * @param {object} response66+ * @api private67+ */68+69+orig = Express.server.callback70+function mockCallback(request, response) {71+ orig(mockRequest(request), mockResponse(response))72+}73+74+/**75+ * Mock route function for HTTP _method_.76+ *77+ * @param {string} method78+ * @return {function}79+ * @api private80+ */81+82+function mockRouteFunctionFor(method) {83+ var orig = Express.routeFunctionFor(method)84+ return function(path, options, callback) {85+ if ((options && options.constructor == Function) || (callback && callback.constructor == Function)) {86+ return orig.apply(Express, arguments)87+ }88+ var request = mockRequest({ method : method.toUpperCase(), uri : { path : path }})89+ if (options)90+ JSpec.extend(request, options.request),91+ request.uri.path = path92+ var response = mockResponse()93+ Express.server.callback(request, response)94+ return Express.response95+ }96+}97+98+// --- Module99+100+JSpec.include({101+ init : function() {102+ Express.server.callback = mockCallback103+ },104+ 105+ utilities : {106+ mockRequest : mockRequest,107+ mockResponse : mockResponse,108+ get : mockRouteFunctionFor('get'),109+ post : mockRouteFunctionFor('post'),110+ put : mockRouteFunctionFor('put'),111+ del : mockRouteFunctionFor('delete')112+ }113+})added:lib/express/cookie.js+48 added
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
// Express - Cookie - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
Express.Cookie = { name : 'cookie', settings : { maxAge : 3600 }, utilities : { /** * Return cookie _key_. When _value_ is present * then a response cookie field will be set. * * @param {string} key * @param {string} value * @return {string, hash} * @api public */
cookie : function(key, value) { return value ? Express.response.cookie[key] = value : Express.response.cookie[key] } }, onRequest : { 'parse cookie' : function() { Express.response.cookie = Express.request.cookie = Express.parseCookie(Express.requestHeader('Cookie')); } }, onResponse : { 'set cookie' : function() { var cookie = [] for (var key in Express.response.cookie) if (Express.response.cookie.hasOwnProperty(key)) cookie.push(key + '=' + Express.response.cookie[key]) if (cookie.length) Express.header('Set-Cookie', cookie.join('; ')) } } }added:lib/express/core.js+678 added
1+2+// Express - Core - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)3+4+process.mixin(GLOBAL, require("sys"))5+var http = require("http")6+7+Express = { 8+ version: '0.0.1',9+ utilities: {},10+ modules: [],11+ routes: [],12+ responseCodes : {13+ 100: 'Continue',14+ 101: 'Switching Protocols',15+ 200: 'OK',16+ 201: 'Created',17+ 202: 'Accepted',18+ 203: 'Non-Authoritative Information',19+ 204: 'No Content',20+ 205: 'Reset Content',21+ 206: 'Partial Content',22+ 300: 'Multiple Choices',23+ 301: 'Moved Permanently',24+ 302: 'Moved Temporarily',25+ 303: 'See Other',26+ 304: 'Not Modified',27+ 305: 'Use Proxy',28+ 400: 'Bad Request',29+ 401: 'Unauthorized',30+ 402: 'Payment Required',31+ 403: 'Forbidden',32+ 404: 'Not Found',33+ 405: 'Method Not Allowed',34+ 406: 'Not Acceptable',35+ 407: 'Proxy Authentication Required',36+ 408: 'Request Time-out',37+ 409: 'Conflict',38+ 410: 'Gone',39+ 411: 'Length Required',40+ 412: 'Precondition Failed',41+ 413: 'Request Entity Too Large',42+ 414: 'Request-URI Too Large',43+ 415: 'Unsupported Media Type',44+ 500: 'Internal Server Error',45+ 501: 'Not Implemented',46+ 502: 'Bad Gateway',47+ 503: 'Service Unavailable',48+ 504: 'Gateway Time-out',49+ 505: 'HTTP Version not supported'50+ },51+ 52+ // --- Response53+ 54+ response : {55+ headers : {},56+ cookie : {}57+ },58+ 59+ // --- Settings60+ 61+ settings : {62+ basepath : '/',63+ defaultRoute : {64+ callback : function() {65+ Express.halt('Page or file cannot be found', 'Not Found')66+ }67+ }68+ },69+ 70+ // --- Modules71+ 72+ RedirectHelpers : {73+ init : function() {74+ Express.home = Express.settings.basepath75+ },76+ 77+ onRequest : {78+ 'set back to referrer' : function() {79+ Express.back = 80+ Express.requestHeader('Referer') ||81+ Express.requestHeader('Referrer')82+ }83+ }84+ },85+ 86+ ContentLength : {87+ onResponse : {88+ 'set content length' : function() {89+ Express.header('Content-Length', (Express.response.body || '').length)90+ }91+ }92+ },93+ 94+ DefaultContentType : {95+ onRequest : {96+ 'set response content type to text/html' : function() {97+ Express.header('Content-Type', 'text/html')98+ }99+ }100+ },101+ 102+ BodyDecoder : {103+ onRequest : {104+ 'parse urlencoded bodies' : function() {105+ switch (Express.requestHeader('Content-Type')) {106+ case 'application/x-www-form-urlencoded':107+ Express.request.uri.params = Express.parseParams(decodeURIComponent(Express.request.body))108+ break109+ 110+ case 'application/json':111+ Express.request.uri.params = Express.jsonDecode(Express.request.body)112+ break113+ }114+ }115+ }116+ },117+ 118+ MethodOverride : {119+ onRequest : {120+ 'set HTTP method to _method when present' : function() {121+ if (method = Express.param('_method'))122+ Express.request.method = method.toUpperCase()123+ }124+ }125+ },126+ 127+ Logger : {128+ onResponse : {129+ 'output log data' : function(){130+ puts('"' + Express.request.method + ' ' + Express.request.uri.path +131+ ' HTTP/' + Express.request.httpVersion + '" - ' + Express.response.status)132+ }133+ }134+ },135+ 136+ /**137+ * Invoke hook _name_ with _args_, returning138+ * an array of return values.139+ *140+ * @param {string} name141+ * @param {...} args142+ * @return {array}143+ * @api public144+ */145+ 146+ hook : function(name, args) {147+ var results = []148+ for (var i = 0, len = this.modules.length; i < len; ++i)149+ for (var key in this.modules[i][name])150+ results.push(this.modules[i][name][key].apply(this.modules[i], this.toArray(arguments, 1))) 151+ return results152+ },153+ 154+ /**155+ * Invoke hook _name_ with _immutable_ and _args_, returning156+ * the _immutable_ variable once modified by each hook implementation.157+ * When implementing these hooks, the function must return a value.158+ *159+ * @param {string} name160+ * @param {mixed} immutable161+ * @param {...} args162+ * @return {mixed}163+ * @api public164+ */165+ 166+ hookImmutable : function(name, immutable, args) {167+ for (var i = 0, len = this.modules.length; i < len; ++i)168+ for (var key in this.modules[i][name])169+ immutable = this.modules[i][name][key].call(this.modules[i], immutable)170+ return immutable171+ },172+ 173+ /**174+ * Add _module_.175+ *176+ * @param {hash} module177+ * @param {...} args178+ * @api public179+ */180+ 181+ addModule : function(module, args) {182+ Express.settings[module.name] = {}183+184+ if ('init' in module) 185+ module.init.apply(module, Express.toArray(arguments, 1))186+187+ if ('settings' in module) {188+ if (!module.name) throw 'module name is required when using .settings'189+ for (var name in module.settings)190+ Express.settings[module.name][name] = module.settings[name]191+ }192+ 193+ if ('utilities' in module)194+ for (var name in module.utilities)195+ Express.utilities[name] = module.utilities[name]196+ 197+ Express.modules.push(module)198+ },199+ 200+ /**201+ * Start Express; binding to _host_ / _port_.202+ *203+ * @param {int} port204+ * @param {string} host205+ * @api public206+ */207+ 208+ start : function(port, host) {209+ this.server.listen(port || 3000, host, this.server.callback)210+ },211+ 212+ server : {213+ 214+ /**215+ * Listen to _host_ / _port_ with _callback_.216+ *217+ * @param {int} port218+ * @param {string} host219+ * @param {function} callback220+ * @api private221+ */222+ 223+ listen : function(port, host, callback) {224+ http.createServer(callback).listen(port, host)225+ puts('Express started at http://' + (host || '127.0.0.1') + ':' + port + '/')226+ },227+ 228+ /**229+ * Request callback.230+ *231+ * @param {object} request232+ * @param {object} response233+ * @api private234+ */235+ 236+ callback : function(request, response){237+ request.body = request.body || ''238+ request.setBodyEncoding('utf8')239+ request.addListener('body', function(chunk) { request.body += chunk })240+ request.addListener('complete', function(){241+ Express.home = Express.settings.basepath242+ Express.response.body = null243+ Express.response.status = 200244+ Express.request = request245+ Express.originalResponse = response246+ request.uri.params = Express.parseNestedParams(request.uri.params)247+ request.uri.path = Express.normalizePath(request.uri.path)248+ Express.hook('onRequest')249+ try { Express.response.body = Express.callRouteFor(request) }250+ catch (e) { Express.fail(e) }251+ if (typeof Express.response.body == 'string')252+ Express.server.finished()253+ })254+ },255+ 256+ finished: function(body) {257+ if (body) Express.response.body = body258+ Express.hook('onResponse')259+ Express.originalResponse.sendHeader(Express.response.status, Express.response.headers)260+ Express.originalResponse.sendBody(Express.response.body || '')261+ Express.originalResponse.finish()262+ }263+ },264+ 265+ /**266+ * Fail Express with exception _e_.267+ *268+ * @param {object} e269+ * @api private270+ */271+272+ fail : function(e) {273+ this.hook('onFailure', e)274+ this.header('Content-Type', 'text/plain')275+ this.response.body = e.message ? e.name + ': ' + e.message : e.toString()276+ this.response.status = 500277+ },278+ 279+ /**280+ * JSON encode _object_281+ *282+ * @param {mixed} object283+ * @return {string}284+ * @api public285+ */286+ 287+ jsonEncode : function(object) {288+ return JSON.stringify(object)289+ },290+ 291+ /**292+ * JSON decode _string_.293+ *294+ * @param {string} string295+ * @return {mixed}296+ * @api public297+ */298+ 299+ jsonDecode : function(string) {300+ return JSON.parse(string)301+ },302+ 303+ /**304+ * Redirect to _uri_.305+ *306+ * @param {string} uri307+ * @api public308+ */309+ 310+ redirect : function(uri) {311+ this.header('Location', uri)312+ this.halt("Page or file has moved to `" + uri + "'", 'Moved Temporarily')313+ },314+ 315+ /**316+ * Set response status to _value_. Where value may be317+ * a case-insensitive string such as 'Not Found', 'forbidden',318+ * or a numeric HTTP response status code.319+ *320+ * @param {int, string} value321+ * @return {int}322+ * @api public323+ */324+ 325+ status : function(value) {326+ if (value == undefined) return327+ if (typeof value == 'number') return this.response.status = value328+ for (var code in this.responseCodes)329+ if (this.responseCodes[code].toLowerCase() == value.toLowerCase())330+ return this.response.status = parseInt(code)331+ },332+333+ /**334+ * Return path segment _n_.335+ *336+ * @param {int} n337+ * @return {string}338+ * @api public339+ */340+ 341+ arg : function(n) {342+ return this.request.uri.path.split('/')[n]343+ },344+ 345+ /**346+ * Set response _status_ and _body_. Status347+ * defaults to 200.348+ *349+ * @param {string} body350+ * @param {string, int} status351+ * @api public352+ */353+ 354+ halt : function(body, status) {355+ this.status(status || 200)356+ Express.server.finished(this.response.body = body)357+ },358+ 359+ /**360+ * Get or set response _name_ header.361+ *362+ * @param {string} name363+ * @param {string} value364+ * @return {string}365+ * @api public366+ */367+ 368+ header : function(name, value) {369+ return value ? 370+ this.response.headers[name.toLowerCase()] = value :371+ this.response.headers[name.toLowerCase()]372+ },373+ 374+ /**375+ * Get request header _name_ optionally providing _default_376+ * when _name_ is not present.377+ *378+ * @param {string} name379+ * @param {string} default380+ * @return {string}381+ * @api public382+ */383+ 384+ requestHeader : function(name, defaultValue) {385+ return this.request.headers[name.toLowerCase()] || defaultValue386+ },387+ 388+ /**389+ * Return param _key_'s value or _defaultValue_ when390+ * the param has not been set.391+ *392+ * @param {string} key393+ * @param {mixed} defaultValue394+ * @return {mixed}395+ * @api public396+ */397+ 398+ param : function(key, defaultValue) {399+ return this.request.uri.params[key] || defaultValue400+ },401+ 402+ /**403+ * Parse params _string_ into a nested hash.404+ *405+ * @param {string} string406+ * @return {hash}407+ * @api public408+ */409+ 410+ parseParams : function(string) {411+ var params = {}, pairs = string.split('&'), pair412+ for (var i = 0, len = pairs.length; i < len; ++i) {413+ pair = pairs[i].split('=')414+ params[pair[0]] = pair[1]415+ }416+ return this.parseNestedParams(params)417+ },418+ 419+ /**420+ * Parse _params_, splitting { user[info][name] : 'tj' } into421+ * { user : { info : { name : 'tj' }}}422+ *423+ * @param {hash} params424+ * @return {hash}425+ * @api public426+ */427+ 428+ parseNestedParams : function(params) {429+ for (var key in params)430+ if (parts = key.split('['))431+ if (parts.length > 1)432+ for (var i = 0, prop = params, len = parts.length; i < len; ++i) {433+ var name = parts[i].replace(']', '')434+ if (i == len - 1) {435+ prop[name] = params[key]436+ prop = params, delete params[key]437+ }438+ else {439+ prop = prop[name] = prop[name] || {}440+ }441+ }442+ 443+ return params444+ },445+ 446+ /**447+ * Parse _cookie_ string into an object (hash).448+ *449+ * @param {string} cookie450+ * @return {hash}451+ * @api public452+ */453+ 454+ parseCookie : function(cookie) {455+ var hash = {}456+ if (!cookie) return hash457+ var attrs = cookie.split(/\s*;\s*/)458+ for (var i = 0; i < attrs.length; ++i)459+ hash[attrs[i].split('=')[0]] = decodeURIComponent(attrs[i].split('=')[1])460+ return hash461+ },462+ 463+ /**464+ * Normalize a path. Strips trailing / leading whitespace465+ * and slashes ('/').466+ *467+ * @param {string} path468+ * @return {string}469+ * @api public470+ */471+ 472+ normalizePath : function(path) {473+ if (typeof path != 'string') return path474+ return path.replace(/^(\s|\/)*|(\s|\/)*$/g, '')475+ },476+ 477+ /**478+ * Normalize _path_. When a RegExp it is simply returned,479+ * otherwise a string is converted to a regular expression480+ * surrounded by ^$. So /user/:id/edit would become:481+ *482+ * \^/user/(.*?)\/edit\$/483+ *484+ * Each param key (:id) will be captured and placed in the485+ * params array, so param('id') would give the string captured.486+ *487+ * @param {string} path488+ * @return {regexp}489+ * @api public490+ */491+ 492+ pathToRegexp : function(path) {493+ Express.regexpKeys = []494+ if (path.constructor == RegExp) return path495+ path = path.replace(/:(\w+)/g, function(_, key){496+ Express.regexpKeys.push(key)497+ return '(.*?)'498+ })499+ return new RegExp('^' + this.escapeRegexp(path, '/ [ ]') + '$', 'i')500+ },501+ 502+ /**503+ * Escape RegExp _chars_ in _string_. Where _chars_ 504+ * defaults to regular expression special characters.505+ *506+ * _chars_ should be a space delimited list of characters,507+ * for example '[ ] ( )'.508+ *509+ * @param {string} string510+ * @param {string} chars511+ * @return {Type}512+ * @api public513+ */514+ 515+ escapeRegexp : function(string, chars) {516+ var specials = (chars || '/ . * + ? | ( ) [ ] { } \\').split(' ').join('|\\')517+ return string.replace(new RegExp('(\\' + specials + ')', 'g'), '\\$1')518+ },519+ 520+ /**521+ * Return the contents of a function body.522+ *523+ * @param {function} body524+ * @return {string}525+ * @api public526+ */527+ 528+ contentsOf : function(body) {529+ if (typeof body != 'function') throw "Express.contentsOf(): `" + body + "' is not a function"530+ return body.toString().match(/^[^\{]*{((.*\n*)*)}/m)[1]531+ },532+ 533+ /**534+ * Eval _string_ in context of Express.535+ *536+ * @param {string} string537+ * @return {mixed}538+ * @api public539+ */540+ 541+ eval : function(string) {542+ return eval('with (Express){ with (Express.utilities){ ' + string + '}}')543+ },544+ 545+ /**546+ * Escape special characters in _html_.547+ *548+ * @param {string} html549+ * @return {string}550+ * @api public551+ */552+ 553+ escape : function(html) {554+ return html.555+ replace(/&/g, '&').556+ replace(/"/g, '"').557+ replace(/</g, '<').558+ replace(/>/g, '>')559+ },560+ 561+ /**562+ * Convert native array-like objects into an563+ * array with optional _offset_.564+ *565+ * @param {object} arr566+ * @param {int} offset567+ * @return {array}568+ * @api public569+ */570+ 571+ toArray : function(arr, offset) {572+ return Array.prototype.slice.call(arr, offset)573+ },574+ 575+ /**576+ * Check if _route_ matches provides the proper577+ * encoding types listed in _request_'s Accept header.578+ *579+ * @param {hash} route580+ * @param {hash} request581+ * @return {bool}582+ * @api private583+ */584+ 585+ routeProvides : function(route, request) {586+ if (!route.options.provides) return true587+ if (route.options.provides.constructor != Array) 588+ route.options.provides = [route.options.provides]589+ for (var i = 0, len = route.options.provides.length; i < len; ++i)590+ if (request.headers.accept && request.headers.accept.match(route.options.provides[i]))591+ return true592+ return false593+ },594+ 595+ /**596+ * Attept to match and call a route for 597+ * the given _request_, returning the data598+ * returned by the route callback.599+ *600+ * @param {object} request601+ * @return {mixed}602+ * @api private603+ */604+ 605+ callRouteFor : function(request) {606+ var route = this.findRouteFor(request) || this.settings.defaultRoute607+ if (route.keys)608+ for (var i = 0, len = route.keys.length; i < len; ++i) 609+ this.request.uri.params[route.keys[i]] = Express.captures[i+1] || null610+ var body = this.eval(Express.contentsOf(route.callback))611+ if (typeof body != 'string') body = null612+ return body613+ },614+ 615+ /**616+ * Attempt to find and return a route matching _request_.617+ *618+ * @param {object} request619+ * @return {object}620+ * @api private621+ */622+ 623+ findRouteFor : function(request) {624+ for (var i = 0, len = this.routes.length; i < len; ++i)625+ if (this.routeMatches(this.routes[i], request))626+ return this.routes[i]627+ },628+ 629+ /**630+ * Check if _route_ matches _request_631+ *632+ * @param {object} route633+ * @param {object} request634+ * @return {bool}635+ * @api private636+ */637+ 638+ routeMatches : function(route, request) {639+ if (request.method.toLowerCase() != route.method) return false640+ switch (route.path.constructor) {641+ case String: return route.path == request.uri.path642+ case RegExp: return !! (Express.captures = request.uri.path.match(route.path))643+ }644+ },645+ 646+ /**647+ * Return a routing function for _method_.648+ *649+ * @param {string} method650+ * @return {function}651+ * @api private652+ */653+ 654+ routeFunctionFor : function(method) {655+ return function(path, options, callback) {656+ if (options.constructor == Function) callback = options, options = {}657+ path = Express.pathToRegexp(Express.normalizePath(path))658+ var route = {659+ keys : Express.regexpKeys,660+ path : path,661+ method : method,662+ options : options,663+ callback : callback664+ }665+ Express.routes.push(route)666+ Express.hook('onRouteAdded', route)667+ }668+ }669+}670+671+// --- Routing API672+673+get = Express.routeFunctionFor('get')674+post = Express.routeFunctionFor('post')675+del = Express.routeFunctionFor('delete')676+put = Express.routeFunctionFor('put')677+use = Express.addModule678+added:lib/express/mime.js+198 added
1+2+// Express - Mime - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)3+4+Express.Mime = {5+ name : 'mime',6+ 7+ settings : {8+ defaultType : 'application/octet-stream'9+ },10+ 11+ utilities : {12+ 13+ /**14+ * Returns the media type of _ext_, where _ext_ may be an15+ * extension ('jpeg') or a file path ('path/to/image.name.jpeg'). 16+ * Defaults to Express.settings.mime.defaultType.17+ *18+ * @param {string} ext19+ * @return {string}20+ * @api public21+ */22+ 23+ mime : function(ext) {24+ if (ext.indexOf('.') != -1) 25+ ext = ext.substring(ext.lastIndexOf('.') + 1, ext.length)26+ return Express.utilities.mimeTypes[ext] || Express.settings.mime.defaultType27+ 28+ },29+ 30+ mimeTypes : {31+ "3gp" : "video/3gpp",32+ "a" : "application/octet-stream",33+ "ai" : "application/postscript",34+ "aif" : "audio/x-aiff",35+ "aiff" : "audio/x-aiff",36+ "asc" : "application/pgp-signature",37+ "asf" : "video/x-ms-asf",38+ "asm" : "text/x-asm",39+ "asx" : "video/x-ms-asf",40+ "atom" : "application/atom+xml",41+ "au" : "audio/basic",42+ "avi" : "video/x-msvideo",43+ "bat" : "application/x-msdownload",44+ "bin" : "application/octet-stream",45+ "bmp" : "image/bmp",46+ "bz2" : "application/x-bzip2",47+ "c" : "text/x-c",48+ "cab" : "application/vnd.ms-cab-compressed",49+ "cc" : "text/x-c",50+ "chm" : "application/vnd.ms-htmlhelp",51+ "class" : "application/octet-stream",52+ "com" : "application/x-msdownload",53+ "conf" : "text/plain",54+ "cpp" : "text/x-c",55+ "crt" : "application/x-x509-ca-cert",56+ "css" : "text/css",57+ "csv" : "text/csv",58+ "cxx" : "text/x-c",59+ "deb" : "application/x-debian-package",60+ "der" : "application/x-x509-ca-cert",61+ "diff" : "text/x-diff",62+ "djv" : "image/vnd.djvu",63+ "djvu" : "image/vnd.djvu",64+ "dll" : "application/x-msdownload",65+ "dmg" : "application/octet-stream",66+ "doc" : "application/msword",67+ "dot" : "application/msword",68+ "dtd" : "application/xml-dtd",69+ "dvi" : "application/x-dvi",70+ "ear" : "application/java-archive",71+ "eml" : "message/rfc822",72+ "eps" : "application/postscript",73+ "exe" : "application/x-msdownload",74+ "f" : "text/x-fortran",75+ "f77" : "text/x-fortran",76+ "f90" : "text/x-fortran",77+ "flv" : "video/x-flv",78+ "for" : "text/x-fortran",79+ "gem" : "application/octet-stream",80+ "gemspec" : "text/x-script.ruby",81+ "gif" : "image/gif",82+ "gz" : "application/x-gzip",83+ "h" : "text/x-c",84+ "hh" : "text/x-c",85+ "htm" : "text/html",86+ "html" : "text/html",87+ "ico" : "image/vnd.microsoft.icon",88+ "ics" : "text/calendar",89+ "ifb" : "text/calendar",90+ "iso" : "application/octet-stream",91+ "jar" : "application/java-archive",92+ "java" : "text/x-java-source",93+ "jnlp" : "application/x-java-jnlp-file",94+ "jpeg" : "image/jpeg",95+ "jpg" : "image/jpeg",96+ "js" : "application/javascript",97+ "json" : "application/json",98+ "log" : "text/plain",99+ "m3u" : "audio/x-mpegurl",100+ "m4v" : "video/mp4",101+ "man" : "text/troff",102+ "mathml" : "application/mathml+xml",103+ "mbox" : "application/mbox",104+ "mdoc" : "text/troff",105+ "me" : "text/troff",106+ "mid" : "audio/midi",107+ "midi" : "audio/midi",108+ "mime" : "message/rfc822",109+ "mml" : "application/mathml+xml",110+ "mng" : "video/x-mng",111+ "mov" : "video/quicktime",112+ "mp3" : "audio/mpeg",113+ "mp4" : "video/mp4",114+ "mp4v" : "video/mp4",115+ "mpeg" : "video/mpeg",116+ "mpg" : "video/mpeg",117+ "ms" : "text/troff",118+ "msi" : "application/x-msdownload",119+ "odp" : "application/vnd.oasis.opendocument.presentation",120+ "ods" : "application/vnd.oasis.opendocument.spreadsheet",121+ "odt" : "application/vnd.oasis.opendocument.text",122+ "ogg" : "application/ogg",123+ "p" : "text/x-pascal",124+ "pas" : "text/x-pascal",125+ "pbm" : "image/x-portable-bitmap",126+ "pdf" : "application/pdf",127+ "pem" : "application/x-x509-ca-cert",128+ "pgm" : "image/x-portable-graymap",129+ "pgp" : "application/pgp-encrypted",130+ "pkg" : "application/octet-stream",131+ "pl" : "text/x-script.perl",132+ "pm" : "text/x-script.perl-module",133+ "png" : "image/png",134+ "pnm" : "image/x-portable-anymap",135+ "ppm" : "image/x-portable-pixmap",136+ "pps" : "application/vnd.ms-powerpoint",137+ "ppt" : "application/vnd.ms-powerpoint",138+ "ps" : "application/postscript",139+ "psd" : "image/vnd.adobe.photoshop",140+ "py" : "text/x-script.python",141+ "qt" : "video/quicktime",142+ "ra" : "audio/x-pn-realaudio",143+ "rake" : "text/x-script.ruby",144+ "ram" : "audio/x-pn-realaudio",145+ "rar" : "application/x-rar-compressed",146+ "rb" : "text/x-script.ruby",147+ "rdf" : "application/rdf+xml",148+ "roff" : "text/troff",149+ "rpm" : "application/x-redhat-package-manager",150+ "rss" : "application/rss+xml",151+ "rtf" : "application/rtf",152+ "ru" : "text/x-script.ruby",153+ "s" : "text/x-asm",154+ "sgm" : "text/sgml",155+ "sgml" : "text/sgml",156+ "sh" : "application/x-sh",157+ "sig" : "application/pgp-signature",158+ "snd" : "audio/basic",159+ "so" : "application/octet-stream",160+ "svg" : "image/svg+xml",161+ "svgz" : "image/svg+xml",162+ "swf" : "application/x-shockwave-flash",163+ "t" : "text/troff",164+ "tar" : "application/x-tar",165+ "tbz" : "application/x-bzip-compressed-tar",166+ "tcl" : "application/x-tcl",167+ "tex" : "application/x-tex",168+ "texi" : "application/x-texinfo",169+ "texinfo" : "application/x-texinfo",170+ "text" : "text/plain",171+ "tif" : "image/tiff",172+ "tiff" : "image/tiff",173+ "torrent" : "application/x-bittorrent",174+ "tr" : "text/troff",175+ "txt" : "text/plain",176+ "vcf" : "text/x-vcard",177+ "vcs" : "text/x-vcalendar",178+ "vrml" : "model/vrml",179+ "war" : "application/java-archive",180+ "wav" : "audio/x-wav",181+ "wma" : "audio/x-ms-wma",182+ "wmv" : "video/x-ms-wmv",183+ "wmx" : "video/x-ms-wmx",184+ "wrl" : "model/vrml",185+ "wsdl" : "application/wsdl+xml",186+ "xbm" : "image/x-xbitmap",187+ "xhtml" : "application/xhtml+xml",188+ "xls" : "application/vnd.ms-excel",189+ "xml" : "application/xml",190+ "xpm" : "image/x-xpixmap",191+ "xsl" : "application/xml",192+ "xslt" : "application/xslt+xml",193+ "yaml" : "text/yaml",194+ "yml" : "text/yaml",195+ "zip" : "application/zip"196+ }197+ }198+}added:lib/express/session.js+6 added
123456
// Express - Session - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed) Express.Session = { }added:lib/express/view.js+6 added
123456
// Express - View - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed) Express.View = { }deleted:lib/express.cookie.js-48 removed
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
// Express - Cookie - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
Express.Cookie = { name : 'cookie', settings : { maxAge : 3600 }, utilities : { /** * Return cookie _key_. When _value_ is present * then a response cookie field will be set. * * @param {string} key * @param {string} value * @return {string, hash} * @api public */
cookie : function(key, value) { return value ? Express.response.cookie[key] = value : Express.response.cookie[key] } }, onRequest : { 'parse cookie' : function() { Express.response.cookie = Express.request.cookie = Express.parseCookie(Express.requestHeader('Cookie')); } }, onResponse : { 'set cookie' : function() { var cookie = [] for (var key in Express.response.cookie) if (Express.response.cookie.hasOwnProperty(key)) cookie.push(key + '=' + Express.response.cookie[key]) if (cookie.length) Express.header('Set-Cookie', cookie.join('; ')) } } }deleted:lib/express.core.js-685 removed
1-2-// Express - Core - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)3-4-process.mixin(GLOBAL, require("sys"))5-var http = require("http")6-7-Express = { 8- version: '0.0.1',9- utilities: {},10- modules: [],11- routes: [],12- responseCodes : {13- 100: 'Continue',14- 101: 'Switching Protocols',15- 200: 'OK',16- 201: 'Created',17- 202: 'Accepted',18- 203: 'Non-Authoritative Information',19- 204: 'No Content',20- 205: 'Reset Content',21- 206: 'Partial Content',22- 300: 'Multiple Choices',23- 301: 'Moved Permanently',24- 302: 'Moved Temporarily',25- 303: 'See Other',26- 304: 'Not Modified',27- 305: 'Use Proxy',28- 400: 'Bad Request',29- 401: 'Unauthorized',30- 402: 'Payment Required',31- 403: 'Forbidden',32- 404: 'Not Found',33- 405: 'Method Not Allowed',34- 406: 'Not Acceptable',35- 407: 'Proxy Authentication Required',36- 408: 'Request Time-out',37- 409: 'Conflict',38- 410: 'Gone',39- 411: 'Length Required',40- 412: 'Precondition Failed',41- 413: 'Request Entity Too Large',42- 414: 'Request-URI Too Large',43- 415: 'Unsupported Media Type',44- 500: 'Internal Server Error',45- 501: 'Not Implemented',46- 502: 'Bad Gateway',47- 503: 'Service Unavailable',48- 504: 'Gateway Time-out',49- 505: 'HTTP Version not supported'50- },51- 52- // --- Response53- 54- response : {55- headers : {},56- cookie : {}57- },58- 59- // --- Settings60- 61- settings : {62- basepath : '/',63- defaultRoute : {64- callback : function() {65- Express.halt('Page or file cannot be found', 'Not Found')66- }67- }68- },69- 70- // --- Modules71- 72- RedirectHelpers : {73- init : function() {74- Express.home = Express.settings.basepath75- },76- 77- onRequest : {78- 'set back to referrer' : function() {79- Express.back = 80- Express.requestHeader('Referer') ||81- Express.requestHeader('Referrer')82- }83- }84- },85- 86- ContentLength : {87- onResponse : {88- 'set content length' : function() {89- Express.header('Content-Length', (Express.response.body || '').length)90- }91- }92- },93- 94- DefaultContentType : {95- onRequest : {96- 'set response content type to text/html' : function() {97- Express.header('Content-Type', 'text/html')98- }99- }100- },101- 102- BodyDecoder : {103- onRequest : {104- 'parse urlencoded bodies' : function() {105- switch (Express.requestHeader('Content-Type')) {106- case 'application/x-www-form-urlencoded':107- Express.request.uri.params = Express.parseParams(decodeURIComponent(Express.request.body))108- break109- 110- case 'application/json':111- Express.request.uri.params = Express.jsonDecode(Express.request.body)112- break113- }114- }115- }116- },117- 118- MethodOverride : {119- onRequest : {120- 'set HTTP method to _method when present' : function() {121- if (method = Express.param('_method'))122- Express.request.method = method.toUpperCase()123- }124- }125- },126- 127- Logger : {128- onResponse : {129- 'output log data' : function(){130- puts('"' + Express.request.method + ' ' + Express.request.uri.path +131- ' HTTP/' + Express.request.httpVersion + '" - ' + Express.response.status)132- }133- }134- },135- 136- /**137- * Invoke hook _name_ with _args_, returning138- * an array of return values.139- *140- * @param {string} name141- * @param {...} args142- * @return {array}143- * @api public144- */145- 146- hook : function(name, args) {147- var results = []148- for (var i = 0, len = this.modules.length; i < len; ++i)149- for (var key in this.modules[i][name])150- results.push(this.modules[i][name][key].apply(this.modules[i], this.toArray(arguments, 1))) 151- return results152- },153- 154- /**155- * Invoke hook _name_ with _immutable_ and _args_, returning156- * the _immutable_ variable once modified by each hook implementation.157- * When implementing these hooks, the function must return a value.158- *159- * @param {string} name160- * @param {mixed} immutable161- * @param {...} args162- * @return {mixed}163- * @api public164- */165- 166- hookImmutable : function(name, immutable, args) {167- for (var i = 0, len = this.modules.length; i < len; ++i)168- for (var key in this.modules[i][name])169- immutable = this.modules[i][name][key].call(this.modules[i], immutable)170- return immutable171- },172- 173- /**174- * Add _module_.175- *176- * @param {hash} module177- * @param {...} args178- * @api public179- */180- 181- addModule : function(module, args) {182- Express.settings[module.name] = {}183-184- if ('init' in module) 185- module.init.apply(module, Express.toArray(arguments, 1))186-187- if ('settings' in module) {188- if (!module.name) throw 'module name is required when using .settings'189- for (var name in module.settings)190- Express.settings[module.name][name] = module.settings[name]191- }192- 193- if ('utilities' in module)194- for (var name in module.utilities)195- Express.utilities[name] = module.utilities[name]196- 197- Express.modules.push(module)198- },199- 200- /**201- * Start Express; binding to _host_ / _port_.202- *203- * @param {int} port204- * @param {string} host205- * @api public206- */207- 208- start : function(port, host) {209- this.server.listen(port || 3000, host, this.server.callback)210- },211- 212- server : {213- 214- /**215- * Listen to _host_ / _port_ with _callback_.216- *217- * @param {int} port218- * @param {string} host219- * @param {function} callback220- * @api private221- */222- 223- listen : function(port, host, callback) {224- http.createServer(callback).listen(port, host)225- puts('Express started at http://' + (host || '127.0.0.1') + ':' + port + '/')226- },227- 228- /**229- * Request callback.230- *231- * @param {object} request232- * @param {object} response233- * @api private234- */235- 236- callback : function(request, response){237- request.body = request.body || ''238- request.setBodyEncoding('utf8')239- request.addListener('body', function(chunk) { request.body += chunk })240- request.addListener('complete', function(){241- Express.home = Express.settings.basepath242- Express.response.body = null243- Express.response.status = 200244- Express.request = request245- Express.originalResponse = response246- request.uri.params = Express.parseNestedParams(request.uri.params)247- request.uri.path = Express.normalizePath(request.uri.path)248- Express.hook('onRequest')249- try { Express.response.body = Express.callRouteFor(request) }250- catch (e) { Express.fail(e) }251- if (typeof Express.response.body == 'string')252- Express.server.finished()253- })254- },255- 256- finished: function(body) {257- if (body) Express.response.body = body258- Express.hook('onResponse')259- Express.originalResponse.sendHeader(Express.response.status, Express.response.headers)260- Express.originalResponse.sendBody(Express.response.body || '')261- Express.originalResponse.finish()262- }263- },264- 265- /**266- * Fail Express with exception _e_.267- *268- * @param {object} e269- * @api private270- */271-272- fail : function(e) {273- this.hook('onFailure', e)274- this.header('Content-Type', 'text/plain')275- this.response.body = e.message ? e.name + ': ' + e.message : e.toString()276- this.response.status = 500277- },278- 279- /**280- * JSON encode _object_281- *282- * @param {mixed} object283- * @return {string}284- * @api public285- */286- 287- jsonEncode : function(object) {288- return JSON.stringify(object)289- },290- 291- /**292- * JSON decode _string_.293- *294- * @param {string} string295- * @return {mixed}296- * @api public297- */298- 299- jsonDecode : function(string) {300- return JSON.parse(string)301- },302- 303- /**304- * Redirect to _uri_.305- *306- * @param {string} uri307- * @api public308- */309- 310- redirect : function(uri) {311- this.header('Location', uri)312- this.halt("Page or file has moved to `" + uri + "'", 'Moved Temporarily')313- },314- 315- /**316- * Set response status to _value_. Where value may be317- * a case-insensitive string such as 'Not Found', 'forbidden',318- * or a numeric HTTP response status code.319- *320- * @param {int, string} value321- * @return {int}322- * @api public323- */324- 325- status : function(value) {326- if (value == undefined) return327- if (typeof value == 'number') return this.response.status = value328- for (var code in this.responseCodes)329- if (this.responseCodes[code].toLowerCase() == value.toLowerCase())330- return this.response.status = parseInt(code)331- },332-333- /**334- * Return path segment _n_.335- *336- * @param {int} n337- * @return {string}338- * @api public339- */340- 341- arg : function(n) {342- return this.request.uri.path.split('/')[n]343- },344- 345- /**346- * Set response _status_ and _body_. Status347- * defaults to 200.348- *349- * @param {string} body350- * @param {string, int} status351- * @api public352- */353- 354- halt : function(body, status) {355- this.status(status || 200)356- Express.server.finished(this.response.body = body)357- },358- 359- /**360- * Get or set response _name_ header.361- *362- * @param {string} name363- * @param {string} value364- * @return {string}365- * @api public366- */367- 368- header : function(name, value) {369- return value ? 370- this.response.headers[name.toLowerCase()] = value :371- this.response.headers[name.toLowerCase()]372- },373- 374- /**375- * Get request header _name_ optionally providing _default_376- * when _name_ is not present.377- *378- * @param {string} name379- * @param {string} default380- * @return {string}381- * @api public382- */383- 384- requestHeader : function(name, defaultValue) {385- return this.request.headers[name.toLowerCase()] || defaultValue386- },387- 388- /**389- * Return param _key_'s value or _defaultValue_ when390- * the param has not been set.391- *392- * @param {string} key393- * @param {mixed} defaultValue394- * @return {mixed}395- * @api public396- */397- 398- param : function(key, defaultValue) {399- return this.request.uri.params[key] || defaultValue400- },401- 402- /**403- * Parse params _string_ into a nested hash.404- *405- * @param {string} string406- * @return {hash}407- * @api public408- */409- 410- parseParams : function(string) {411- var params = {}, pairs = string.split('&'), pair412- for (var i = 0, len = pairs.length; i < len; ++i) {413- pair = pairs[i].split('=')414- params[pair[0]] = pair[1]415- }416- return this.parseNestedParams(params)417- },418- 419- /**420- * Parse _params_, splitting { user[info][name] : 'tj' } into421- * { user : { info : { name : 'tj' }}}422- *423- * @param {hash} params424- * @return {hash}425- * @api public426- */427- 428- parseNestedParams : function(params) {429- for (var key in params)430- if (parts = key.split('['))431- if (parts.length > 1)432- for (var i = 0, prop = params, len = parts.length; i < len; ++i) {433- var name = parts[i].replace(']', '')434- if (i == len - 1) {435- prop[name] = params[key]436- prop = params, delete params[key]437- }438- else {439- prop = prop[name] = prop[name] || {}440- }441- }442- 443- return params444- },445- 446- /**447- * Parse _cookie_ string into an object (hash).448- *449- * @param {string} cookie450- * @return {hash}451- * @api public452- */453- 454- parseCookie : function(cookie) {455- var hash = {}456- if (!cookie) return hash457- var attrs = cookie.split(/\s*;\s*/)458- for (var i = 0; i < attrs.length; ++i)459- hash[attrs[i].split('=')[0]] = decodeURIComponent(attrs[i].split('=')[1])460- return hash461- },462- 463- /**464- * Normalize a path. Strips trailing / leading whitespace465- * and slashes ('/').466- *467- * @param {string} path468- * @return {string}469- * @api public470- */471- 472- normalizePath : function(path) {473- if (typeof path != 'string') return path474- return path.replace(/^(\s|\/)*|(\s|\/)*$/g, '')475- },476- 477- /**478- * Normalize _path_. When a RegExp it is simply returned,479- * otherwise a string is converted to a regular expression480- * surrounded by ^$. So /user/:id/edit would become:481- *482- * \^/user/(.*?)\/edit\$/483- *484- * Each param key (:id) will be captured and placed in the485- * params array, so param('id') would give the string captured.486- *487- * @param {string} path488- * @return {regexp}489- * @api public490- */491- 492- pathToRegexp : function(path) {493- Express.regexpKeys = []494- if (path.constructor == RegExp) return path495- path = path.replace(/:(\w+)/g, function(_, key){496- Express.regexpKeys.push(key)497- return '(.*?)'498- })499- return new RegExp('^' + this.escapeRegexp(path, '/ [ ]') + '$', 'i')500- },501- 502- /**503- * Escape RegExp _chars_ in _string_. Where _chars_ 504- * defaults to regular expression special characters.505- *506- * _chars_ should be a space delimited list of characters,507- * for example '[ ] ( )'.508- *509- * @param {string} string510- * @param {string} chars511- * @return {Type}512- * @api public513- */514- 515- escapeRegexp : function(string, chars) {516- var specials = (chars || '/ . * + ? | ( ) [ ] { } \\').split(' ').join('|\\')517- return string.replace(new RegExp('(\\' + specials + ')', 'g'), '\\$1')518- },519- 520- /**521- * Return the contents of a function body.522- *523- * @param {function} body524- * @return {string}525- * @api public526- */527- 528- contentsOf : function(body) {529- if (typeof body != 'function') throw "Express.contentsOf(): `" + body + "' is not a function"530- return body.toString().match(/^[^\{]*{((.*\n*)*)}/m)[1]531- },532- 533- /**534- * Eval _string_ in context of Express.535- *536- * @param {string} string537- * @return {mixed}538- * @api public539- */540- 541- eval : function(string) {542- return eval('with (Express){ with (Express.utilities){ ' + string + '}}')543- },544- 545- /**546- * Escape special characters in _html_.547- *548- * @param {string} html549- * @return {string}550- * @api public551- */552- 553- escape : function(html) {554- return html.555- replace(/&/g, '&').556- replace(/"/g, '"').557- replace(/</g, '<').558- replace(/>/g, '>')559- },560- 561- /**562- * Convert native array-like objects into an563- * array with optional _offset_.564- *565- * @param {object} arr566- * @param {int} offset567- * @return {array}568- * @api public569- */570- 571- toArray : function(arr, offset) {572- return Array.prototype.slice.call(arr, offset)573- },574- 575- /**576- * Check if _route_ matches provides the proper577- * encoding types listed in _request_'s Accept header.578- *579- * @param {hash} route580- * @param {hash} request581- * @return {bool}582- * @api private583- */584- 585- routeProvides : function(route, request) {586- if (!route.options.provides) return true587- if (route.options.provides.constructor != Array) 588- route.options.provides = [route.options.provides]589- for (var i = 0, len = route.options.provides.length; i < len; ++i)590- if (request.headers.accept && request.headers.accept.match(route.options.provides[i]))591- return true592- return false593- },594- 595- /**596- * Attept to match and call a route for 597- * the given _request_, returning the data598- * returned by the route callback.599- *600- * @param {object} request601- * @return {mixed}602- * @api private603- */604- 605- callRouteFor : function(request) {606- var route = this.findRouteFor(request) || this.settings.defaultRoute607- if (route.keys)608- for (var i = 0, len = route.keys.length; i < len; ++i) 609- this.request.uri.params[route.keys[i]] = Express.captures[i+1] || null610- var body = this.eval(Express.contentsOf(route.callback))611- if (typeof body != 'string') body = null612- return body613- },614- 615- /**616- * Attempt to find and return a route matching _request_.617- *618- * @param {object} request619- * @return {object}620- * @api private621- */622- 623- findRouteFor : function(request) {624- for (var i = 0, len = this.routes.length; i < len; ++i)625- if (this.routeMatches(this.routes[i], request))626- return this.routes[i]627- },628- 629- /**630- * Check if _route_ matches _request_631- *632- * @param {object} route633- * @param {object} request634- * @return {bool}635- * @api private636- */637- 638- routeMatches : function(route, request) {639- if (request.method.toLowerCase() != route.method) return false640- switch (route.path.constructor) {641- case String: return route.path == request.uri.path642- case RegExp: return !! (Express.captures = request.uri.path.match(route.path))643- }644- },645- 646- /**647- * Return a routing function for _method_.648- *649- * @param {string} method650- * @return {function}651- * @api private652- */653- 654- routeFunctionFor : function(method) {655- return function(path, options, callback) {656- if (options.constructor == Function) callback = options, options = {}657- path = Express.pathToRegexp(Express.normalizePath(path))658- var route = {659- keys : Express.regexpKeys,660- path : path,661- method : method,662- options : options,663- callback : callback664- }665- Express.routes.push(route)666- Express.hook('onRouteAdded', route)667- }668- }669-}670-671-// --- Routing API672-673-get = Express.routeFunctionFor('get')674-post = Express.routeFunctionFor('post')675-del = Express.routeFunctionFor('delete')676-put = Express.routeFunctionFor('put')677-use = Express.addModule678-679-// --- Core Modules680-681-use(Express.BodyDecoder)682-use(Express.MethodOverride)683-use(Express.ContentLength)684-use(Express.DefaultContentType)685-use(Express.RedirectHelpers)modified:lib/express.js+17 added-5 removed
12345623456789101112131415161718
require('express.core')require('express.cookie')require('express.mime')require('express.session')require('express.view')require('express/core')require('express/cookie')require('express/mime')require('express/session')require('express/view')
// --- Core Modules
use(Express.BodyDecoder)use(Express.MethodOverride)use(Express.ContentLength)use(Express.DefaultContentType)use(Express.RedirectHelpers)use(Express.Mime)use(Express.Cookie)use(Express.Session)use(Express.View)deleted:lib/express.mime.js-198 removed
1-2-// Express - Mime - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)3-4-Express.Mime = {5- name : 'mime',6- 7- settings : {8- defaultType : 'application/octet-stream'9- },10- 11- utilities : {12- 13- /**14- * Returns the media type of _ext_, where _ext_ may be an15- * extension ('jpeg') or a file path ('path/to/image.name.jpeg'). 16- * Defaults to Express.settings.mime.defaultType.17- *18- * @param {string} ext19- * @return {string}20- * @api public21- */22- 23- mime : function(ext) {24- if (ext.indexOf('.') != -1) 25- ext = ext.substring(ext.lastIndexOf('.') + 1, ext.length)26- return Express.utilities.mimeTypes[ext] || Express.settings.mime.defaultType27- 28- },29- 30- mimeTypes : {31- "3gp" : "video/3gpp",32- "a" : "application/octet-stream",33- "ai" : "application/postscript",34- "aif" : "audio/x-aiff",35- "aiff" : "audio/x-aiff",36- "asc" : "application/pgp-signature",37- "asf" : "video/x-ms-asf",38- "asm" : "text/x-asm",39- "asx" : "video/x-ms-asf",40- "atom" : "application/atom+xml",41- "au" : "audio/basic",42- "avi" : "video/x-msvideo",43- "bat" : "application/x-msdownload",44- "bin" : "application/octet-stream",45- "bmp" : "image/bmp",46- "bz2" : "application/x-bzip2",47- "c" : "text/x-c",48- "cab" : "application/vnd.ms-cab-compressed",49- "cc" : "text/x-c",50- "chm" : "application/vnd.ms-htmlhelp",51- "class" : "application/octet-stream",52- "com" : "application/x-msdownload",53- "conf" : "text/plain",54- "cpp" : "text/x-c",55- "crt" : "application/x-x509-ca-cert",56- "css" : "text/css",57- "csv" : "text/csv",58- "cxx" : "text/x-c",59- "deb" : "application/x-debian-package",60- "der" : "application/x-x509-ca-cert",61- "diff" : "text/x-diff",62- "djv" : "image/vnd.djvu",63- "djvu" : "image/vnd.djvu",64- "dll" : "application/x-msdownload",65- "dmg" : "application/octet-stream",66- "doc" : "application/msword",67- "dot" : "application/msword",68- "dtd" : "application/xml-dtd",69- "dvi" : "application/x-dvi",70- "ear" : "application/java-archive",71- "eml" : "message/rfc822",72- "eps" : "application/postscript",73- "exe" : "application/x-msdownload",74- "f" : "text/x-fortran",75- "f77" : "text/x-fortran",76- "f90" : "text/x-fortran",77- "flv" : "video/x-flv",78- "for" : "text/x-fortran",79- "gem" : "application/octet-stream",80- "gemspec" : "text/x-script.ruby",81- "gif" : "image/gif",82- "gz" : "application/x-gzip",83- "h" : "text/x-c",84- "hh" : "text/x-c",85- "htm" : "text/html",86- "html" : "text/html",87- "ico" : "image/vnd.microsoft.icon",88- "ics" : "text/calendar",89- "ifb" : "text/calendar",90- "iso" : "application/octet-stream",91- "jar" : "application/java-archive",92- "java" : "text/x-java-source",93- "jnlp" : "application/x-java-jnlp-file",94- "jpeg" : "image/jpeg",95- "jpg" : "image/jpeg",96- "js" : "application/javascript",97- "json" : "application/json",98- "log" : "text/plain",99- "m3u" : "audio/x-mpegurl",100- "m4v" : "video/mp4",101- "man" : "text/troff",102- "mathml" : "application/mathml+xml",103- "mbox" : "application/mbox",104- "mdoc" : "text/troff",105- "me" : "text/troff",106- "mid" : "audio/midi",107- "midi" : "audio/midi",108- "mime" : "message/rfc822",109- "mml" : "application/mathml+xml",110- "mng" : "video/x-mng",111- "mov" : "video/quicktime",112- "mp3" : "audio/mpeg",113- "mp4" : "video/mp4",114- "mp4v" : "video/mp4",115- "mpeg" : "video/mpeg",116- "mpg" : "video/mpeg",117- "ms" : "text/troff",118- "msi" : "application/x-msdownload",119- "odp" : "application/vnd.oasis.opendocument.presentation",120- "ods" : "application/vnd.oasis.opendocument.spreadsheet",121- "odt" : "application/vnd.oasis.opendocument.text",122- "ogg" : "application/ogg",123- "p" : "text/x-pascal",124- "pas" : "text/x-pascal",125- "pbm" : "image/x-portable-bitmap",126- "pdf" : "application/pdf",127- "pem" : "application/x-x509-ca-cert",128- "pgm" : "image/x-portable-graymap",129- "pgp" : "application/pgp-encrypted",130- "pkg" : "application/octet-stream",131- "pl" : "text/x-script.perl",132- "pm" : "text/x-script.perl-module",133- "png" : "image/png",134- "pnm" : "image/x-portable-anymap",135- "ppm" : "image/x-portable-pixmap",136- "pps" : "application/vnd.ms-powerpoint",137- "ppt" : "application/vnd.ms-powerpoint",138- "ps" : "application/postscript",139- "psd" : "image/vnd.adobe.photoshop",140- "py" : "text/x-script.python",141- "qt" : "video/quicktime",142- "ra" : "audio/x-pn-realaudio",143- "rake" : "text/x-script.ruby",144- "ram" : "audio/x-pn-realaudio",145- "rar" : "application/x-rar-compressed",146- "rb" : "text/x-script.ruby",147- "rdf" : "application/rdf+xml",148- "roff" : "text/troff",149- "rpm" : "application/x-redhat-package-manager",150- "rss" : "application/rss+xml",151- "rtf" : "application/rtf",152- "ru" : "text/x-script.ruby",153- "s" : "text/x-asm",154- "sgm" : "text/sgml",155- "sgml" : "text/sgml",156- "sh" : "application/x-sh",157- "sig" : "application/pgp-signature",158- "snd" : "audio/basic",159- "so" : "application/octet-stream",160- "svg" : "image/svg+xml",161- "svgz" : "image/svg+xml",162- "swf" : "application/x-shockwave-flash",163- "t" : "text/troff",164- "tar" : "application/x-tar",165- "tbz" : "application/x-bzip-compressed-tar",166- "tcl" : "application/x-tcl",167- "tex" : "application/x-tex",168- "texi" : "application/x-texinfo",169- "texinfo" : "application/x-texinfo",170- "text" : "text/plain",171- "tif" : "image/tiff",172- "tiff" : "image/tiff",173- "torrent" : "application/x-bittorrent",174- "tr" : "text/troff",175- "txt" : "text/plain",176- "vcf" : "text/x-vcard",177- "vcs" : "text/x-vcalendar",178- "vrml" : "model/vrml",179- "war" : "application/java-archive",180- "wav" : "audio/x-wav",181- "wma" : "audio/x-ms-wma",182- "wmv" : "video/x-ms-wmv",183- "wmx" : "video/x-ms-wmx",184- "wrl" : "model/vrml",185- "wsdl" : "application/wsdl+xml",186- "xbm" : "image/x-xbitmap",187- "xhtml" : "application/xhtml+xml",188- "xls" : "application/vnd.ms-excel",189- "xml" : "application/xml",190- "xpm" : "image/x-xpixmap",191- "xsl" : "application/xml",192- "xslt" : "application/xslt+xml",193- "yaml" : "text/yaml",194- "yml" : "text/yaml",195- "zip" : "application/zip"196- }197- }198-}deleted:lib/express.mocks.js-113 removed
1-2-// Express - Mocks - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)3-4-/**5- * Mock _request_ object. Optionally pass hash of properties.6- *7- * @param {hash} request8- * @return {hash}9- * @api public10- */11-12-function mockRequest(request) {13- var mock = {14- listeners: [],15- method: 'GET',16- headers: {},17- uri: {18- path: '/',19- params: {}20- },21- setBodyEncoding : function(type) {22- this.bodyEncoding = type 23- },24- addListener : function(event, callback) {25- this.listeners.push({ event : event, callback : callback })26- if (event == 'body') {27- var body = this.body28- this.body = ''29- callback(body)30- }31- else32- callback()33- }34- }35- JSpec.extend(mock, request)36- mock.uri.params = mock.uri.params || {}37- return mock38-}39-40-/**41- * Mock _response_ object. Optionally pass hash of properties.42- *43- * @param {hash} response44- * @return {hash}45- * @api public46- */47- 48-function mockResponse(response) {49- var mock = {50- body: null,51- status: 200,52- headers: [],53- sendHeader: function(){},54- sendBody: function(){},55- finish: function(){ this.finished = true }56- }57- JSpec.extend(mock, response)58- return mock59-}60-61-/**62- * Mock server callback.63- *64- * @param {object} request65- * @param {object} response66- * @api private67- */68-69-orig = Express.server.callback70-function mockCallback(request, response) {71- orig(mockRequest(request), mockResponse(response))72-}73-74-/**75- * Mock route function for HTTP _method_.76- *77- * @param {string} method78- * @return {function}79- * @api private80- */81-82-function mockRouteFunctionFor(method) {83- var orig = Express.routeFunctionFor(method)84- return function(path, options, callback) {85- if ((options && options.constructor == Function) || (callback && callback.constructor == Function)) {86- return orig.apply(Express, arguments)87- }88- var request = mockRequest({ method : method.toUpperCase(), uri : { path : path }})89- if (options)90- JSpec.extend(request, options.request),91- request.uri.path = path92- var response = mockResponse()93- Express.server.callback(request, response)94- return Express.response95- }96-}97-98-// --- Module99-100-JSpec.include({101- init : function() {102- Express.server.callback = mockCallback103- },104- 105- utilities : {106- mockRequest : mockRequest,107- mockResponse : mockResponse,108- get : mockRouteFunctionFor('get'),109- post : mockRouteFunctionFor('post'),110- put : mockRouteFunctionFor('put'),111- del : mockRouteFunctionFor('delete')112- }113-})deleted:lib/express.session.js-6 removed
123456
// Express - Session - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed)
Express.Session = { }deleted:lib/express.view.js-6 removed
123456
// Express - View - Copyright TJ Holowaychuk <tj@vision-media.ca> (MIT Licensed) Express.View = { }modified:spec/spec.cookie.js-2 removed
123234540 unmodified lines
use(Express.Cookie)
describe 'Express' describe 'Cookie' before_each Express.routes = []40 unmodified linesmodified:spec/spec.mime.js-2 removed
1 2-use(Express.Mime)3-2 describe 'Express'3 describe 'Mime'4 describe '.mime()'5 it 'should return media type of extensions passed'14 unmodified linesmodified:spec/spec.node.js+1 added-1 removed
1 unmodified line2 process.mixin(GLOBAL, require("sys"))3 4 require("jspec")5 require("express")6-require("express.mocks")6+require("express/spec/mocks")7 8 var posix = require('posix')9 10 quit = process.exit29 unmodified linesmodified:spec/spec.session.js-2 removed
1 2-use(Express.Session)3-2 describe 'Express'3 describe 'Session'4 5 end1 unmodified line