Starting fresh
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parent 24edc4d · Browse files · 17 files·+2 added−1744 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+2 added−1744 removed
- tests:+2 added−789 removed
- other:+0 added−955 removed
Provenance
- Commit
2603bb4- Tree
eaf3202- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
24edc4d
17 files changed+2 added−1744 removed
deleted:lib/express/spec/mocks.js-111 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-var 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- var request = mockRequest({ method: method.toUpperCase(), uri: { path: path }})88- if (options)89- JSpec.extend(request, options.request),90- request.uri.path = path91- Express.server.callback(request, mockResponse())92- return Express.response93- }94-}95-96-// --- Module97-98-JSpec.include({99- init : function() {100- Express.server.callback = mockCallback101- },102- 103- utilities : {104- mockRequest : mockRequest,105- mockResponse : mockResponse,106- get : mockRouteFunctionFor('get'),107- post : mockRouteFunctionFor('post'),108- put : mockRouteFunctionFor('put'),109- del : mockRouteFunctionFor('delete')110- }111-})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-679 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.status('Not Found')66- 'Page or file cannot be found'67- }68- }69- },70- 71- // --- Modules72- 73- RedirectHelpers : {74- init : function() {75- Express.home = Express.settings.basepath76- },77- 78- onRequest : {79- 'set back to referrer' : function() {80- Express.back = 81- Express.requestHeader('Referer') ||82- Express.requestHeader('Referrer')83- }84- }85- },86- 87- ContentLength : {88- onResponse : {89- 'set content length' : function() {90- Express.header('Content-Length', (Express.response.body || '').length)91- }92- }93- },94- 95- DefaultContentType : {96- onRequest : {97- 'set response content type to text/html' : function() {98- Express.header('Content-Type', 'text/html')99- }100- }101- },102- 103- BodyDecoder : {104- onRequest : {105- 'parse urlencoded bodies' : function() {106- switch (Express.requestHeader('Content-Type')) {107- case 'application/x-www-form-urlencoded':108- Express.request.uri.params = Express.parseParams(decodeURIComponent(Express.request.body))109- break110- 111- case 'application/json':112- Express.request.uri.params = Express.jsonDecode(Express.request.body)113- break114- }115- }116- }117- },118- 119- MethodOverride : {120- onRequest : {121- 'set HTTP method to _method when present' : function() {122- if (method = Express.param('_method'))123- Express.request.method = method.toUpperCase()124- }125- }126- },127- 128- Logger : {129- onResponse : {130- 'output log data' : function(){131- puts('"' + Express.request.method + ' ' + Express.request.uri.path +132- ' HTTP/' + Express.request.httpVersion + '" - ' + Express.response.status)133- }134- }135- },136- 137- /**138- * Invoke hook _name_ with _args_, returning139- * an array of return values.140- *141- * @param {string} name142- * @param {...} args143- * @return {array}144- * @api public145- */146- 147- hook : function(name, args) {148- var results = []149- for (var i = 0, len = this.modules.length; i < len; ++i)150- for (var key in this.modules[i][name])151- results.push(this.modules[i][name][key].apply(this.modules[i], this.toArray(arguments, 1))) 152- return results153- },154- 155- /**156- * Invoke hook _name_ with _immutable_ and _args_, returning157- * the _immutable_ variable once modified by each hook implementation.158- * When implementing these hooks, the function must return a value.159- *160- * @param {string} name161- * @param {mixed} immutable162- * @param {...} args163- * @return {mixed}164- * @api public165- */166- 167- hookImmutable : function(name, immutable, args) {168- for (var i = 0, len = this.modules.length; i < len; ++i)169- for (var key in this.modules[i][name])170- immutable = this.modules[i][name][key].call(this.modules[i], immutable)171- return immutable172- },173- 174- /**175- * Add _module_.176- *177- * @param {hash} module178- * @param {...} args179- * @api public180- */181- 182- addModule : function(module, args) {183- Express.settings[module.name] = {}184-185- if ('init' in module) 186- module.init.apply(module, Express.toArray(arguments, 1))187-188- if ('settings' in module) {189- if (!module.name) throw 'module name is required when using .settings'190- for (var name in module.settings)191- Express.settings[module.name][name] = module.settings[name]192- }193- 194- if ('utilities' in module)195- for (var name in module.utilities)196- Express.utilities[name] = module.utilities[name]197- 198- Express.modules.push(module)199- },200- 201- /**202- * Start Express; binding to _host_ / _port_.203- *204- * @param {int} port205- * @param {string} host206- * @api public207- */208- 209- start : function(port, host) {210- this.server.listen(port || 3000, host, this.server.callback)211- },212- 213- server : {214- 215- /**216- * Listen to _host_ / _port_ with _callback_.217- *218- * @param {int} port219- * @param {string} host220- * @param {function} callback221- * @api private222- */223- 224- listen : function(port, host, callback) {225- http.createServer(callback).listen(port, host)226- puts('Express started at http://' + (host || '127.0.0.1') + ':' + port + '/')227- },228- 229- /**230- * Request callback.231- *232- * @param {object} request233- * @param {object} response234- * @api private235- */236- 237- callback : function(request, response){238- request.body = request.body || ''239- request.setBodyEncoding('utf8')240- request.addListener('body', function(chunk) { request.body += chunk })241- request.addListener('complete', function(){242- Express.home = Express.settings.basepath243- Express.response.body = null244- Express.response.status = 200245- Express.request = request246- Express.originalResponse = response247- request.uri.params = Express.parseNestedParams(request.uri.params)248- request.uri.path = Express.normalizePath(request.uri.path)249- Express.hook('onRequest')250- try { Express.response.body = Express.callRouteFor(request) }251- catch (e) { Express.fail(e) }252- if (typeof Express.response.body == 'string')253- Express.server.finished()254- })255- },256- 257- finished: function(body) {258- if (body) Express.response.body = body259- Express.hook('onResponse')260- Express.originalResponse.sendHeader(Express.response.status, Express.response.headers)261- Express.originalResponse.sendBody(Express.response.body || '')262- Express.originalResponse.finish()263- }264- },265- 266- /**267- * Fail Express with exception _e_.268- *269- * @param {object} e270- * @api private271- */272-273- fail : function(e) {274- this.hook('onFailure', e)275- this.header('Content-Type', 'text/plain')276- this.response.body = e.message ? e.name + ': ' + e.message : e.toString()277- this.response.status = 500278- },279- 280- /**281- * JSON encode _object_282- *283- * @param {mixed} object284- * @return {string}285- * @api public286- */287- 288- jsonEncode : function(object) {289- return JSON.stringify(object)290- },291- 292- /**293- * JSON decode _string_.294- *295- * @param {string} string296- * @return {mixed}297- * @api public298- */299- 300- jsonDecode : function(string) {301- return JSON.parse(string)302- },303- 304- /**305- * Redirect to _uri_.306- *307- * @param {string} uri308- * @api public309- */310- 311- redirect : function(uri) {312- this.header('Location', uri)313- this.halt("Page or file has moved to `" + uri + "'", 'Moved Temporarily')314- },315- 316- /**317- * Set response status to _value_. Where value may be318- * a case-insensitive string such as 'Not Found', 'forbidden',319- * or a numeric HTTP response status code.320- *321- * @param {int, string} value322- * @return {int}323- * @api public324- */325- 326- status : function(value) {327- if (value == undefined) return328- if (typeof value == 'number') return this.response.status = value329- for (var code in this.responseCodes)330- if (this.responseCodes[code].toLowerCase() == value.toLowerCase())331- return this.response.status = parseInt(code)332- },333-334- /**335- * Return path segment _n_.336- *337- * @param {int} n338- * @return {string}339- * @api public340- */341- 342- arg : function(n) {343- return this.request.uri.path.split('/')[n]344- },345- 346- /**347- * Set response _status_ and _body_. Status348- * defaults to 200.349- *350- * @param {string} body351- * @param {string, int} status352- * @api public353- */354- 355- halt : function(body, status) {356- this.status(status || 200)357- Express.server.finished(body)358- },359- 360- /**361- * Get or set response _name_ header.362- *363- * @param {string} name364- * @param {string} value365- * @return {string}366- * @api public367- */368- 369- header : function(name, value) {370- return value ? 371- this.response.headers[name.toLowerCase()] = value :372- this.response.headers[name.toLowerCase()]373- },374- 375- /**376- * Get request header _name_ optionally providing _default_377- * when _name_ is not present.378- *379- * @param {string} name380- * @param {string} default381- * @return {string}382- * @api public383- */384- 385- requestHeader : function(name, defaultValue) {386- return this.request.headers[name.toLowerCase()] || defaultValue387- },388- 389- /**390- * Return param _key_'s value or _defaultValue_ when391- * the param has not been set.392- *393- * @param {string} key394- * @param {mixed} defaultValue395- * @return {mixed}396- * @api public397- */398- 399- param : function(key, defaultValue) {400- return this.request.uri.params[key] || defaultValue401- },402- 403- /**404- * Parse params _string_ into a nested hash.405- *406- * @param {string} string407- * @return {hash}408- * @api public409- */410- 411- parseParams : function(string) {412- var params = {}, pairs = string.split('&'), pair413- for (var i = 0, len = pairs.length; i < len; ++i) {414- pair = pairs[i].split('=')415- params[pair[0]] = pair[1]416- }417- return this.parseNestedParams(params)418- },419- 420- /**421- * Parse _params_, splitting { user[info][name] : 'tj' } into422- * { user : { info : { name : 'tj' }}}423- *424- * @param {hash} params425- * @return {hash}426- * @api public427- */428- 429- parseNestedParams : function(params) {430- for (var key in params)431- if (parts = key.split('['))432- if (parts.length > 1)433- for (var i = 0, prop = params, len = parts.length; i < len; ++i) {434- var name = parts[i].replace(']', '')435- if (i == len - 1) {436- prop[name] = params[key]437- prop = params, delete params[key]438- }439- else {440- prop = prop[name] = prop[name] || {}441- }442- }443- 444- return params445- },446- 447- /**448- * Parse _cookie_ string into an object (hash).449- *450- * @param {string} cookie451- * @return {hash}452- * @api public453- */454- 455- parseCookie : function(cookie) {456- var hash = {}457- if (!cookie) return hash458- var attrs = cookie.split(/\s*;\s*/)459- for (var i = 0; i < attrs.length; ++i)460- hash[attrs[i].split('=')[0]] = decodeURIComponent(attrs[i].split('=')[1])461- return hash462- },463- 464- /**465- * Normalize a path. Strips trailing / leading whitespace466- * and slashes ('/').467- *468- * @param {string} path469- * @return {string}470- * @api public471- */472- 473- normalizePath : function(path) {474- if (typeof path != 'string') return path475- return path.replace(/^(\s|\/)*|(\s|\/)*$/g, '')476- },477- 478- /**479- * Normalize _path_. When a RegExp it is simply returned,480- * otherwise a string is converted to a regular expression481- * surrounded by ^$. So /user/:id/edit would become:482- *483- * \^/user/(.*?)\/edit\$/484- *485- * Each param key (:id) will be captured and placed in the486- * params array, so param('id') would give the string captured.487- *488- * @param {string} path489- * @return {regexp}490- * @api public491- */492- 493- pathToRegexp : function(path) {494- Express.regexpKeys = []495- if (path.constructor == RegExp) return path496- path = path.replace(/:(\w+)/g, function(_, key){497- Express.regexpKeys.push(key)498- return '(.*?)'499- })500- return new RegExp('^' + this.escapeRegexp(path, '/ [ ]') + '$', 'i')501- },502- 503- /**504- * Escape RegExp _chars_ in _string_. Where _chars_ 505- * defaults to regular expression special characters.506- *507- * _chars_ should be a space delimited list of characters,508- * for example '[ ] ( )'.509- *510- * @param {string} string511- * @param {string} chars512- * @return {Type}513- * @api public514- */515- 516- escapeRegexp : function(string, chars) {517- var specials = (chars || '/ . * + ? | ( ) [ ] { } \\').split(' ').join('|\\')518- return string.replace(new RegExp('(\\' + specials + ')', 'g'), '\\$1')519- },520- 521- /**522- * Return the contents of a function body.523- *524- * @param {function} body525- * @return {string}526- * @api public527- */528- 529- contentsOf : function(body) {530- if (typeof body != 'function') throw "Express.contentsOf(): `" + body + "' is not a function"531- return body.toString().match(/^[^\{]*{((.*\n*)*)}/m)[1]532- },533- 534- /**535- * Eval _string_ in context of Express.536- *537- * @param {string} string538- * @return {mixed}539- * @api public540- */541- 542- eval : function(string) {543- return eval('with (Express){ with (Express.utilities){ ' + string + '}}')544- },545- 546- /**547- * Escape special characters in _html_.548- *549- * @param {string} html550- * @return {string}551- * @api public552- */553- 554- escape : function(html) {555- return html.556- replace(/&/g, '&').557- replace(/"/g, '"').558- replace(/</g, '<').559- replace(/>/g, '>')560- },561- 562- /**563- * Convert native array-like objects into an564- * array with optional _offset_.565- *566- * @param {object} arr567- * @param {int} offset568- * @return {array}569- * @api public570- */571- 572- toArray : function(arr, offset) {573- return Array.prototype.slice.call(arr, offset)574- },575- 576- /**577- * Check if _route_ matches provides the proper578- * encoding types listed in _request_'s Accept header.579- *580- * @param {hash} route581- * @param {hash} request582- * @return {bool}583- * @api private584- */585- 586- routeProvides : function(route, request) {587- if (!route.options.provides) return true588- if (route.options.provides.constructor != Array) 589- route.options.provides = [route.options.provides]590- for (var i = 0, len = route.options.provides.length; i < len; ++i)591- if (request.headers.accept && request.headers.accept.match(route.options.provides[i]))592- return true593- return false594- },595- 596- /**597- * Attept to match and call a route for 598- * the given _request_, returning the data599- * returned by the route callback.600- *601- * @param {object} request602- * @return {mixed}603- * @api private604- */605- 606- callRouteFor : function(request) {607- var route = this.findRouteFor(request) || this.settings.defaultRoute608- if (route.keys)609- for (var i = 0, len = route.keys.length; i < len; ++i) 610- this.request.uri.params[route.keys[i]] = Express.captures[i+1] || null611- var body = this.eval(Express.contentsOf(route.callback))612- if (typeof body != 'string') body = null613- return body614- },615- 616- /**617- * Attempt to find and return a route matching _request_.618- *619- * @param {object} request620- * @return {object}621- * @api private622- */623- 624- findRouteFor : function(request) {625- for (var i = 0, len = this.routes.length; i < len; ++i)626- if (this.routeMatches(this.routes[i], request))627- return this.routes[i]628- },629- 630- /**631- * Check if _route_ matches _request_632- *633- * @param {object} route634- * @param {object} request635- * @return {bool}636- * @api private637- */638- 639- routeMatches : function(route, request) {640- if (request.method.toLowerCase() != route.method) return false641- switch (route.path.constructor) {642- case String: return route.path == request.uri.path643- case RegExp: return !! (Express.captures = request.uri.path.match(route.path))644- }645- },646- 647- /**648- * Return a routing function for _method_.649- *650- * @param {string} method651- * @return {function}652- * @api private653- */654- 655- routeFunctionFor : function(method) {656- return function(path, options, callback) {657- if (options.constructor == Function) callback = options, options = {}658- path = Express.pathToRegexp(Express.normalizePath(path))659- var route = {660- keys : Express.regexpKeys,661- path : path,662- method : method,663- options : options,664- callback : callback665- }666- Express.routes.push(route)667- Express.hook('onRouteAdded', route)668- }669- }670-}671-672-// --- Routing API673-674-get = Express.routeFunctionFor('get')675-post = Express.routeFunctionFor('post')676-del = Express.routeFunctionFor('delete')677-put = Express.routeFunctionFor('put')678-use = Express.addModule679-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/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:lib/express.js-18 removed
123456789101112131415161718
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:spec/spec.async.js-32 removed
1234567891011121314151617181920212223242526272829303132
describe 'Express' describe 'server' before_each Express.routes = [] end
describe 'callback' it 'should wait for an asynchronous handler to finish' require('jspec.timers') get('pants', function() { setTimeout(function() { halt('asynchronous thing done') }, 50) }) var response = get('pants') response.body.should.be_null tick(50) response.body.should.eql 'asynchronous thing done' response.status.should.eql 200 response.headers['content-type'].should.eql 'text/html' end it 'should still accept a synchronous handler that returns a string' get('pants', function() { 'no pants' }) get('pants').body.should.eql 'no pants' end end endend
deleted:spec/spec.cookie.js-45 removed
123456789101112131415161718192021222324252627282930313233343536373839404142434445
describe 'Express' describe 'Cookie' before_each Express.routes = [] end describe 'settings' it 'should maxAge' Express.settings.cookie.maxAge.should.be_a Number end end describe 'onRequest' it 'should parse cookie fields' get('foo', function() { cookie('q') }) request = mockRequest({ headers : { 'cookie': 'path=/; q=something; domain=.example.net' } }) response = get('foo', { request: request }) response.body.should.eql 'something' end end describe 'utilities' describe 'cookie()' before_each Express.response.cookie = Express.parseCookie('path=/; q=foo%3dbar; domain=.example.net') end
it 'should return cookie value when key passed' Express.Cookie.utilities.cookie('path').should.eql '/' Express.Cookie.utilities.cookie('domain').should.eql '.example.net' end
it 'should set response cookies when value passed' Express.Cookie.utilities.cookie('foo', 'bar') Express.Cookie.utilities.cookie('foo').should.eql 'bar' end end end endendmodified:spec/spec.core.js+2 added-232 removed
1+2 describe 'Express'2- before_each3- Express.routes = []4- end5- 3 describe '.version'4 it 'should be properly formatted'8- Express.version.should.match /\d+\.\d+\.\d+/5+ Express.version.should.match(/^\d+\.\d+\.\d+$/)6 end7 end11- 12- describe '.parseParams()'13- it 'should parse a string of parameters'14- string = 'user[name]=tj&user[pass]=test&foo=some bar stuff&cookies=awesome'15- params = Express.parseParams(string)16- params.user.name.should.eql 'tj'17- params.user.pass.should.eql 'test'18- params.foo.should.eql 'some bar stuff'19- params.cookies.should.eql 'awesome'20- end21- end22- 23- describe '.parseNestedParams()'24- it 'should parse nested params hash provided by node'25- params = { 'foo' : 'bar', 'user[name]' : 'tj', 'user[info][email]' : 'tj@vision-media.ca', 'user[info][city]' : 'Victoria' }26- nested = Express.parseNestedParams(params)27- nested.foo.should.eql 'bar'28- nested.user.name.should.eql 'tj'29- nested.user.info.email.should.eql 'tj@vision-media.ca'30- nested.user.info.city.should.eql 'Victoria'31- end32- end33- 34- describe '.parseCookie()'35- it 'should parse cookie pairs'36- var cookie = 'expires=Fri, 31-Dec-2010 23:59:59 GMT; path=/; q=foo%3dbar; domain=example.net'37- parts = Express.parseCookie(cookie)38- parts.expires.should.eql 'Fri, 31-Dec-2010 23:59:59 GMT'39- parts.path.should.eql '/'40- parts.q.should.eql 'foo=bar'41- parts.domain.should.eql 'example.net'42- end43- end44- 45- describe '.toArray()'46- it 'should return an array of arguments'47- Express.toArray(-{ return arguments }('foo', 'bar')).should.eql ['foo', 'bar']48- end49- 50- it 'should allow an offset'51- Express.toArray(-{ return arguments }('foo', 'bar'), 1).should.eql ['bar']52- end53- end54- 55- describe '.escape()'56- it 'should escape html'57- Express.escape('<>&""').should.eql '<>&""'58- end59- end60- 61- describe '.escapeRegexp()'62- it 'should escape regexp special characters'63- Express.escapeRegexp('/users/(name)').should.eql '\\/users\\/\\(name\\)'64- end65- 66- it 'should accept a string of space-delimited characters'67- Express.escapeRegexp('/foo/#bar?user[name]=tj', '/ [ ]').should.eql '\\/foo\\/#bar?user\\[name\\]=tj'68- end69- end70- 71- describe '.contentsOf()'72- it 'should return the body of a function as a string'73- Express.contentsOf(function(){ return 'foo' }).should.include 'return', 'foo'74- end75- end76- 77- describe '.header()'78- it 'should set / get headers'79- Express.header('Content-Type', 'text/html')80- Express.header('Content-Type').should.eql 'text/html'81- Express.header('content-type').should.eql 'text/html'82- end83- end84- 85- describe '.arg()'86- it 'should return the given path segment'87- Express.request = mockRequest({ uri : { path : 'some/foo-bar/baz' }})88- Express.arg(0).should.eql 'some'89- Express.arg(1).should.eql 'foo-bar'90- Express.arg(2).should.eql 'baz'91- end92- 93- it 'should return null when segment does not exist'94- Express.arg(12).should.be_null95- end96- end97- 98- describe '.status()'99- after_each100- Express.response.status = 200101- end102- 103- it 'should set response status code by number'104- Express.status(404)105- Express.response.status.should.eql 404106- end107- 108- it 'should set using the status string map'109- Express.status('Not Found')110- Express.response.status.should.eql 404111- end112- 113- it 'should be case insensitive'114- Express.status('forbidden')115- Express.response.status.should.eql 403116- end117- end118- 119- describe '.halt()'120- after_each121- Express.response.status = 200122- end123- 124- it 'should default response status to 200'125- get('/foo', function(){126- halt('Foo bar')127- })128- get('/foo').status.should.eql 200129- get('/foo').body.should.eql 'Foo bar'130- end131- 132- it 'should set response status and body'133- get('/foo', function(){134- halt('Page or file cannot be found', 'Not Found')135- })136- get('/foo').status.should.eql 404137- get('/foo').body.should.eql 'Page or file cannot be found'138- end139- 140- it 'should allow specific status to be passed'141- get('/foo', function(){142- halt('Page or file cannot be found', 'Not Found')143- })144- get('/foo').status.should.eql 404145- get('/foo').body.should.eql 'Page or file cannot be found'146- end147- end148-149- describe '.redirect()'150- it 'should redirect to the url specified'151- get('foo', function(){ redirect('http://google.com') })152- response = get('foo')153- response.headers.location.should.eql 'http://google.com'154- response.status.should.eql 302155- end156- end157- 158- describe 'RedirectHelpers'159- before_each160- Express.response.headers = {}161- end162- 163- describe '.home'164- it 'should redirect home'165- get('foo', function(){ redirect(home) })166- get('foo').headers.location.should.eql '/'167- end168- 169- it 'should not always set location'170- get('foo', function(){ 'bar' })171- get('foo').headers.should.not.have_property 'location'172- end173- end174- 175- describe '.back'176- it 'should redirect to the referrer'177- uri = 'http://vision-media.ca'178- get('foo', function(){ redirect(back) })179- request = mockRequest({ headers : { 'referer': uri }})180- get('foo', { request: request }).headers.location.should.eql uri181- Express.back.should.eql uri182- end183- end184- end185- 186- describe 'BodyDecoder'187- it 'should parse urlencoded bodies'188- request = mockRequest({189- method: 'POST',190- headers : { 'content-type': 'application/x-www-form-urlencoded' },191- body : 'user[name]=foo%20bar&status=1'192- })193- post('admin', function(){ param('user').name + ' ' + param('status') })194- post('admin', { request : request }).body.should.eql 'foo bar 1'195- end196-197- it 'should parse JSON bodies'198- request = mockRequest({199- method: 'POST',200- headers : { 'content-type': 'application/json' },201- body : '{ foo : "bar" }'202- })203- post('foo', function(){ param('foo') })204- post('foo', { request : request }).body.should.eql 'bar'205- end206- end207- 208- describe 'ContentLength'209- it 'should set the content length header'210- get('foo', function(){ 'foo bar' })211- get('foo').headers['content-length'].should.eql 7212- end213- end214- 215- describe 'MethodOverride'216- it 'should override request method when _method param is present'217- request = mockRequest({218- method: 'POST',219- headers : { 'content-type': 'application/x-www-form-urlencoded' },220- body : '_method=delete'221- })222- del('foo', function(){ 'Deleted' })223- post('foo', { request : request}).body.should.eql 'Deleted'224- end225- end226- 227- describe 'DefaultContentType'228- it 'should default to text/html'229- get('foo', function(){ 'bar' })230- get('foo').headers['content-type'].should.eql 'text/html'231- end232- 233- it 'should be overridable'234- get('foo', function(){ header('Content-Type', 'application/json'); 'bar' })235- get('foo').headers['content-type'].should.eql 'application/json'236- end237- end8 enddeleted:spec/spec.mime.js-19 removed
12345678910111213141516171819
describe 'Express' describe 'Mime' describe '.mime()' it 'should return media type of extensions passed' Express.utilities.mime('jpeg').should.eql 'image/jpeg' end
it 'should return application/octet-stream when invalid' Express.utilities.mime('foobar').should.eql 'application/octet-stream' end
it 'should parse extension of basename or path passed' Express.utilities.mime('images/profile.png').should.eql 'image/png' Express.utilities.mime('foo.bar.something-else.png').should.eql 'image/png' end end endendNo newline at end of filedeleted:spec/spec.mocks.js-73 removed
1-2-describe 'Express'3- describe 'Mocks'4- before_each5- Express.routes = []6- end7- 8- describe 'mockRequest()'9- it 'should return a mock request'10- mockRequest().method.should.eql 'GET'11- end12- 13- it 'should merge hash passed'14- mockRequest({ method : 'POST' }).method.should.eql 'POST'15- end16- end17- 18- describe 'mockResponse()'19- it 'should return a mock response'20- mockResponse().status.should.eql 20021- end22- 23- it 'should merge hash passed'24- mockResponse({ status : 404 }).status.should.eql 40425- end26- end27- 28- describe 'get()'29- it 'should get route when available'30- get('users', function(){ 'User list' })31- get('users').body.should.eql 'User list'32- get('other').status.should.eql 40433- end34- end35- 36- describe 'post()'37- it 'should post route when available'38- post('users/delete', function(){ 'Users deleted' })39- post('users/delete').body.should.eql 'Users deleted'40- post('other').status.should.eql 404 41- end42- end43-44- describe 'put()'45- it 'should put route when available'46- put('user/update', function(){ 'Updated' })47- put('user/update').body.should.eql 'Updated'48- put('other').status.should.eql 404 49- end50- end51- 52- describe 'del()'53- it 'should delete route when available'54- del('user', function(){ 'Deleted' })55- del('user').body.should.eql 'Deleted'56- del('other').status.should.eql 404 57- end58- end59- 60- describe 'options'61- it 'should allow request to be passed'62- post('article', function(){ request.test })63- post('article', { request : { test : '1' }}).body.should.eql '1'64- end65-66- it 'should override request body'67- post('article', function(){ request.body })68- post('article', { request : { body : 'foo' }}).body.should.eql 'foo'69- end70- end71-72- end73-enddeleted:spec/spec.modules.js-87 removed
1-2-use({3- name : 'foo',4- init : function(a, b) {5- argA = a, argB = b6- initCalled = true7- initContext = this8- },9- 10- settings : {11- one : 1,12- two : 213- },14- 15- utilities : {16- foo : function(){17- return 'bar'18- }19- },20- 21- onFoo : {22- 'return bar' : function(one, two) {23- return 'bar ' + one + ' ' + two24- }25- },26- 27- onFooImmutable : {28- 'test one' : function(immutable, arg) {29- return 'one ' + immutable30- },31- 32- 'test two' : function(immutable, arg) {33- return immutable + ' two'34- }35- }36-}, 'foo', 'bar')37-38-describe 'Express'39- describe 'Modules'40- before_each41- Express.routes = []42- end43- 44- it 'should call init when passed to use()'45- initCalled.should.be_true46- end47- 48- it 'should pass args to init'49- argA.should.eql 'foo'50- argB.should.eql 'bar'51- end52- 53- it 'should have module context'54- initContext.name.should.eql 'foo'55- end56- 57- it 'should merge utilities'58- Express.utilities.foo().should.eql 'bar'59- end60- 61- it 'should expose utilities to routes'62- get('foo', function(){ foo() })63- get('foo').body.should.eql 'bar'64- end65- 66- it 'should merge settings'67- Express.settings.foo.one.should.eql 168- Express.settings.foo.two.should.eql 269- end70- 71- it 'should throw error when trying to merge settings without module name'72- -{ use({ settings : { foo : 'bar' }}) }.should.throw_error(/module name is required/)73- end74- 75- describe 'hook()'76- it 'should call hook implementations returning an array of results'77- Express.hook('onFoo', 'test', 'stuff').should.eql ['bar test stuff']78- end79- end80- 81- describe 'hookImmutable'82- it 'should call hook implementations sequencially passing the first argument passed'83- Express.hookImmutable('onFooImmutable', 'test').should.eql 'one test two'84- end85- end86- end87-enddeleted:spec/spec.node.js-39 removed
1-require.paths.unshift("./spec/lib", "./lib");2-process.mixin(GLOBAL, require("sys"))3-4-require("jspec")5-require("express")6-require("express/spec/mocks")7-8-var posix = require('posix')9-10-quit = process.exit11-print = puts12-13-readFile = function(path) {14- var promise = posix.cat(path, "utf8")15- var result = ''16- promise.addErrback(function(){ throw "failed to read file `" + path + "'" })17- promise.addCallback(function(contents){18- result = contents19- })20- promise.wait()21- return result22-}23-24-if (process.ARGV[2])25- JSpec.exec('spec/spec.' + process.ARGV[2] + '.js') 26-else27- JSpec28- .exec('spec/spec.core.js')29- .exec('spec/spec.routing.js')30- .exec('spec/spec.mocks.js')31- .exec('spec/spec.modules.js')32- .exec('spec/spec.mime.js')33- .exec('spec/spec.cookie.js')34- .exec('spec/spec.session.js')35- .exec('spec/spec.view.js') 36- .exec('spec/spec.async.js')37-JSpec.run({ formatter: JSpec.formatters.Terminal, failuresOnly: true })38-JSpec.report()39-deleted:spec/spec.routing.js-139 removed
1-2-describe 'Express'3- describe 'routing'4- describe '.routeFunctionFor()'5- it 'should return a routing function'6- Express.routes = []7- foo = Express.routeFunctionFor('get')8- foo('/some/path', function(){ return 'body' })9- foo('/something/else', function(){ return 'body' })10- Express.routes.should.have_length 211- end12- end13- 14- describe '.normalizePath()'15- it 'should strip leading / trailing slashes'16- Express.normalizePath('/foo/bar/').should.eql 'foo/bar'17- end18-19- it 'should strip leading / trailing whitespace'20- Express.normalizePath(' /foo/').should.eql 'foo'21- end22- end23- 24- describe '.routeProvides()'25- it 'should match a route providing the correct encoding'26- route = { options : {}}27- request = mockRequest({ headers : { 'accept' : 'text/html' }})28- Express.routeProvides(route, request).should.be_true29- route = { options : { provides : 'text/html' }}30- request = mockRequest({ headers : { 'accept' : 'application/javascript,text/html,text/plain' }})31- Express.routeProvides(route, request).should.be_true32- request = mockRequest({ headers : { 'accept' : 'text/plain' }})33- Express.routeProvides(route, request).should.be_false34- route.options.provides = 'text/plain'35- Express.routeProvides(route, request).should.be_true36- route.options.provides = ['text/html', 'text/plain']37- Express.routeProvides(route, request).should.be_true38- end39- end40- 41- describe '.routeMatches()'42- before_each43- request = mockRequest({ uri : { path : '/user/1/edit' }})44- end45- 46- it 'should return true when the route passed is valid for the request passed'47- route = { path : '/user/1/edit', method : 'get' }48- Express.routeMatches(route, request).should.be_true49- end50- 51- it 'should return false when method is incorrect'52- route = { path : '/user/1/edit', method : 'post' }53- Express.routeMatches(route, request).should.be_false54- end55- 56- it 'should return false when path is invalid'57- route = { path : '/user/1', method : 'get' }58- Express.routeMatches(route, request).should.be_false59- end60- 61- it 'should return true when path is a valid regexp'62- route = { path : /user\/(\d+)\/edit/, method : 'get' }63- Express.routeMatches(route, request).should.be_true64- end65- 66- it 'should return false when path is invalid regexp'67- route = { path : /user\/(\d+)\/view/, method : 'get' }68- Express.routeMatches(route, request).should.be_false69- end70- end71- 72- describe '.pathToRegexp()'73- it 'should return a regexp with capture groups when using the :foo syntax'74- Express.pathToRegexp('/user/:name').should.eql(/^\/user\/(.*?)$/i)75- Express.regexpKeys.should.have_length 176- Express.pathToRegexp('/user/:name/edit').should.eql(/^\/user\/(.*?)\/edit$/i)77- Express.regexpKeys.should.have_length 178- end79- 80- it 'should populate Express.regexpKeys with key names'81- Express.pathToRegexp('user/:name/:op')82- Express.regexpKeys.should.eql ['name', 'op']83- Express.pathToRegexp('admin/:page')84- Express.regexpKeys.should.eql ['page']85- end86- end87- 88- describe 'restful functions'89- before_each90- Express.routes = []91- end92- 93- it 'should set last expression as response body'94- get('user', function(){ 'tj' })95- get('user').body.should.eql 'tj'96- end97- 98- it 'should disregard leading and trailing slashes'99- get('/one', function(){ 'tj' })100- get('one').body.should.eql 'tj'101- 102- get('/two/', function(){ 'tj' })103- get('two').body.should.eql 'tj'104- 105- get('three/', function(){ 'tj' })106- get('three').body.should.eql 'tj'107- end108- 109- it 'should populate params hash when using param keys'110- get('/user/:name', function(){ param('name') })111- get('/user/tj').body.should.eql 'tj'112- get('/user/joe').body.should.eql 'joe'113- end114- 115- it 'should populate several param keys'116- get('/admin/:section/:page', function(){117- param('section') + ' ' + param('page')118- })119- get('admin/report/users').body.should.eql 'report users'120- end121- 122- it 'should match strings literally'123- get('foo', function(){ 'bar' })124- var response = get('foobar')125- response.status.should.eql 404126- response.body.should.eql 'Page or file cannot be found'127- end128- 129- it 'should match using regexp and populate captures array'130- get(/foo(bar)?/, function(){131- captures[1] ? 'got bar' : 'no bar'132- })133- get('foo').body.should.eql 'no bar'134- get('foobar').body.should.eql 'got bar'135- end136- end137- 138- end139-enddeleted:spec/spec.session.js-6 removed
1-2-describe 'Express'3- describe 'Session'4- 5- end6-enddeleted:spec/spec.view.js-6 removed
1-2-describe 'Express'3- describe 'View'4- 5- end6-end