Skip to content

Instantly share code, notes, and snippets.

@carmonac
Created March 28, 2015 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carmonac/9469c4798469bc15e644 to your computer and use it in GitHub Desktop.
Save carmonac/9469c4798469bc15e644 to your computer and use it in GitHub Desktop.
Chat para post de openwebinars
This gist exceeds the recommended number of files (~10). To access all files, please clone this gist.
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
<component name="ProjectDictionaryState">
<dictionary name="careuno" />
</component>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
<OptionsSetting value="true" id="Add" />
<OptionsSetting value="true" id="Remove" />
<OptionsSetting value="true" id="Checkout" />
<OptionsSetting value="true" id="Update" />
<OptionsSetting value="true" id="Status" />
<OptionsSetting value="true" id="Edit" />
<ConfirmationsSetting value="0" id="Add" />
<ConfirmationsSetting value="0" id="Remove" />
</component>
<component name="ProjectRootManager" version="2" />
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/chatOpenWebinars.iml" filepath="$PROJECT_DIR$/.idea/chatOpenWebinars.iml" />
</modules>
</component>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="" />
</component>
</project>
/**
* Created by careuno on 28/3/15.
*/
// requerimos express y lo suministramos a un servidor http para manejar las conexiones.
// requerimos socket.io y le suministramos http
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
// devolvemos index html
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
});
// implementamos el evento connection el cual se llamará cada vez que un usuario conecte y el de disconnect
io.on('connection', function(socket){
console.log('un usuario conectado');
socket.on('disconnect', function(){
console.log('usuario desconectado');
});
// los mensajes que lleguen al evento mensaje los manejamos por aqui y con io.emit los emitimos a todo el mundo.
socket.on('mensaje', function(mensaje){
console.log('mensaje: ' + mensaje);
io.emit('mensaje', mensaje);
});
});
// iniciamos el servidor
http.listen(8080, function(){
console.log('Servidor escuchando en puerto 8080');
});
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Chat OpenWebinars</title>
<style>
.capaMensajes {
width: 70%;
height: 500px;
border: 2px solid;
padding: 10px;
margin: 0;
}
ul { padding: 8px; list-style-type: none; }
input { height: 32px; width: 50%; }
button { height: 32px; width: 20%; }
</style>
</head>
<body>
<div class="capaMensajes">
<ul id="mensajesLista"></ul>
</div>
<div>
<div>
<span><input type="text" id="mensajeParaEnviar" placeholder="Escribe tu mensaje" /></span>
<span><button onclick="enviarMensaje()">Enviar</button></span>
</div>
</div>
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io();
// el mensaje que nos llega desde el servidor
socket.on("mensaje", function(mensaje) {
document.getElementById("mensajesLista").innerHTML += "<li>" + mensaje + "</li>";
});
function enviarMensaje() {
console.log("enviando: " + document.getElementById("mensajeParaEnviar").value);
socket.emit('mensaje', document.getElementById("mensajeParaEnviar").value);
document.getElementById("mensajeParaEnviar").value = "";
}
</script>
</body>
</html>

4.12.3 / 2015-03-17

  • deps: accepts@~1.2.5
    • deps: mime-types@~2.0.10
  • deps: debug@~2.1.3
    • Fix high intensity foreground color for bold
    • deps: ms@0.7.0
  • deps: finalhandler@0.3.4
    • deps: debug@~2.1.3
  • deps: proxy-addr@~1.0.7
    • deps: ipaddr.js@0.1.9
  • deps: qs@2.4.1
    • Fix error when parameter hasOwnProperty is present
  • deps: send@0.12.2
    • Throw errors early for invalid extensions or index options
    • deps: debug@~2.1.3
  • deps: serve-static@~1.9.2
    • deps: send@0.12.2
  • deps: type-is@~1.6.1
    • deps: mime-types@~2.0.10

4.12.2 / 2015-03-02

  • Fix regression where "Request aborted" is logged using res.sendFile

4.12.1 / 2015-03-01

  • Fix constructing application with non-configurable prototype properties
  • Fix ECONNRESET errors from res.sendFile usage
  • Fix req.host when using "trust proxy" hops count
  • Fix req.protocol/req.secure when using "trust proxy" hops count
  • Fix wrong code on aborted connections from res.sendFile
  • deps: merge-descriptors@1.0.0

4.12.0 / 2015-02-23

  • Fix "trust proxy" setting to inherit when app is mounted
  • Generate ETags for all request responses
    • No longer restricted to only responses for GET and HEAD requests
  • Use content-type to parse Content-Type headers
  • deps: accepts@~1.2.4
    • Fix preference sorting to be stable for long acceptable lists
    • deps: mime-types@~2.0.9
    • deps: negotiator@0.5.1
  • deps: cookie-signature@1.0.6
  • deps: send@0.12.1
    • Always read the stat size from the file
    • Fix mutating passed-in options
    • deps: mime@1.3.4
  • deps: serve-static@~1.9.1
    • deps: send@0.12.1
  • deps: type-is@~1.6.0
    • fix argument reassignment
    • fix false-positives in hasBody Transfer-Encoding check
    • support wildcard for both type and subtype (*/*)
    • deps: mime-types@~2.0.9

4.11.2 / 2015-02-01

  • Fix res.redirect double-calling res.end for HEAD requests
  • deps: accepts@~1.2.3
    • deps: mime-types@~2.0.8
  • deps: proxy-addr@~1.0.6
    • deps: ipaddr.js@0.1.8
  • deps: type-is@~1.5.6
    • deps: mime-types@~2.0.8

4.11.1 / 2015-01-20

  • deps: send@0.11.1
    • Fix root path disclosure
  • deps: serve-static@~1.8.1
    • Fix redirect loop in Node.js 0.11.14
    • Fix root path disclosure
    • deps: send@0.11.1

4.11.0 / 2015-01-13

  • Add res.append(field, val) to append headers
  • Deprecate leading : in name for app.param(name, fn)
  • Deprecate req.param() -- use req.params, req.body, or req.query instead
  • Deprecate app.param(fn)
  • Fix OPTIONS responses to include the HEAD method properly
  • Fix res.sendFile not always detecting aborted connection
  • Match routes iteratively to prevent stack overflows
  • deps: accepts@~1.2.2
    • deps: mime-types@~2.0.7
    • deps: negotiator@0.5.0
  • deps: send@0.11.0
    • deps: debug@~2.1.1
    • deps: etag@~1.5.1
    • deps: ms@0.7.0
    • deps: on-finished@~2.2.0
  • deps: serve-static@~1.8.0
    • deps: send@0.11.0

4.10.8 / 2015-01-13

  • Fix crash from error within OPTIONS response handler
  • deps: proxy-addr@~1.0.5
    • deps: ipaddr.js@0.1.6

4.10.7 / 2015-01-04

  • Fix Allow header for OPTIONS to not contain duplicate methods
  • Fix incorrect "Request aborted" for res.sendFile when HEAD or 304
  • deps: debug@~2.1.1
  • deps: finalhandler@0.3.3
    • deps: debug@~2.1.1
    • deps: on-finished@~2.2.0
  • deps: methods@~1.1.1
  • deps: on-finished@~2.2.0
  • deps: serve-static@~1.7.2
    • Fix potential open redirect when mounted at root
  • deps: type-is@~1.5.5
    • deps: mime-types@~2.0.7

4.10.6 / 2014-12-12

  • Fix exception in req.fresh/req.stale without response headers

4.10.5 / 2014-12-10

  • Fix res.send double-calling res.end for HEAD requests
  • deps: accepts@~1.1.4
    • deps: mime-types@~2.0.4
  • deps: type-is@~1.5.4
    • deps: mime-types@~2.0.4

4.10.4 / 2014-11-24

  • Fix res.sendfile logging standard write errors

4.10.3 / 2014-11-23

  • Fix res.sendFile logging standard write errors
  • deps: etag@~1.5.1
  • deps: proxy-addr@~1.0.4
    • deps: ipaddr.js@0.1.5
  • deps: qs@2.3.3
    • Fix arrayLimit behavior

4.10.2 / 2014-11-09

  • Correctly invoke async router callback asynchronously
  • deps: accepts@~1.1.3
    • deps: mime-types@~2.0.3
  • deps: type-is@~1.5.3
    • deps: mime-types@~2.0.3

4.10.1 / 2014-10-28

  • Fix handling of URLs containing :// in the path
  • deps: qs@2.3.2
    • Fix parsing of mixed objects and values

4.10.0 / 2014-10-23

  • Add support for app.set('views', array)
    • Views are looked up in sequence in array of directories
  • Fix res.send(status) to mention res.sendStatus(status)
  • Fix handling of invalid empty URLs
  • Use content-disposition module for res.attachment/res.download
    • Sends standards-compliant Content-Disposition header
    • Full Unicode support
  • Use path.resolve in view lookup
  • deps: debug@~2.1.0
    • Implement DEBUG_FD env variable support
  • deps: depd@~1.0.0
  • deps: etag@~1.5.0
    • Improve string performance
    • Slightly improve speed for weak ETags over 1KB
  • deps: finalhandler@0.3.2
    • Terminate in progress response only on error
    • Use on-finished to determine request status
    • deps: debug@~2.1.0
    • deps: on-finished@~2.1.1
  • deps: on-finished@~2.1.1
    • Fix handling of pipelined requests
  • deps: qs@2.3.0
    • Fix parsing of mixed implicit and explicit arrays
  • deps: send@0.10.1
    • deps: debug@~2.1.0
    • deps: depd@~1.0.0
    • deps: etag@~1.5.0
    • deps: on-finished@~2.1.1
  • deps: serve-static@~1.7.1
    • deps: send@0.10.1

4.9.8 / 2014-10-17

  • Fix res.redirect body when redirect status specified
  • deps: accepts@~1.1.2
    • Fix error when media type has invalid parameter
    • deps: negotiator@0.4.9

4.9.7 / 2014-10-10

  • Fix using same param name in array of paths

4.9.6 / 2014-10-08

  • deps: accepts@~1.1.1
    • deps: mime-types@~2.0.2
    • deps: negotiator@0.4.8
  • deps: serve-static@~1.6.4
    • Fix redirect loop when index file serving disabled
  • deps: type-is@~1.5.2
    • deps: mime-types@~2.0.2

4.9.5 / 2014-09-24

  • deps: etag@~1.4.0
  • deps: proxy-addr@~1.0.3
    • Use forwarded npm module
  • deps: send@0.9.3
    • deps: etag@~1.4.0
  • deps: serve-static@~1.6.3
    • deps: send@0.9.3

4.9.4 / 2014-09-19

  • deps: qs@2.2.4
    • Fix issue with object keys starting with numbers truncated

4.9.3 / 2014-09-18

  • deps: proxy-addr@~1.0.2
    • Fix a global leak when multiple subnets are trusted
    • deps: ipaddr.js@0.1.3

4.9.2 / 2014-09-17

  • Fix regression for empty string path in app.use
  • Fix router.use to accept array of middleware without path
  • Improve error message for bad app.use arguments

4.9.1 / 2014-09-16

  • Fix app.use to accept array of middleware without path
  • deps: depd@0.4.5
  • deps: etag@~1.3.1
  • deps: send@0.9.2
    • deps: depd@0.4.5
    • deps: etag@~1.3.1
    • deps: range-parser@~1.0.2
  • deps: serve-static@~1.6.2
    • deps: send@0.9.2

4.9.0 / 2014-09-08

  • Add res.sendStatus
  • Invoke callback for sendfile when client aborts
    • Applies to res.sendFile, res.sendfile, and res.download
    • err will be populated with request aborted error
  • Support IP address host in req.subdomains
  • Use etag to generate ETag headers
  • deps: accepts@~1.1.0
    • update mime-types
  • deps: cookie-signature@1.0.5
  • deps: debug@~2.0.0
  • deps: finalhandler@0.2.0
    • Set X-Content-Type-Options: nosniff header
    • deps: debug@~2.0.0
  • deps: fresh@0.2.4
  • deps: media-typer@0.3.0
    • Throw error when parameter format invalid on parse
  • deps: qs@2.2.3
    • Fix issue where first empty value in array is discarded
  • deps: range-parser@~1.0.2
  • deps: send@0.9.1
    • Add lastModified option
    • Use etag to generate ETag header
    • deps: debug@~2.0.0
    • deps: fresh@0.2.4
  • deps: serve-static@~1.6.1
    • Add lastModified option
    • deps: send@0.9.1
  • deps: type-is@~1.5.1
    • fix hasbody to be true for content-length: 0
    • deps: media-typer@0.3.0
    • deps: mime-types@~2.0.1
  • deps: vary@~1.0.0
    • Accept valid Vary header string as field

4.8.8 / 2014-09-04

  • deps: send@0.8.5
    • Fix a path traversal issue when using root
    • Fix malicious path detection for empty string path
  • deps: serve-static@~1.5.4
    • deps: send@0.8.5

4.8.7 / 2014-08-29

  • deps: qs@2.2.2
    • Remove unnecessary cloning

4.8.6 / 2014-08-27

  • deps: qs@2.2.0
    • Array parsing fix
    • Performance improvements

4.8.5 / 2014-08-18

  • deps: send@0.8.3
    • deps: destroy@1.0.3
    • deps: on-finished@2.1.0
  • deps: serve-static@~1.5.3
    • deps: send@0.8.3

4.8.4 / 2014-08-14

  • deps: qs@1.2.2
  • deps: send@0.8.2
    • Work around fd leak in Node.js 0.10 for fs.ReadStream
  • deps: serve-static@~1.5.2
    • deps: send@0.8.2

4.8.3 / 2014-08-10

  • deps: parseurl@~1.3.0
  • deps: qs@1.2.1
  • deps: serve-static@~1.5.1
    • Fix parsing of weird req.originalUrl values
    • deps: parseurl@~1.3.0
    • deps: utils-merge@1.0.0

4.8.2 / 2014-08-07

  • deps: qs@1.2.0
    • Fix parsing array of objects

4.8.1 / 2014-08-06

  • fix incorrect deprecation warnings on res.download
  • deps: qs@1.1.0
    • Accept urlencoded square brackets
    • Accept empty values in implicit array notation

4.8.0 / 2014-08-05

  • add res.sendFile
    • accepts a file system path instead of a URL
    • requires an absolute path or root option specified
  • deprecate res.sendfile -- use res.sendFile instead
  • support mounted app as any argument to app.use()
  • deps: qs@1.0.2
    • Complete rewrite
    • Limits array length to 20
    • Limits object depth to 5
    • Limits parameters to 1,000
  • deps: send@0.8.1
    • Add extensions option
  • deps: serve-static@~1.5.0
    • Add extensions option
    • deps: send@0.8.1

4.7.4 / 2014-08-04

  • fix res.sendfile regression for serving directory index files
  • deps: send@0.7.4
    • Fix incorrect 403 on Windows and Node.js 0.11
    • Fix serving index files without root dir
  • deps: serve-static@~1.4.4
    • deps: send@0.7.4

4.7.3 / 2014-08-04

  • deps: send@0.7.3
    • Fix incorrect 403 on Windows and Node.js 0.11
  • deps: serve-static@~1.4.3
    • Fix incorrect 403 on Windows and Node.js 0.11
    • deps: send@0.7.3

4.7.2 / 2014-07-27

  • deps: depd@0.4.4
    • Work-around v8 generating empty stack traces
  • deps: send@0.7.2
    • deps: depd@0.4.4
  • deps: serve-static@~1.4.2

4.7.1 / 2014-07-26

  • deps: depd@0.4.3
    • Fix exception when global Error.stackTraceLimit is too low
  • deps: send@0.7.1
    • deps: depd@0.4.3
  • deps: serve-static@~1.4.1

4.7.0 / 2014-07-25

  • fix req.protocol for proxy-direct connections
  • configurable query parser with app.set('query parser', parser)
    • app.set('query parser', 'extended') parse with "qs" module
    • app.set('query parser', 'simple') parse with "querystring" core module
    • app.set('query parser', false) disable query string parsing
    • app.set('query parser', true) enable simple parsing
  • deprecate res.json(status, obj) -- use res.status(status).json(obj) instead
  • deprecate res.jsonp(status, obj) -- use res.status(status).jsonp(obj) instead
  • deprecate res.send(status, body) -- use res.status(status).send(body) instead
  • deps: debug@1.0.4
  • deps: depd@0.4.2
    • Add TRACE_DEPRECATION environment variable
    • Remove non-standard grey color from color output
    • Support --no-deprecation argument
    • Support --trace-deprecation argument
  • deps: finalhandler@0.1.0
    • Respond after request fully read
    • deps: debug@1.0.4
  • deps: parseurl@~1.2.0
    • Cache URLs based on original value
    • Remove no-longer-needed URL mis-parse work-around
    • Simplify the "fast-path" RegExp
  • deps: send@0.7.0
    • Add dotfiles option
    • Cap maxAge value to 1 year
    • deps: debug@1.0.4
    • deps: depd@0.4.2
  • deps: serve-static@~1.4.0
    • deps: parseurl@~1.2.0
    • deps: send@0.7.0
  • perf: prevent multiple Buffer creation in res.send

4.6.1 / 2014-07-12

  • fix subapp.mountpath regression for app.use(subapp)

4.6.0 / 2014-07-11

  • accept multiple callbacks to app.use()
  • add explicit "Rosetta Flash JSONP abuse" protection
    • previous versions are not vulnerable; this is just explicit protection
  • catch errors in multiple req.param(name, fn) handlers
  • deprecate res.redirect(url, status) -- use res.redirect(status, url) instead
  • fix res.send(status, num) to send num as json (not error)
  • remove unnecessary escaping when res.jsonp returns JSON response
  • support non-string path in app.use(path, fn)
    • supports array of paths
    • supports RegExp
  • router: fix optimization on router exit
  • router: refactor location of try blocks
  • router: speed up standard app.use(fn)
  • deps: debug@1.0.3
    • Add support for multiple wildcards in namespaces
  • deps: finalhandler@0.0.3
    • deps: debug@1.0.3
  • deps: methods@1.1.0
    • add CONNECT
  • deps: parseurl@~1.1.3
    • faster parsing of href-only URLs
  • deps: path-to-regexp@0.1.3
  • deps: send@0.6.0
    • deps: debug@1.0.3
  • deps: serve-static@~1.3.2
    • deps: parseurl@~1.1.3
    • deps: send@0.6.0
  • perf: fix arguments reassign deopt in some res methods

4.5.1 / 2014-07-06

  • fix routing regression when altering req.method

4.5.0 / 2014-07-04

  • add deprecation message to non-plural req.accepts*
  • add deprecation message to res.send(body, status)
  • add deprecation message to res.vary()
  • add headers option to res.sendfile
    • use to set headers on successful file transfer
  • add mergeParams option to Router
    • merges req.params from parent routes
  • add req.hostname -- correct name for what req.host returns
  • deprecate things with depd module
  • deprecate req.host -- use req.hostname instead
  • fix behavior when handling request without routes
  • fix handling when route.all is only route
  • invoke router.param() only when route matches
  • restore req.params after invoking router
  • use finalhandler for final response handling
  • use media-typer to alter content-type charset
  • deps: accepts@~1.0.7
  • deps: send@0.5.0
    • Accept string for maxage (converted by ms)
    • Include link in default redirect response
  • deps: serve-static@~1.3.0
    • Accept string for maxAge (converted by ms)
    • Add setHeaders option
    • Include HTML link in redirect response
    • deps: send@0.5.0
  • deps: type-is@~1.3.2

4.4.5 / 2014-06-26

  • deps: cookie-signature@1.0.4
    • fix for timing attacks

4.4.4 / 2014-06-20

  • fix res.attachment Unicode filenames in Safari
  • fix "trim prefix" debug message in express:router
  • deps: accepts@~1.0.5
  • deps: buffer-crc32@0.2.3

4.4.3 / 2014-06-11

  • fix persistence of modified req.params[name] from app.param()
  • deps: accepts@1.0.3
    • deps: negotiator@0.4.6
  • deps: debug@1.0.2
  • deps: send@0.4.3
    • Do not throw un-catchable error on file open race condition
    • Use escape-html for HTML escaping
    • deps: debug@1.0.2
    • deps: finished@1.2.2
    • deps: fresh@0.2.2
  • deps: serve-static@1.2.3
    • Do not throw un-catchable error on file open race condition
    • deps: send@0.4.3

4.4.2 / 2014-06-09

  • fix catching errors from top-level handlers
  • use vary module for res.vary
  • deps: debug@1.0.1
  • deps: proxy-addr@1.0.1
  • deps: send@0.4.2
    • fix "event emitter leak" warnings
    • deps: debug@1.0.1
    • deps: finished@1.2.1
  • deps: serve-static@1.2.2
    • fix "event emitter leak" warnings
    • deps: send@0.4.2
  • deps: type-is@1.2.1

4.4.1 / 2014-06-02

  • deps: methods@1.0.1
  • deps: send@0.4.1
    • Send max-age in Cache-Control in correct format
  • deps: serve-static@1.2.1
    • use escape-html for escaping
    • deps: send@0.4.1

4.4.0 / 2014-05-30

  • custom etag control with app.set('etag', val)
    • app.set('etag', function(body, encoding){ return '"etag"' }) custom etag generation
    • app.set('etag', 'weak') weak tag
    • app.set('etag', 'strong') strong etag
    • app.set('etag', false) turn off
    • app.set('etag', true) standard etag
  • mark res.send ETag as weak and reduce collisions
  • update accepts to 1.0.2
    • Fix interpretation when header not in request
  • update send to 0.4.0
    • Calculate ETag with md5 for reduced collisions
    • Ignore stream errors after request ends
    • deps: debug@0.8.1
  • update serve-static to 1.2.0
    • Calculate ETag with md5 for reduced collisions
    • Ignore stream errors after request ends
    • deps: send@0.4.0

4.3.2 / 2014-05-28

  • fix handling of errors from router.param() callbacks

4.3.1 / 2014-05-23

  • revert "fix behavior of multiple app.VERB for the same path"
    • this caused a regression in the order of route execution

4.3.0 / 2014-05-21

  • add req.baseUrl to access the path stripped from req.url in routes
  • fix behavior of multiple app.VERB for the same path
  • fix issue routing requests among sub routers
  • invoke router.param() only when necessary instead of every match
  • proper proxy trust with app.set('trust proxy', trust)
    • app.set('trust proxy', 1) trust first hop
    • app.set('trust proxy', 'loopback') trust loopback addresses
    • app.set('trust proxy', '10.0.0.1') trust single IP
    • app.set('trust proxy', '10.0.0.1/16') trust subnet
    • app.set('trust proxy', '10.0.0.1, 10.0.0.2') trust list
    • app.set('trust proxy', false) turn off
    • app.set('trust proxy', true) trust everything
  • set proper charset in Content-Type for res.send
  • update type-is to 1.2.0
    • support suffix matching

4.2.0 / 2014-05-11

  • deprecate app.del() -- use app.delete() instead
  • deprecate res.json(obj, status) -- use res.json(status, obj) instead
    • the edge-case res.json(status, num) requires res.status(status).json(num)
  • deprecate res.jsonp(obj, status) -- use res.jsonp(status, obj) instead
    • the edge-case res.jsonp(status, num) requires res.status(status).jsonp(num)
  • fix req.next when inside router instance
  • include ETag header in HEAD requests
  • keep previous Content-Type for res.jsonp
  • support PURGE method
    • add app.purge
    • add router.purge
    • include PURGE in app.all
  • update debug to 0.8.0
    • add enable() method
    • change from stderr to stdout
  • update methods to 1.0.0
    • add PURGE

4.1.2 / 2014-05-08

  • fix req.host for IPv6 literals
  • fix res.jsonp error if callback param is object

4.1.1 / 2014-04-27

  • fix package.json to reflect supported node version

4.1.0 / 2014-04-24

  • pass options from res.sendfile to send
  • preserve casing of headers in res.header and res.set
  • support unicode file names in res.attachment and res.download
  • update accepts to 1.0.1
    • deps: negotiator@0.4.0
  • update cookie to 0.1.2
    • Fix for maxAge == 0
    • made compat with expires field
  • update send to 0.3.0
    • Accept API options in options object
    • Coerce option types
    • Control whether to generate etags
    • Default directory access to 403 when index disabled
    • Fix sending files with dots without root set
    • Include file path in etag
    • Make "Can't set headers after they are sent." catchable
    • Send full entity-body for multi range requests
    • Set etags to "weak"
    • Support "If-Range" header
    • Support multiple index paths
    • deps: mime@1.2.11
  • update serve-static to 1.1.0
    • Accept options directly to send module
    • Resolve relative paths at middleware setup
    • Use parseurl to parse the URL from request
    • deps: send@0.3.0
  • update type-is to 1.1.0
    • add non-array values support
    • add multipart as a shorthand

4.0.0 / 2014-04-09

  • remove:
    • node 0.8 support
    • connect and connect's patches except for charset handling
    • express(1) - moved to express-generator
    • express.createServer() - it has been deprecated for a long time. Use express()
    • app.configure - use logic in your own app code
    • app.router - is removed
    • req.auth - use basic-auth instead
    • req.accepted* - use req.accepts*() instead
    • res.location - relative URL resolution is removed
    • res.charset - include the charset in the content type when using res.set()
    • all bundled middleware except static
  • change:
    • app.route -> app.mountpath when mounting an express app in another express app
    • json spaces no longer enabled by default in development
    • req.accepts* -> req.accepts*s - i.e. req.acceptsEncoding -> req.acceptsEncodings
    • req.params is now an object instead of an array
    • res.locals is no longer a function. It is a plain js object. Treat it as such.
    • res.headerSent -> res.headersSent to match node.js ServerResponse object
  • refactor:
  • add:
    • app.router() - returns the app Router instance
    • app.route() - Proxy to the app's Router#route() method to create a new route
    • Router & Route - public API

3.20.2 / 2015-03-16

  • deps: connect@2.29.1
    • deps: body-parser@~1.12.2
    • deps: compression@~1.4.3
    • deps: connect-timeout@~1.6.1
    • deps: debug@~2.1.3
    • deps: errorhandler@~1.3.5
    • deps: express-session@~1.10.4
    • deps: finalhandler@0.3.4
    • deps: method-override@~2.3.2
    • deps: morgan@~1.5.2
    • deps: qs@2.4.1
    • deps: serve-index@~1.6.3
    • deps: serve-static@~1.9.2
    • deps: type-is@~1.6.1
  • deps: debug@~2.1.3
    • Fix high intensity foreground color for bold
    • deps: ms@0.7.0
  • deps: merge-descriptors@1.0.0
  • deps: proxy-addr@~1.0.7
    • deps: ipaddr.js@0.1.9
  • deps: send@0.12.2
    • Throw errors early for invalid extensions or index options
    • deps: debug@~2.1.3

3.20.1 / 2015-02-28

  • Fix req.host when using "trust proxy" hops count
  • Fix req.protocol/req.secure when using "trust proxy" hops count

3.20.0 / 2015-02-18

  • Fix "trust proxy" setting to inherit when app is mounted
  • Generate ETags for all request responses
    • No longer restricted to only responses for GET and HEAD requests
  • Use content-type to parse Content-Type headers
  • deps: connect@2.29.0
    • Use content-type to parse Content-Type headers
    • deps: body-parser@~1.12.0
    • deps: compression@~1.4.1
    • deps: connect-timeout@~1.6.0
    • deps: cookie-parser@~1.3.4
    • deps: cookie-signature@1.0.6
    • deps: csurf@~1.7.0
    • deps: errorhandler@~1.3.4
    • deps: express-session@~1.10.3
    • deps: http-errors@~1.3.1
    • deps: response-time@~2.3.0
    • deps: serve-index@~1.6.2
    • deps: serve-static@~1.9.1
    • deps: type-is@~1.6.0
  • deps: cookie-signature@1.0.6
  • deps: send@0.12.1
    • Always read the stat size from the file
    • Fix mutating passed-in options
    • deps: mime@1.3.4

3.19.2 / 2015-02-01

  • deps: connect@2.28.3
    • deps: compression@~1.3.1
    • deps: csurf@~1.6.6
    • deps: errorhandler@~1.3.3
    • deps: express-session@~1.10.2
    • deps: serve-index@~1.6.1
    • deps: type-is@~1.5.6
  • deps: proxy-addr@~1.0.6
    • deps: ipaddr.js@0.1.8

3.19.1 / 2015-01-20

  • deps: connect@2.28.2
    • deps: body-parser@~1.10.2
    • deps: serve-static@~1.8.1
  • deps: send@0.11.1
    • Fix root path disclosure

3.19.0 / 2015-01-09

  • Fix OPTIONS responses to include the HEAD method property
  • Use readline for prompt in express(1)
  • deps: commander@2.6.0
  • deps: connect@2.28.1
    • deps: body-parser@~1.10.1
    • deps: compression@~1.3.0
    • deps: connect-timeout@~1.5.0
    • deps: csurf@~1.6.4
    • deps: debug@~2.1.1
    • deps: errorhandler@~1.3.2
    • deps: express-session@~1.10.1
    • deps: finalhandler@0.3.3
    • deps: method-override@~2.3.1
    • deps: morgan@~1.5.1
    • deps: serve-favicon@~2.2.0
    • deps: serve-index@~1.6.0
    • deps: serve-static@~1.8.0
    • deps: type-is@~1.5.5
  • deps: debug@~2.1.1
  • deps: methods@~1.1.1
  • deps: proxy-addr@~1.0.5
    • deps: ipaddr.js@0.1.6
  • deps: send@0.11.0
    • deps: debug@~2.1.1
    • deps: etag@~1.5.1
    • deps: ms@0.7.0
    • deps: on-finished@~2.2.0

3.18.6 / 2014-12-12

  • Fix exception in req.fresh/req.stale without response headers

3.18.5 / 2014-12-11

  • deps: connect@2.27.6
    • deps: compression@~1.2.2
    • deps: express-session@~1.9.3
    • deps: http-errors@~1.2.8
    • deps: serve-index@~1.5.3
    • deps: type-is@~1.5.4

3.18.4 / 2014-11-23

  • deps: connect@2.27.4
    • deps: body-parser@~1.9.3
    • deps: compression@~1.2.1
    • deps: errorhandler@~1.2.3
    • deps: express-session@~1.9.2
    • deps: qs@2.3.3
    • deps: serve-favicon@~2.1.7
    • deps: serve-static@~1.5.1
    • deps: type-is@~1.5.3
  • deps: etag@~1.5.1
  • deps: proxy-addr@~1.0.4
    • deps: ipaddr.js@0.1.5

3.18.3 / 2014-11-09

  • deps: connect@2.27.3
    • Correctly invoke async callback asynchronously
    • deps: csurf@~1.6.3

3.18.2 / 2014-10-28

  • deps: connect@2.27.2
    • Fix handling of URLs containing :// in the path
    • deps: body-parser@~1.9.2
    • deps: qs@2.3.2

3.18.1 / 2014-10-22

  • Fix internal utils.merge deprecation warnings
  • deps: connect@2.27.1
    • deps: body-parser@~1.9.1
    • deps: express-session@~1.9.1
    • deps: finalhandler@0.3.2
    • deps: morgan@~1.4.1
    • deps: qs@2.3.0
    • deps: serve-static@~1.7.1
  • deps: send@0.10.1
    • deps: on-finished@~2.1.1

3.18.0 / 2014-10-17

  • Use content-disposition module for res.attachment/res.download
    • Sends standards-compliant Content-Disposition header
    • Full Unicode support
  • Use etag module to generate ETag headers
  • deps: connect@2.27.0
    • Use http-errors module for creating errors
    • Use utils-merge module for merging objects
    • deps: body-parser@~1.9.0
    • deps: compression@~1.2.0
    • deps: connect-timeout@~1.4.0
    • deps: debug@~2.1.0
    • deps: depd@~1.0.0
    • deps: express-session@~1.9.0
    • deps: finalhandler@0.3.1
    • deps: method-override@~2.3.0
    • deps: morgan@~1.4.0
    • deps: response-time@~2.2.0
    • deps: serve-favicon@~2.1.6
    • deps: serve-index@~1.5.0
    • deps: serve-static@~1.7.0
  • deps: debug@~2.1.0
    • Implement DEBUG_FD env variable support
  • deps: depd@~1.0.0
  • deps: send@0.10.0
    • deps: debug@~2.1.0
    • deps: depd@~1.0.0
    • deps: etag@~1.5.0

3.17.8 / 2014-10-15

  • deps: connect@2.26.6
    • deps: compression@~1.1.2
    • deps: csurf@~1.6.2
    • deps: errorhandler@~1.2.2

3.17.7 / 2014-10-08

  • deps: connect@2.26.5
    • Fix accepting non-object arguments to logger
    • deps: serve-static@~1.6.4

3.17.6 / 2014-10-02

  • deps: connect@2.26.4
    • deps: morgan@~1.3.2
    • deps: type-is@~1.5.2

3.17.5 / 2014-09-24

  • deps: connect@2.26.3
    • deps: body-parser@~1.8.4
    • deps: serve-favicon@~2.1.5
    • deps: serve-static@~1.6.3
  • deps: proxy-addr@~1.0.3
    • Use forwarded npm module
  • deps: send@0.9.3
    • deps: etag@~1.4.0

3.17.4 / 2014-09-19

  • deps: connect@2.26.2
    • deps: body-parser@~1.8.3
    • deps: qs@2.2.4

3.17.3 / 2014-09-18

  • deps: proxy-addr@~1.0.2
    • Fix a global leak when multiple subnets are trusted
    • deps: ipaddr.js@0.1.3

3.17.2 / 2014-09-15

  • Use crc instead of buffer-crc32 for speed
  • deps: connect@2.26.1
    • deps: body-parser@~1.8.2
    • deps: depd@0.4.5
    • deps: express-session@~1.8.2
    • deps: morgan@~1.3.1
    • deps: serve-favicon@~2.1.3
    • deps: serve-static@~1.6.2
  • deps: depd@0.4.5
  • deps: send@0.9.2
    • deps: depd@0.4.5
    • deps: etag@~1.3.1
    • deps: range-parser@~1.0.2

3.17.1 / 2014-09-08

  • Fix error in req.subdomains on empty host

3.17.0 / 2014-09-08

  • Support X-Forwarded-Host in req.subdomains
  • Support IP address host in req.subdomains
  • deps: connect@2.26.0
    • deps: body-parser@~1.8.1
    • deps: compression@~1.1.0
    • deps: connect-timeout@~1.3.0
    • deps: cookie-parser@~1.3.3
    • deps: cookie-signature@1.0.5
    • deps: csurf@~1.6.1
    • deps: debug@~2.0.0
    • deps: errorhandler@~1.2.0
    • deps: express-session@~1.8.1
    • deps: finalhandler@0.2.0
    • deps: fresh@0.2.4
    • deps: media-typer@0.3.0
    • deps: method-override@~2.2.0
    • deps: morgan@~1.3.0
    • deps: qs@2.2.3
    • deps: serve-favicon@~2.1.3
    • deps: serve-index@~1.2.1
    • deps: serve-static@~1.6.1
    • deps: type-is@~1.5.1
    • deps: vhost@~3.0.0
  • deps: cookie-signature@1.0.5
  • deps: debug@~2.0.0
  • deps: fresh@0.2.4
  • deps: media-typer@0.3.0
    • Throw error when parameter format invalid on parse
  • deps: range-parser@~1.0.2
  • deps: send@0.9.1
    • Add lastModified option
    • Use etag to generate ETag header
    • deps: debug@~2.0.0
    • deps: fresh@0.2.4
  • deps: vary@~1.0.0
    • Accept valid Vary header string as field

3.16.10 / 2014-09-04

  • deps: connect@2.25.10
    • deps: serve-static@~1.5.4
  • deps: send@0.8.5
    • Fix a path traversal issue when using root
    • Fix malicious path detection for empty string path

3.16.9 / 2014-08-29

  • deps: connect@2.25.9
    • deps: body-parser@~1.6.7
    • deps: qs@2.2.2

3.16.8 / 2014-08-27

  • deps: connect@2.25.8
    • deps: body-parser@~1.6.6
    • deps: csurf@~1.4.1
    • deps: qs@2.2.0

3.16.7 / 2014-08-18

  • deps: connect@2.25.7
    • deps: body-parser@~1.6.5
    • deps: express-session@~1.7.6
    • deps: morgan@~1.2.3
    • deps: serve-static@~1.5.3
  • deps: send@0.8.3
    • deps: destroy@1.0.3
    • deps: on-finished@2.1.0

3.16.6 / 2014-08-14

  • deps: connect@2.25.6
    • deps: body-parser@~1.6.4
    • deps: qs@1.2.2
    • deps: serve-static@~1.5.2
  • deps: send@0.8.2
    • Work around fd leak in Node.js 0.10 for fs.ReadStream

3.16.5 / 2014-08-11

  • deps: connect@2.25.5
    • Fix backwards compatibility in logger

3.16.4 / 2014-08-10

  • Fix original URL parsing in res.location
  • deps: connect@2.25.4
    • Fix query middleware breaking with argument
    • deps: body-parser@~1.6.3
    • deps: compression@~1.0.11
    • deps: connect-timeout@~1.2.2
    • deps: express-session@~1.7.5
    • deps: method-override@~2.1.3
    • deps: on-headers@~1.0.0
    • deps: parseurl@~1.3.0
    • deps: qs@1.2.1
    • deps: response-time@~2.0.1
    • deps: serve-index@~1.1.6
    • deps: serve-static@~1.5.1
  • deps: parseurl@~1.3.0

3.16.3 / 2014-08-07

  • deps: connect@2.25.3
    • deps: multiparty@3.3.2

3.16.2 / 2014-08-07

  • deps: connect@2.25.2
    • deps: body-parser@~1.6.2
    • deps: qs@1.2.0

3.16.1 / 2014-08-06

  • deps: connect@2.25.1
    • deps: body-parser@~1.6.1
    • deps: qs@1.1.0

3.16.0 / 2014-08-05

  • deps: connect@2.25.0
    • deps: body-parser@~1.6.0
    • deps: compression@~1.0.10
    • deps: csurf@~1.4.0
    • deps: express-session@~1.7.4
    • deps: qs@1.0.2
    • deps: serve-static@~1.5.0
  • deps: send@0.8.1
    • Add extensions option

3.15.3 / 2014-08-04

  • fix res.sendfile regression for serving directory index files
  • deps: connect@2.24.3
    • deps: serve-index@~1.1.5
    • deps: serve-static@~1.4.4
  • deps: send@0.7.4
    • Fix incorrect 403 on Windows and Node.js 0.11
    • Fix serving index files without root dir

3.15.2 / 2014-07-27

  • deps: connect@2.24.2
    • deps: body-parser@~1.5.2
    • deps: depd@0.4.4
    • deps: express-session@~1.7.2
    • deps: morgan@~1.2.2
    • deps: serve-static@~1.4.2
  • deps: depd@0.4.4
    • Work-around v8 generating empty stack traces
  • deps: send@0.7.2
    • deps: depd@0.4.4

3.15.1 / 2014-07-26

  • deps: connect@2.24.1
    • deps: body-parser@~1.5.1
    • deps: depd@0.4.3
    • deps: express-session@~1.7.1
    • deps: morgan@~1.2.1
    • deps: serve-index@~1.1.4
    • deps: serve-static@~1.4.1
  • deps: depd@0.4.3
    • Fix exception when global Error.stackTraceLimit is too low
  • deps: send@0.7.1
    • deps: depd@0.4.3

3.15.0 / 2014-07-22

  • Fix req.protocol for proxy-direct connections
  • Pass options from res.sendfile to send
  • deps: connect@2.24.0
    • deps: body-parser@~1.5.0
    • deps: compression@~1.0.9
    • deps: connect-timeout@~1.2.1
    • deps: debug@1.0.4
    • deps: depd@0.4.2
    • deps: express-session@~1.7.0
    • deps: finalhandler@0.1.0
    • deps: method-override@~2.1.2
    • deps: morgan@~1.2.0
    • deps: multiparty@3.3.1
    • deps: parseurl@~1.2.0
    • deps: serve-static@~1.4.0
  • deps: debug@1.0.4
  • deps: depd@0.4.2
    • Add TRACE_DEPRECATION environment variable
    • Remove non-standard grey color from color output
    • Support --no-deprecation argument
    • Support --trace-deprecation argument
  • deps: parseurl@~1.2.0
    • Cache URLs based on original value
    • Remove no-longer-needed URL mis-parse work-around
    • Simplify the "fast-path" RegExp
  • deps: send@0.7.0
    • Add dotfiles option
    • Cap maxAge value to 1 year
    • deps: debug@1.0.4
    • deps: depd@0.4.2

3.14.0 / 2014-07-11

  • add explicit "Rosetta Flash JSONP abuse" protection
    • previous versions are not vulnerable; this is just explicit protection
  • deprecate res.redirect(url, status) -- use res.redirect(status, url) instead
  • fix res.send(status, num) to send num as json (not error)
  • remove unnecessary escaping when res.jsonp returns JSON response
  • deps: basic-auth@1.0.0
    • support empty password
    • support empty username
  • deps: connect@2.23.0
    • deps: debug@1.0.3
    • deps: express-session@~1.6.4
    • deps: method-override@~2.1.0
    • deps: parseurl@~1.1.3
    • deps: serve-static@~1.3.1
  • deps: debug@1.0.3
    • Add support for multiple wildcards in namespaces
  • deps: methods@1.1.0
    • add CONNECT
  • deps: parseurl@~1.1.3
    • faster parsing of href-only URLs

3.13.0 / 2014-07-03

  • add deprecation message to app.configure
  • add deprecation message to req.auth
  • use basic-auth to parse Authorization header
  • deps: connect@2.22.0
    • deps: csurf@~1.3.0
    • deps: express-session@~1.6.1
    • deps: multiparty@3.3.0
    • deps: serve-static@~1.3.0
  • deps: send@0.5.0
    • Accept string for maxage (converted by ms)
    • Include link in default redirect response

3.12.1 / 2014-06-26

  • deps: connect@2.21.1
    • deps: cookie-parser@1.3.2
    • deps: cookie-signature@1.0.4
    • deps: express-session@~1.5.2
    • deps: type-is@~1.3.2
  • deps: cookie-signature@1.0.4
    • fix for timing attacks

3.12.0 / 2014-06-21

  • use media-typer to alter content-type charset
  • deps: connect@2.21.0
    • deprecate connect(middleware) -- use app.use(middleware) instead
    • deprecate connect.createServer() -- use connect() instead
    • fix res.setHeader() patch to work with with get -> append -> set pattern
    • deps: compression@~1.0.8
    • deps: errorhandler@~1.1.1
    • deps: express-session@~1.5.0
    • deps: serve-index@~1.1.3

3.11.0 / 2014-06-19

  • deprecate things with depd module
  • deps: buffer-crc32@0.2.3
  • deps: connect@2.20.2
    • deprecate verify option to json -- use body-parser npm module instead
    • deprecate verify option to urlencoded -- use body-parser npm module instead
    • deprecate things with depd module
    • use finalhandler for final response handling
    • use media-typer to parse content-type for charset
    • deps: body-parser@1.4.3
    • deps: connect-timeout@1.1.1
    • deps: cookie-parser@1.3.1
    • deps: csurf@1.2.2
    • deps: errorhandler@1.1.0
    • deps: express-session@1.4.0
    • deps: multiparty@3.2.9
    • deps: serve-index@1.1.2
    • deps: type-is@1.3.1
    • deps: vhost@2.0.0

3.10.5 / 2014-06-11

  • deps: connect@2.19.6
    • deps: body-parser@1.3.1
    • deps: compression@1.0.7
    • deps: debug@1.0.2
    • deps: serve-index@1.1.1
    • deps: serve-static@1.2.3
  • deps: debug@1.0.2
  • deps: send@0.4.3
    • Do not throw un-catchable error on file open race condition
    • Use escape-html for HTML escaping
    • deps: debug@1.0.2
    • deps: finished@1.2.2
    • deps: fresh@0.2.2

3.10.4 / 2014-06-09

  • deps: connect@2.19.5
    • fix "event emitter leak" warnings
    • deps: csurf@1.2.1
    • deps: debug@1.0.1
    • deps: serve-static@1.2.2
    • deps: type-is@1.2.1
  • deps: debug@1.0.1
  • deps: send@0.4.2
    • fix "event emitter leak" warnings
    • deps: finished@1.2.1
    • deps: debug@1.0.1

3.10.3 / 2014-06-05

  • use vary module for res.vary
  • deps: connect@2.19.4
    • deps: errorhandler@1.0.2
    • deps: method-override@2.0.2
    • deps: serve-favicon@2.0.1
  • deps: debug@1.0.0

3.10.2 / 2014-06-03

  • deps: connect@2.19.3
    • deps: compression@1.0.6

3.10.1 / 2014-06-03

  • deps: connect@2.19.2
    • deps: compression@1.0.4
  • deps: proxy-addr@1.0.1

3.10.0 / 2014-06-02

  • deps: connect@2.19.1
    • deprecate methodOverride() -- use method-override npm module instead
    • deps: body-parser@1.3.0
    • deps: method-override@2.0.1
    • deps: multiparty@3.2.8
    • deps: response-time@2.0.0
    • deps: serve-static@1.2.1
  • deps: methods@1.0.1
  • deps: send@0.4.1
    • Send max-age in Cache-Control in correct format

3.9.0 / 2014-05-30

  • custom etag control with app.set('etag', val)
    • app.set('etag', function(body, encoding){ return '"etag"' }) custom etag generation
    • app.set('etag', 'weak') weak tag
    • app.set('etag', 'strong') strong etag
    • app.set('etag', false) turn off
    • app.set('etag', true) standard etag
  • Include ETag in HEAD requests
  • mark res.send ETag as weak and reduce collisions
  • update connect to 2.18.0
    • deps: compression@1.0.3
    • deps: serve-index@1.1.0
    • deps: serve-static@1.2.0
  • update send to 0.4.0
    • Calculate ETag with md5 for reduced collisions
    • Ignore stream errors after request ends
    • deps: debug@0.8.1

3.8.1 / 2014-05-27

  • update connect to 2.17.3
    • deps: body-parser@1.2.2
    • deps: express-session@1.2.1
    • deps: method-override@1.0.2

3.8.0 / 2014-05-21

  • keep previous Content-Type for res.jsonp
  • set proper charset in Content-Type for res.send
  • update connect to 2.17.1
    • fix res.charset appending charset when content-type has one
    • deps: express-session@1.2.0
    • deps: morgan@1.1.1
    • deps: serve-index@1.0.3

3.7.0 / 2014-05-18

  • proper proxy trust with app.set('trust proxy', trust)
    • app.set('trust proxy', 1) trust first hop
    • app.set('trust proxy', 'loopback') trust loopback addresses
    • app.set('trust proxy', '10.0.0.1') trust single IP
    • app.set('trust proxy', '10.0.0.1/16') trust subnet
    • app.set('trust proxy', '10.0.0.1, 10.0.0.2') trust list
    • app.set('trust proxy', false) turn off
    • app.set('trust proxy', true) trust everything
  • update connect to 2.16.2
    • deprecate res.headerSent -- use res.headersSent
    • deprecate res.on("header") -- use on-headers module instead
    • fix edge-case in res.appendHeader that would append in wrong order
    • json: use body-parser
    • urlencoded: use body-parser
    • dep: bytes@1.0.0
    • dep: cookie-parser@1.1.0
    • dep: csurf@1.2.0
    • dep: express-session@1.1.0
    • dep: method-override@1.0.1

3.6.0 / 2014-05-09

  • deprecate app.del() -- use app.delete() instead
  • deprecate res.json(obj, status) -- use res.json(status, obj) instead
    • the edge-case res.json(status, num) requires res.status(status).json(num)
  • deprecate res.jsonp(obj, status) -- use res.jsonp(status, obj) instead
    • the edge-case res.jsonp(status, num) requires res.status(status).jsonp(num)
  • support PURGE method
    • add app.purge
    • add router.purge
    • include PURGE in app.all
  • update connect to 2.15.0
    • Add res.appendHeader
    • Call error stack even when response has been sent
    • Patch res.headerSent to return Boolean
    • Patch res.headersSent for node.js 0.8
    • Prevent default 404 handler after response sent
    • dep: compression@1.0.2
    • dep: connect-timeout@1.1.0
    • dep: debug@^0.8.0
    • dep: errorhandler@1.0.1
    • dep: express-session@1.0.4
    • dep: morgan@1.0.1
    • dep: serve-favicon@2.0.0
    • dep: serve-index@1.0.2
  • update debug to 0.8.0
    • add enable() method
    • change from stderr to stdout
  • update methods to 1.0.0
    • add PURGE
  • update mkdirp to 0.5.0

3.5.3 / 2014-05-08

  • fix req.host for IPv6 literals
  • fix res.jsonp error if callback param is object

3.5.2 / 2014-04-24

  • update connect to 2.14.5
  • update cookie to 0.1.2
  • update mkdirp to 0.4.0
  • update send to 0.3.0

3.5.1 / 2014-03-25

  • pin less-middleware in generated app

3.5.0 / 2014-03-06

  • bump deps

3.4.8 / 2014-01-13

  • prevent incorrect automatic OPTIONS responses #1868 @dpatti
  • update binary and examples for jade 1.0 #1876 @yossi, #1877 @reqshark, #1892 @matheusazzi
  • throw 400 in case of malformed paths @rlidwka

3.4.7 / 2013-12-10

  • update connect

3.4.6 / 2013-12-01

  • update connect (raw-body)

3.4.5 / 2013-11-27

  • update connect
  • res.location: remove leading ./ #1802 @kapouer
  • res.redirect: fix `res.redirect('toString') #1829 @michaelficarra
  • res.send: always send ETag when content-length > 0
  • router: add Router.all() method

3.4.4 / 2013-10-29

  • update connect
  • update supertest
  • update methods
  • express(1): replace bodyParser() with urlencoded() and json() #1795 @chirag04

3.4.3 / 2013-10-23

  • update connect

3.4.2 / 2013-10-18

  • update connect
  • downgrade commander

3.4.1 / 2013-10-15

  • update connect
  • update commander
  • jsonp: check if callback is a function
  • router: wrap encodeURIComponent in a try/catch #1735 (@lxe)
  • res.format: now includes chraset @1747 (@sorribas)
  • res.links: allow multiple calls @1746 (@sorribas)

3.4.0 / 2013-09-07

  • add res.vary(). Closes #1682
  • update connect

3.3.8 / 2013-09-02

  • update connect

3.3.7 / 2013-08-28

  • update connect

3.3.6 / 2013-08-27

  • Revert "remove charset from json responses. Closes #1631" (causes issues in some clients)
  • add: req.accepts take an argument list

3.3.4 / 2013-07-08

  • update send and connect

3.3.3 / 2013-07-04

  • update connect

3.3.2 / 2013-07-03

  • update connect
  • update send
  • remove .version export

3.3.1 / 2013-06-27

  • update connect

3.3.0 / 2013-06-26

  • update connect
  • add support for multiple X-Forwarded-Proto values. Closes #1646
  • change: remove charset from json responses. Closes #1631
  • change: return actual booleans from req.accept* functions
  • fix jsonp callback array throw

3.2.6 / 2013-06-02

  • update connect

3.2.5 / 2013-05-21

  • update connect
  • update node-cookie
  • add: throw a meaningful error when there is no default engine
  • change generation of ETags with res.send() to GET requests only. Closes #1619

3.2.4 / 2013-05-09

  • fix req.subdomains when no Host is present
  • fix req.host when no Host is present, return undefined

3.2.3 / 2013-05-07

  • update connect / qs

3.2.2 / 2013-05-03

  • update qs

3.2.1 / 2013-04-29

  • add app.VERB() paths array deprecation warning
  • update connect
  • update qs and remove all ~ semver crap
  • fix: accept number as value of Signed Cookie

3.2.0 / 2013-04-15

  • add "view" constructor setting to override view behaviour
  • add req.acceptsEncoding(name)
  • add req.acceptedEncodings
  • revert cookie signature change causing session race conditions
  • fix sorting of Accept values of the same quality

3.1.2 / 2013-04-12

  • add support for custom Accept parameters
  • update cookie-signature

3.1.1 / 2013-04-01

  • add X-Forwarded-Host support to req.host
  • fix relative redirects
  • update mkdirp
  • update buffer-crc32
  • remove legacy app.configure() method from app template.

3.1.0 / 2013-01-25

  • add support for leading "." in "view engine" setting
  • add array support to res.set()
  • add node 0.8.x to travis.yml
  • add "subdomain offset" setting for tweaking req.subdomains
  • add res.location(url) implementing res.redirect()-like setting of Location
  • use app.get() for x-powered-by setting for inheritance
  • fix colons in passwords for req.auth

3.0.6 / 2013-01-04

  • add http verb methods to Router
  • update connect
  • fix mangling of the res.cookie() options object
  • fix jsonp whitespace escape. Closes #1132

3.0.5 / 2012-12-19

  • add throwing when a non-function is passed to a route
  • fix: explicitly remove Transfer-Encoding header from 204 and 304 responses
  • revert "add 'etag' option"

3.0.4 / 2012-12-05

  • add 'etag' option to disable res.send() Etags
  • add escaping of urls in text/plain in res.redirect() for old browsers interpreting as html
  • change crc32 module for a more liberal license
  • update connect

3.0.3 / 2012-11-13

  • update connect
  • update cookie module
  • fix cookie max-age

3.0.2 / 2012-11-08

  • add OPTIONS to cors example. Closes #1398
  • fix route chaining regression. Closes #1397

3.0.1 / 2012-11-01

  • update connect

3.0.0 / 2012-10-23

  • add make clean
  • add "Basic" check to req.auth
  • add req.auth test coverage
  • add cb && cb(payload) to res.jsonp(). Closes #1374
  • add backwards compat for res.redirect() status. Closes #1336
  • add support for res.json() to retain previously defined Content-Types. Closes #1349
  • update connect
  • change res.redirect() to utilize a pathname-relative Location again. Closes #1382
  • remove non-primitive string support for res.send()
  • fix view-locals example. Closes #1370
  • fix route-separation example

3.0.0rc5 / 2012-09-18

  • update connect
  • add redis search example
  • add static-files example
  • add "x-powered-by" setting (app.disable('x-powered-by'))
  • add "application/octet-stream" redirect Accept test case. Closes #1317

3.0.0rc4 / 2012-08-30

  • add res.jsonp(). Closes #1307
  • add "verbose errors" option to error-pages example
  • add another route example to express(1) so people are not so confused
  • add redis online user activity tracking example
  • update connect dep
  • fix etag quoting. Closes #1310
  • fix error-pages 404 status
  • fix jsonp callback char restrictions
  • remove old OPTIONS default response

3.0.0rc3 / 2012-08-13

  • update connect dep
  • fix signed cookies to work with connect.cookieParser() ("s:" prefix was missing) [tnydwrds]
  • fix res.render() clobbering of "locals"

3.0.0rc2 / 2012-08-03

  • add CORS example
  • update connect dep
  • deprecate .createServer() & remove old stale examples
  • fix: escape res.redirect() link
  • fix vhost example

3.0.0rc1 / 2012-07-24

  • add more examples to view-locals
  • add scheme-relative redirects (res.redirect("//foo.com")) support
  • update cookie dep
  • update connect dep
  • update send dep
  • fix express(1) -h flag, use -H for hogan. Closes #1245
  • fix res.sendfile() socket error handling regression

3.0.0beta7 / 2012-07-16

  • update connect dep for send() root normalization regression

3.0.0beta6 / 2012-07-13

  • add err.view property for view errors. Closes #1226
  • add "jsonp callback name" setting
  • add support for "/foo/:bar*" non-greedy matches
  • change res.sendfile() to use send() module
  • change res.send to use "response-send" module
  • remove app.locals.use and res.locals.use, use regular middleware

3.0.0beta5 / 2012-07-03

  • add "make check" support
  • add route-map example
  • add res.json(obj, status) support back for BC
  • add "methods" dep, remove internal methods module
  • update connect dep
  • update auth example to utilize cores pbkdf2
  • updated tests to use "supertest"

3.0.0beta4 / 2012-06-25

  • Added req.auth
  • Added req.range(size)
  • Added res.links(obj)
  • Added res.send(body, status) support back for backwards compat
  • Added .default() support to res.format()
  • Added 2xx / 304 check to req.fresh
  • Revert "Added + support to the router"
  • Fixed res.send() freshness check, respect res.statusCode

3.0.0beta3 / 2012-06-15

  • Added hogan --hjs to express(1) [nullfirm]
  • Added another example to content-negotiation
  • Added fresh dep
  • Changed: res.send() always checks freshness
  • Fixed: expose connects mime module. Cloases #1165

3.0.0beta2 / 2012-06-06

  • Added + support to the router
  • Added req.host
  • Changed req.param() to check route first
  • Update connect dep

3.0.0beta1 / 2012-06-01

  • Added res.format() callback to override default 406 behaviour
  • Fixed res.redirect() 406. Closes #1154

3.0.0alpha5 / 2012-05-30

  • Added req.ip
  • Added { signed: true } option to res.cookie()
  • Removed res.signedCookie()
  • Changed: dont reverse req.ips
  • Fixed "trust proxy" setting check for req.ips

3.0.0alpha4 / 2012-05-09

  • Added: allow [] in jsonp callback. Closes #1128
  • Added PORT env var support in generated template. Closes #1118 [benatkin]
  • Updated: connect 2.2.2

3.0.0alpha3 / 2012-05-04

  • Added public app.routes. Closes #887
  • Added view-locals example
  • Added mvc example
  • Added res.locals.use(). Closes #1120
  • Added conditional-GET support to res.send()
  • Added: coerce res.set() values to strings
  • Changed: moved static() in generated apps below router
  • Changed: res.send() only set ETag when not previously set
  • Changed connect 2.2.1 dep
  • Changed: make test now runs unit / acceptance tests
  • Fixed req/res proto inheritance

3.0.0alpha2 / 2012-04-26

  • Added make benchmark back
  • Added res.send() support for String objects
  • Added client-side data exposing example
  • Added res.header() and req.header() aliases for BC
  • Added express.createServer() for BC
  • Perf: memoize parsed urls
  • Perf: connect 2.2.0 dep
  • Changed: make expressInit() middleware self-aware
  • Fixed: use app.get() for all core settings
  • Fixed redis session example
  • Fixed session example. Closes #1105
  • Fixed generated express dep. Closes #1078

3.0.0alpha1 / 2012-04-15

  • Added app.locals.use(callback)
  • Added app.locals object
  • Added app.locals(obj)
  • Added res.locals object
  • Added res.locals(obj)
  • Added res.format() for content-negotiation
  • Added app.engine()
  • Added res.cookie() JSON cookie support
  • Added "trust proxy" setting
  • Added req.subdomains
  • Added req.protocol
  • Added req.secure
  • Added req.path
  • Added req.ips
  • Added req.fresh
  • Added req.stale
  • Added comma-delmited / array support for req.accepts()
  • Added debug instrumentation
  • Added res.set(obj)
  • Added res.set(field, value)
  • Added res.get(field)
  • Added app.get(setting). Closes #842
  • Added req.acceptsLanguage()
  • Added req.acceptsCharset()
  • Added req.accepted
  • Added req.acceptedLanguages
  • Added req.acceptedCharsets
  • Added "json replacer" setting
  • Added "json spaces" setting
  • Added X-Forwarded-Proto support to res.redirect(). Closes #92
  • Added --less support to express(1)
  • Added express.response prototype
  • Added express.request prototype
  • Added express.application prototype
  • Added app.path()
  • Added app.render()
  • Added res.type() to replace res.contentType()
  • Changed: res.redirect() to add relative support
  • Changed: enable "jsonp callback" by default
  • Changed: renamed "case sensitive routes" to "case sensitive routing"
  • Rewrite of all tests with mocha
  • Removed "root" setting
  • Removed res.redirect('home') support
  • Removed req.notify()
  • Removed app.register()
  • Removed app.redirect()
  • Removed app.is()
  • Removed app.helpers()
  • Removed app.dynamicHelpers()
  • Fixed res.sendfile() with non-GET. Closes #723
  • Fixed express(1) public dir for windows. Closes #866

2.5.9/ 2012-04-02

  • Added support for PURGE request method [pbuyle]
  • Fixed express(1) generated app app.address() before listening [mmalecki]

2.5.8 / 2012-02-08

  • Update mkdirp dep. Closes #991

2.5.7 / 2012-02-06

  • Fixed app.all duplicate DELETE requests [mscdex]

2.5.6 / 2012-01-13

  • Updated hamljs dev dep. Closes #953

2.5.5 / 2012-01-08

  • Fixed: set filename on cached templates [matthewleon]

2.5.4 / 2012-01-02

  • Fixed express(1) eol on 0.4.x. Closes #947

2.5.3 / 2011-12-30

  • Fixed req.is() when a charset is present

2.5.2 / 2011-12-10

  • Fixed: express(1) LF -> CRLF for windows

2.5.1 / 2011-11-17

  • Changed: updated connect to 1.8.x
  • Removed sass.js support from express(1)

2.5.0 / 2011-10-24

  • Added ./routes dir for generated app by default
  • Added npm install reminder to express(1) app gen
  • Added 0.5.x support
  • Removed make test-cov since it wont work with node 0.5.x
  • Fixed express(1) public dir for windows. Closes #866

2.4.7 / 2011-10-05

  • Added mkdirp to express(1). Closes #795
  • Added simple json-config example
  • Added shorthand for the parsed request's pathname via req.path
  • Changed connect dep to 1.7.x to fix npm issue...
  • Fixed res.redirect() HEAD support. [reported by xerox]
  • Fixed req.flash(), only escape args
  • Fixed absolute path checking on windows. Closes #829 [reported by andrewpmckenzie]

2.4.6 / 2011-08-22

  • Fixed multiple param callback regression. Closes #824 [reported by TroyGoode]

2.4.5 / 2011-08-19

  • Added support for routes to handle errors. Closes #809
  • Added app.routes.all(). Closes #803
  • Added "basepath" setting to work in conjunction with reverse proxies etc.
  • Refactored Route to use a single array of callbacks
  • Added support for multiple callbacks for app.param(). Closes #801 Closes #805
  • Changed: removed .call(self) for route callbacks
  • Dependency: qs >= 0.3.1
  • Fixed res.redirect() on windows due to join() usage. Closes #808

2.4.4 / 2011-08-05

  • Fixed res.header() intention of a set, even when undefined
  • Fixed *, value no longer required
  • Fixed res.send(204) support. Closes #771

2.4.3 / 2011-07-14

  • Added docs for status option special-case. Closes #739
  • Fixed options.filename, exposing the view path to template engines

2.4.2. / 2011-07-06

  • Revert "removed jsonp stripping" for XSS

2.4.1 / 2011-07-06

  • Added res.json() JSONP support. Closes #737
  • Added extending-templates example. Closes #730
  • Added "strict routing" setting for trailing slashes
  • Added support for multiple envs in app.configure() calls. Closes #735
  • Changed: res.send() using res.json()
  • Changed: when cookie path === null don't default it
  • Changed; default cookie path to "home" setting. Closes #731
  • Removed pids/logs creation from express(1)

2.4.0 / 2011-06-28

  • Added chainable res.status(code)
  • Added res.json(), an explicit version of res.send(obj)
  • Added simple web-service example

2.3.12 / 2011-06-22

  • #express is now on freenode! come join!
  • Added req.get(field, param)
  • Added links to Japanese documentation, thanks @hideyukisaito!
  • Added; the express(1) generated app outputs the env
  • Added content-negotiation example
  • Dependency: connect >= 1.5.1 < 2.0.0
  • Fixed view layout bug. Closes #720
  • Fixed; ignore body on 304. Closes #701

2.3.11 / 2011-06-04

  • Added npm test
  • Removed generation of dummy test file from express(1)
  • Fixed; express(1) adds express as a dep
  • Fixed; prune on prepublish

2.3.10 / 2011-05-27

  • Added req.route, exposing the current route
  • Added package.json generation support to express(1)
  • Fixed call to app.param() function for optional params. Closes #682

2.3.9 / 2011-05-25

  • Fixed bug-ish with ../' in res.partial()` calls

2.3.8 / 2011-05-24

  • Fixed app.options()

2.3.7 / 2011-05-23

  • Added route Collection, ex: app.get('/user/:id').remove();
  • Added support for app.param(fn) to define param logic
  • Removed app.param() support for callback with return value
  • Removed module.parent check from express(1) generated app. Closes #670
  • Refactored router. Closes #639

2.3.6 / 2011-05-20

  • Changed; using devDependencies instead of git submodules
  • Fixed redis session example
  • Fixed markdown example
  • Fixed view caching, should not be enabled in development

2.3.5 / 2011-05-20

  • Added export .view as alias for .View

2.3.4 / 2011-05-08

  • Added ./examples/say
  • Fixed res.sendfile() bug preventing the transfer of files with spaces

2.3.3 / 2011-05-03

  • Added "case sensitive routes" option.
  • Changed; split methods supported per rfc [slaskis]
  • Fixed route-specific middleware when using the same callback function several times

2.3.2 / 2011-04-27

  • Fixed view hints

2.3.1 / 2011-04-26

  • Added app.match() as app.match.all()
  • Added app.lookup() as app.lookup.all()
  • Added app.remove() for app.remove.all()
  • Added app.remove.VERB()
  • Fixed template caching collision issue. Closes #644
  • Moved router over from connect and started refactor

2.3.0 / 2011-04-25

  • Added options support to res.clearCookie()
  • Added res.helpers() as alias of res.locals()
  • Added; json defaults to UTF-8 with res.send(). Closes #632. [Daniel * Dependency connect >= 1.4.0
  • Changed; auto set Content-Type in res.attachement [Aaron Heckmann]
  • Renamed "cache views" to "view cache". Closes #628
  • Fixed caching of views when using several apps. Closes #637
  • Fixed gotcha invoking app.param() callbacks once per route middleware. Closes #638
  • Fixed partial lookup precedence. Closes #631 Shaw]

2.2.2 / 2011-04-12

  • Added second callback support for res.download() connection errors
  • Fixed filename option passing to template engine

2.2.1 / 2011-04-04

  • Added layout(path) helper to change the layout within a view. Closes #610

  • Fixed partial() collection object support. Previously only anything with .length would work. When .length is present one must still be aware of holes, however now { collection: {foo: 'bar'}} is valid, exposes keyInCollection and keysInCollection.

  • Performance improved with better view caching

  • Removed request and response locals

  • Changed; errorHandler page title is now Express instead of Connect

2.2.0 / 2011-03-30

  • Added app.lookup.VERB(), ex app.lookup.put('/user/:id'). Closes #606
  • Added app.match.VERB(), ex app.match.put('/user/12'). Closes #606
  • Added app.VERB(path) as alias of app.lookup.VERB().
  • Dependency connect >= 1.2.0

2.1.1 / 2011-03-29

  • Added; expose err.view object when failing to locate a view
  • Fixed res.partial() call next(err) when no callback is given [reported by aheckmann]
  • Fixed; res.send(undefined) responds with 204 [aheckmann]

2.1.0 / 2011-03-24

  • Added <root>/_?<name> partial lookup support. Closes #447
  • Added request, response, and app local variables
  • Added settings local variable, containing the app's settings
  • Added req.flash() exception if req.session is not available
  • Added res.send(bool) support (json response)
  • Fixed stylus example for latest version
  • Fixed; wrap try/catch around res.render()

2.0.0 / 2011-03-17

  • Fixed up index view path alternative.
  • Changed; res.locals() without object returns the locals

2.0.0rc3 / 2011-03-17

  • Added res.locals(obj) to compliment res.local(key, val)
  • Added res.partial() callback support
  • Fixed recursive error reporting issue in res.render()

2.0.0rc2 / 2011-03-17

  • Changed; partial() "locals" are now optional
  • Fixed SlowBuffer support. Closes #584 [reported by tyrda01]
  • Fixed .filename view engine option [reported by drudge]
  • Fixed blog example
  • Fixed {req,res}.app reference when mounting [Ben Weaver]

2.0.0rc / 2011-03-14

  • Fixed; expose HTTPSServer constructor
  • Fixed express(1) default test charset. Closes #579 [reported by secoif]
  • Fixed; default charset to utf-8 instead of utf8 for lame IE [reported by NickP]

2.0.0beta3 / 2011-03-09

  • Added support for res.contentType() literal The original res.contentType('.json'), res.contentType('application/json'), and res.contentType('json') will work now.
  • Added res.render() status option support back
  • Added charset option for res.render()
  • Added .charset support (via connect 1.0.4)
  • Added view resolution hints when in development and a lookup fails
  • Added layout lookup support relative to the page view. For example while rendering ./views/user/index.jade if you create ./views/user/layout.jade it will be used in favour of the root layout.
  • Fixed res.redirect(). RFC states absolute url [reported by unlink]
  • Fixed; default res.send() string charset to utf8
  • Removed Partial constructor (not currently used)

2.0.0beta2 / 2011-03-07

  • Added res.render() .locals support back to aid in migration process
  • Fixed flash example

2.0.0beta / 2011-03-03

  • Added HTTPS support
  • Added res.cookie() maxAge support
  • Added req.header() Referrer / Referer special-case, either works
  • Added mount support for res.redirect(), now respects the mount-point
  • Added union() util, taking place of merge(clone()) combo
  • Added stylus support to express(1) generated app
  • Added secret to session middleware used in examples and generated app
  • Added res.local(name, val) for progressive view locals
  • Added default param support to req.param(name, default)
  • Added app.disabled() and app.enabled()
  • Added app.register() support for omitting leading ".", either works
  • Added res.partial(), using the same interface as partial() within a view. Closes #539
  • Added app.param() to map route params to async/sync logic
  • Added; aliased app.helpers() as app.locals(). Closes #481
  • Added extname with no leading "." support to res.contentType()
  • Added cache views setting, defaulting to enabled in "production" env
  • Added index file partial resolution, eg: partial('user') may try views/user/index.jade.
  • Added req.accepts() support for extensions
  • Changed; res.download() and res.sendfile() now utilize Connect's static file server connect.static.send().
  • Changed; replaced connect.utils.mime() with npm mime module
  • Changed; allow req.query to be pre-defined (via middleware or other parent
  • Changed view partial resolution, now relative to parent view
  • Changed view engine signature. no longer engine.render(str, options, callback), now engine.compile(str, options) -> Function, the returned function accepts fn(locals).
  • Fixed req.param() bug returning Array.prototype methods. Closes #552
  • Fixed; using Stream#pipe() instead of sys.pump() in res.sendfile()
  • Fixed; using qs module instead of querystring
  • Fixed; strip unsafe chars from jsonp callbacks
  • Removed "stream threshold" setting

1.0.8 / 2011-03-01

  • Allow req.query to be pre-defined (via middleware or other parent app)
  • "connect": ">= 0.5.0 < 1.0.0". Closes #547
  • Removed the long deprecated EXPRESS_ENV support

1.0.7 / 2011-02-07

  • Fixed render() setting inheritance. Mounted apps would not inherit "view engine"

1.0.6 / 2011-02-07

  • Fixed view engine setting bug when period is in dirname

1.0.5 / 2011-02-05

  • Added secret to generated app session() call

1.0.4 / 2011-02-05

  • Added qs dependency to package.json
  • Fixed namespaced require()s for latest connect support

1.0.3 / 2011-01-13

  • Remove unsafe characters from JSONP callback names [Ryan Grove]

1.0.2 / 2011-01-10

  • Removed nested require, using connect.router

1.0.1 / 2010-12-29

  • Fixed for middleware stacked via createServer() previously the foo middleware passed to createServer(foo) would not have access to Express methods such as res.send() or props like req.query etc.

1.0.0 / 2010-11-16

  • Added; deduce partial object names from the last segment. For example by default partial('forum/post', postObject) will give you the post object, providing a meaningful default.
  • Added http status code string representation to res.redirect() body
  • Added; res.redirect() supporting text/plain and text/html via Accept.
  • Added req.is() to aid in content negotiation
  • Added partial local inheritance [suggested by masylum]. Closes #102 providing access to parent template locals.
  • Added -s, --session[s] flag to express(1) to add session related middleware
  • Added --template flag to express(1) to specify the template engine to use.
  • Added --css flag to express(1) to specify the stylesheet engine to use (or just plain css by default).
  • Added app.all() support [thanks aheckmann]
  • Added partial direct object support. You may now partial('user', user) providing the "user" local, vs previously partial('user', { object: user }).
  • Added route-separation example since many people question ways to do this with CommonJS modules. Also view the blog example for an alternative.
  • Performance; caching view path derived partial object names
  • Fixed partial local inheritance precedence. [reported by Nick Poulden] Closes #454
  • Fixed jsonp support; text/javascript as per mailinglist discussion

1.0.0rc4 / 2010-10-14

  • Added NODE_ENV support, EXPRESS_ENV is deprecated and will be removed in 1.0.0
  • Added route-middleware support (very helpful, see the docs)
  • Added jsonp callback setting to enable/disable jsonp autowrapping [Dav Glass]
  • Added callback query check on response.send to autowrap JSON objects for simple webservice implementations [Dav Glass]
  • Added partial() support for array-like collections. Closes #434
  • Added support for swappable querystring parsers
  • Added session usage docs. Closes #443
  • Added dynamic helper caching. Closes #439 [suggested by maritz]
  • Added authentication example
  • Added basic Range support to res.sendfile() (and res.download() etc)
  • Changed; express(1) generated app using 2 spaces instead of 4
  • Default env to "development" again [aheckmann]
  • Removed context option is no more, use "scope"
  • Fixed; exposing ./support libs to examples so they can run without installs
  • Fixed mvc example

1.0.0rc3 / 2010-09-20

  • Added confirmation for express(1) app generation. Closes #391
  • Added extending of flash formatters via app.flashFormatters
  • Added flash formatter support. Closes #411
  • Added streaming support to res.sendfile() using sys.pump() when >= "stream threshold"
  • Added stream threshold setting for res.sendfile()
  • Added res.send() HEAD support
  • Added res.clearCookie()
  • Added res.cookie()
  • Added res.render() headers option
  • Added res.redirect() response bodies
  • Added res.render() status option support. Closes #425 [thanks aheckmann]
  • Fixed res.sendfile() responding with 403 on malicious path
  • Fixed res.download() bug; when an error occurs remove Content-Disposition
  • Fixed; mounted apps settings now inherit from parent app [aheckmann]
  • Fixed; stripping Content-Length / Content-Type when 204
  • Fixed res.send() 204. Closes #419
  • Fixed multiple Set-Cookie headers via res.header(). Closes #402
  • Fixed bug messing with error handlers when listenFD() is called instead of listen(). [thanks guillermo]

1.0.0rc2 / 2010-08-17

  • Added app.register() for template engine mapping. Closes #390
  • Added res.render() callback support as second argument (no options)
  • Added callback support to res.download()
  • Added callback support for res.sendfile()
  • Added support for middleware access via express.middlewareName() vs connect.middlewareName()
  • Added "partials" setting to docs
  • Added default expresso tests to express(1) generated app. Closes #384
  • Fixed res.sendfile() error handling, defer via next()
  • Fixed res.render() callback when a layout is used [thanks guillermo]
  • Fixed; make install creating ~/.node_libraries when not present
  • Fixed issue preventing error handlers from being defined anywhere. Closes #387

1.0.0rc / 2010-07-28

  • Added mounted hook. Closes #369

  • Added connect dependency to package.json

  • Removed "reload views" setting and support code development env never caches, production always caches.

  • Removed param in route callbacks, signature is now simply (req, res, next), previously (req, res, params, next). Use req.params for path captures, req.query for GET params.

  • Fixed "home" setting

  • Fixed middleware/router precedence issue. Closes #366

  • Fixed; configure() callbacks called immediately. Closes #368

1.0.0beta2 / 2010-07-23

  • Added more examples
  • Added; exporting Server constructor
  • Added Server#helpers() for view locals
  • Added Server#dynamicHelpers() for dynamic view locals. Closes #349
  • Added support for absolute view paths
  • Added; home setting defaults to Server#route for mounted apps. Closes #363
  • Added Guillermo Rauch to the contributor list
  • Added support for "as" for non-collection partials. Closes #341
  • Fixed install.sh, ensuring ~/.node_libraries exists. Closes #362 [thanks jf]
  • Fixed res.render() exceptions, now passed to next() when no callback is given [thanks guillermo]
  • Fixed instanceof Array checks, now Array.isArray()
  • Fixed express(1) expansion of public dirs. Closes #348
  • Fixed middleware precedence. Closes #345
  • Fixed view watcher, now async [thanks aheckmann]

1.0.0beta / 2010-07-15

  • Re-write
    • much faster
    • much lighter
    • Check ExpressJS.com for migration guide and updated docs

0.14.0 / 2010-06-15

  • Utilize relative requires
  • Added Static bufferSize option [aheckmann]
  • Fixed caching of view and partial subdirectories [aheckmann]
  • Fixed mime.type() comments now that ".ext" is not supported
  • Updated haml submodule
  • Updated class submodule
  • Removed bin/express

0.13.0 / 2010-06-01

  • Added node v0.1.97 compatibility
  • Added support for deleting cookies via Request#cookie('key', null)
  • Updated haml submodule
  • Fixed not-found page, now using using charset utf-8
  • Fixed show-exceptions page, now using using charset utf-8
  • Fixed view support due to fs.readFile Buffers
  • Changed; mime.type() no longer accepts ".type" due to node extname() changes

0.12.0 / 2010-05-22

  • Added node v0.1.96 compatibility
  • Added view helpers export which act as additional local variables
  • Updated haml submodule
  • Changed ETag; removed inode, modified time only
  • Fixed LF to CRLF for setting multiple cookies
  • Fixed cookie complation; values are now urlencoded
  • Fixed cookies parsing; accepts quoted values and url escaped cookies

0.11.0 / 2010-05-06

  • Added support for layouts using different engines
    • this.render('page.html.haml', { layout: 'super-cool-layout.html.ejs' })
    • this.render('page.html.haml', { layout: 'foo' }) // assumes 'foo.html.haml'
    • this.render('page.html.haml', { layout: false }) // no layout
  • Updated ext submodule
  • Updated haml submodule
  • Fixed EJS partial support by passing along the context. Issue #307

0.10.1 / 2010-05-03

  • Fixed binary uploads.

0.10.0 / 2010-04-30

  • Added charset support via Request#charset (automatically assigned to 'UTF-8' when respond()'s encoding is set to 'utf8' or 'utf-8'.
  • Added "encoding" option to Request#render(). Closes #299
  • Added "dump exceptions" setting, which is enabled by default.
  • Added simple ejs template engine support
  • Added error response support for text/plain, application/json. Closes #297
  • Added callback function param to Request#error()
  • Added Request#sendHead()
  • Added Request#stream()
  • Added support for Request#respond(304, null) for empty response bodies
  • Added ETag support to Request#sendfile()
  • Added options to Request#sendfile(), passed to fs.createReadStream()
  • Added filename arg to Request#download()
  • Performance enhanced due to pre-reversing plugins so that plugins.reverse() is not called on each request
  • Performance enhanced by preventing several calls to toLowerCase() in Router#match()
  • Changed; Request#sendfile() now streams
  • Changed; Renamed Request#halt() to Request#respond(). Closes #289
  • Changed; Using sys.inspect() instead of JSON.encode() for error output
  • Changed; run() returns the http.Server instance. Closes #298
  • Changed; Defaulting Server#host to null (INADDR_ANY)
  • Changed; Logger "common" format scale of 0.4f
  • Removed Logger "request" format
  • Fixed; Catching ENOENT in view caching, preventing error when "views/partials" is not found
  • Fixed several issues with http client
  • Fixed Logger Content-Length output
  • Fixed bug preventing Opera from retaining the generated session id. Closes #292

0.9.0 / 2010-04-14

  • Added DSL level error() route support
  • Added DSL level notFound() route support
  • Added Request#error()
  • Added Request#notFound()
  • Added Request#render() callback function. Closes #258
  • Added "max upload size" setting
  • Added "magic" variables to collection partials (__index__, __length__, __isFirst__, __isLast__). Closes #254
  • Added haml.js submodule; removed haml-js
  • Added callback function support to Request#halt() as 3rd/4th arg
  • Added preprocessing of route param wildcards using param(). Closes #251
  • Added view partial support (with collections etc)
  • Fixed bug preventing falsey params (such as ?page=0). Closes #286
  • Fixed setting of multiple cookies. Closes #199
  • Changed; view naming convention is now NAME.TYPE.ENGINE (for example page.html.haml)
  • Changed; session cookie is now httpOnly
  • Changed; Request is no longer global
  • Changed; Event is no longer global
  • Changed; "sys" module is no longer global
  • Changed; moved Request#download to Static plugin where it belongs
  • Changed; Request instance created before body parsing. Closes #262
  • Changed; Pre-caching views in memory when "cache view contents" is enabled. Closes #253
  • Changed; Pre-caching view partials in memory when "cache view partials" is enabled
  • Updated support to node --version 0.1.90
  • Updated dependencies
  • Removed set("session cookie") in favour of use(Session, { cookie: { ... }})
  • Removed utils.mixin(); use Object#mergeDeep()

0.8.0 / 2010-03-19

  • Added coffeescript example app. Closes #242
  • Changed; cache api now async friendly. Closes #240
  • Removed deprecated 'express/static' support. Use 'express/plugins/static'

0.7.6 / 2010-03-19

  • Added Request#isXHR. Closes #229
  • Added make install (for the executable)
  • Added express executable for setting up simple app templates
  • Added "GET /public/*" to Static plugin, defaulting to /public
  • Added Static plugin
  • Fixed; Request#render() only calls cache.get() once
  • Fixed; Namespacing View caches with "view:"
  • Fixed; Namespacing Static caches with "static:"
  • Fixed; Both example apps now use the Static plugin
  • Fixed set("views"). Closes #239
  • Fixed missing space for combined log format
  • Deprecated Request#sendfile() and 'express/static'
  • Removed Server#running

0.7.5 / 2010-03-16

  • Added Request#flash() support without args, now returns all flashes
  • Updated ext submodule

0.7.4 / 2010-03-16

  • Fixed session reaper
  • Changed; class.js replacing js-oo Class implementation (quite a bit faster, no browser cruft)

0.7.3 / 2010-03-16

  • Added package.json
  • Fixed requiring of haml / sass due to kiwi removal

0.7.2 / 2010-03-16

  • Fixed GIT submodules (HAH!)

0.7.1 / 2010-03-16

  • Changed; Express now using submodules again until a PM is adopted
  • Changed; chat example using millisecond conversions from ext

0.7.0 / 2010-03-15

  • Added Request#pass() support (finds the next matching route, or the given path)
  • Added Logger plugin (default "common" format replaces CommonLogger)
  • Removed Profiler plugin
  • Removed CommonLogger plugin

0.6.0 / 2010-03-11

  • Added seed.yml for kiwi package management support

  • Added HTTP client query string support when method is GET. Closes #205

  • Added support for arbitrary view engines. For example "foo.engine.html" will now require('engine'), the exports from this module are cached after the first require().

  • Added async plugin support

  • Removed usage of RESTful route funcs as http client get() etc, use http.get() and friends

  • Removed custom exceptions

0.5.0 / 2010-03-10

  • Added ext dependency (library of js extensions)
  • Removed extname() / basename() utils. Use path module
  • Removed toArray() util. Use arguments.values
  • Removed escapeRegexp() util. Use RegExp.escape()
  • Removed process.mixin() dependency. Use utils.mixin()
  • Removed Collection
  • Removed ElementCollection
  • Shameless self promotion of ebook "Advanced JavaScript" (http://dev-mag.com) ;)

0.4.0 / 2010-02-11

  • Added flash() example to sample upload app
  • Added high level restful http client module (express/http)
  • Changed; RESTful route functions double as HTTP clients. Closes #69
  • Changed; throwing error when routes are added at runtime
  • Changed; defaulting render() context to the current Request. Closes #197
  • Updated haml submodule

0.3.0 / 2010-02-11

  • Updated haml / sass submodules. Closes #200
  • Added flash message support. Closes #64
  • Added accepts() now allows multiple args. fixes #117
  • Added support for plugins to halt. Closes #189
  • Added alternate layout support. Closes #119
  • Removed Route#run(). Closes #188
  • Fixed broken specs due to use(Cookie) missing

0.2.1 / 2010-02-05

  • Added "plot" format option for Profiler (for gnuplot processing)
  • Added request number to Profiler plugin
  • Fixed binary encoding for multi-part file uploads, was previously defaulting to UTF8
  • Fixed issue with routes not firing when not files are present. Closes #184
  • Fixed process.Promise -> events.Promise

0.2.0 / 2010-02-03

  • Added parseParam() support for name[] etc. (allows for file inputs with "multiple" attr) Closes #180
  • Added Both Cache and Session option "reapInterval" may be "reapEvery". Closes #174
  • Added expiration support to cache api with reaper. Closes #133
  • Added cache Store.Memory#reap()
  • Added Cache; cache api now uses first class Cache instances
  • Added abstract session Store. Closes #172
  • Changed; cache Memory.Store#get() utilizing Collection
  • Renamed MemoryStore -> Store.Memory
  • Fixed use() of the same plugin several time will always use latest options. Closes #176

0.1.0 / 2010-02-03

  • Changed; Hooks (before / after) pass request as arg as well as evaluated in their context
  • Updated node support to 0.1.27 Closes #169
  • Updated dirname(__filename) -> __dirname
  • Updated libxmljs support to v0.2.0
  • Added session support with memory store / reaping
  • Added quick uid() helper
  • Added multi-part upload support
  • Added Sass.js support / submodule
  • Added production env caching view contents and static files
  • Added static file caching. Closes #136
  • Added cache plugin with memory stores
  • Added support to StaticFile so that it works with non-textual files.
  • Removed dirname() helper
  • Removed several globals (now their modules must be required)

0.0.2 / 2010-01-10

  • Added view benchmarks; currently haml vs ejs
  • Added Request#attachment() specs. Closes #116
  • Added use of node's parseQuery() util. Closes #123
  • Added make init for submodules
  • Updated Haml
  • Updated sample chat app to show messages on load
  • Updated libxmljs parseString -> parseHtmlString
  • Fixed make init to work with older versions of git
  • Fixed specs can now run independent specs for those who cant build deps. Closes #127
  • Fixed issues introduced by the node url module changes. Closes 126.
  • Fixed two assertions failing due to Collection#keys() returning strings
  • Fixed faulty Collection#toArray() spec due to keys() returning strings
  • Fixed make test now builds libxmljs.node before testing

0.0.1 / 2010-01-03

  • Initial release
module.exports = require('./lib/express');
/*!
* express
* Copyright(c) 2009-2013 TJ Holowaychuk
* Copyright(c) 2013 Roman Shtylman
* Copyright(c) 2014-2015 Douglas Christopher Wilson
* MIT Licensed
*/
/**
* Module dependencies.
* @api private
*/
var finalhandler = require('finalhandler');
var flatten = require('./utils').flatten;
var Router = require('./router');
var methods = require('methods');
var middleware = require('./middleware/init');
var query = require('./middleware/query');
var debug = require('debug')('express:application');
var View = require('./view');
var http = require('http');
var compileETag = require('./utils').compileETag;
var compileQueryParser = require('./utils').compileQueryParser;
var compileTrust = require('./utils').compileTrust;
var deprecate = require('depd')('express');
var merge = require('utils-merge');
var resolve = require('path').resolve;
var slice = Array.prototype.slice;
/**
* Application prototype.
*/
var app = exports = module.exports = {};
/**
* Variable for trust proxy inheritance back-compat
* @api private
*/
var trustProxyDefaultSymbol = '@@symbol:trust_proxy_default';
/**
* Initialize the server.
*
* - setup default configuration
* - setup default middleware
* - setup route reflection methods
*
* @api private
*/
app.init = function(){
this.cache = {};
this.settings = {};
this.engines = {};
this.defaultConfiguration();
};
/**
* Initialize application configuration.
*
* @api private
*/
app.defaultConfiguration = function(){
// default settings
this.enable('x-powered-by');
this.set('etag', 'weak');
var env = process.env.NODE_ENV || 'development';
this.set('env', env);
this.set('query parser', 'extended');
this.set('subdomain offset', 2);
this.set('trust proxy', false);
// trust proxy inherit back-compat
Object.defineProperty(this.settings, trustProxyDefaultSymbol, {
configurable: true,
value: true
});
debug('booting in %s mode', env);
this.on('mount', function onmount(parent) {
// inherit trust proxy
if (this.settings[trustProxyDefaultSymbol] === true
&& typeof parent.settings['trust proxy fn'] === 'function') {
delete this.settings['trust proxy'];
delete this.settings['trust proxy fn'];
}
// inherit protos
this.request.__proto__ = parent.request;
this.response.__proto__ = parent.response;
this.engines.__proto__ = parent.engines;
this.settings.__proto__ = parent.settings;
});
// setup locals
this.locals = Object.create(null);
// top-most app is mounted at /
this.mountpath = '/';
// default locals
this.locals.settings = this.settings;
// default configuration
this.set('view', View);
this.set('views', resolve('views'));
this.set('jsonp callback name', 'callback');
if (env === 'production') {
this.enable('view cache');
}
Object.defineProperty(this, 'router', {
get: function() {
throw new Error('\'app.router\' is deprecated!\nPlease see the 3.x to 4.x migration guide for details on how to update your app.');
}
});
};
/**
* lazily adds the base router if it has not yet been added.
*
* We cannot add the base router in the defaultConfiguration because
* it reads app settings which might be set after that has run.
*
* @api private
*/
app.lazyrouter = function() {
if (!this._router) {
this._router = new Router({
caseSensitive: this.enabled('case sensitive routing'),
strict: this.enabled('strict routing')
});
this._router.use(query(this.get('query parser fn')));
this._router.use(middleware.init(this));
}
};
/**
* Dispatch a req, res pair into the application. Starts pipeline processing.
*
* If no _done_ callback is provided, then default error handlers will respond
* in the event of an error bubbling through the stack.
*
* @api private
*/
app.handle = function(req, res, done) {
var router = this._router;
// final handler
done = done || finalhandler(req, res, {
env: this.get('env'),
onerror: logerror.bind(this)
});
// no routes
if (!router) {
debug('no routes defined on app');
done();
return;
}
router.handle(req, res, done);
};
/**
* Proxy `Router#use()` to add middleware to the app router.
* See Router#use() documentation for details.
*
* If the _fn_ parameter is an express app, then it will be
* mounted at the _route_ specified.
*
* @api public
*/
app.use = function use(fn) {
var offset = 0;
var path = '/';
// default path to '/'
// disambiguate app.use([fn])
if (typeof fn !== 'function') {
var arg = fn;
while (Array.isArray(arg) && arg.length !== 0) {
arg = arg[0];
}
// first arg is the path
if (typeof arg !== 'function') {
offset = 1;
path = fn;
}
}
var fns = flatten(slice.call(arguments, offset));
if (fns.length === 0) {
throw new TypeError('app.use() requires middleware functions');
}
// setup router
this.lazyrouter();
var router = this._router;
fns.forEach(function (fn) {
// non-express app
if (!fn || !fn.handle || !fn.set) {
return router.use(path, fn);
}
debug('.use app under %s', path);
fn.mountpath = path;
fn.parent = this;
// restore .app property on req and res
router.use(path, function mounted_app(req, res, next) {
var orig = req.app;
fn.handle(req, res, function (err) {
req.__proto__ = orig.request;
res.__proto__ = orig.response;
next(err);
});
});
// mounted an app
fn.emit('mount', this);
}, this);
return this;
};
/**
* Proxy to the app `Router#route()`
* Returns a new `Route` instance for the _path_.
*
* Routes are isolated middleware stacks for specific paths.
* See the Route api docs for details.
*
* @api public
*/
app.route = function(path){
this.lazyrouter();
return this._router.route(path);
};
/**
* Register the given template engine callback `fn`
* as `ext`.
*
* By default will `require()` the engine based on the
* file extension. For example if you try to render
* a "foo.jade" file Express will invoke the following internally:
*
* app.engine('jade', require('jade').__express);
*
* For engines that do not provide `.__express` out of the box,
* or if you wish to "map" a different extension to the template engine
* you may use this method. For example mapping the EJS template engine to
* ".html" files:
*
* app.engine('html', require('ejs').renderFile);
*
* In this case EJS provides a `.renderFile()` method with
* the same signature that Express expects: `(path, options, callback)`,
* though note that it aliases this method as `ejs.__express` internally
* so if you're using ".ejs" extensions you dont need to do anything.
*
* Some template engines do not follow this convention, the
* [Consolidate.js](https://github.com/tj/consolidate.js)
* library was created to map all of node's popular template
* engines to follow this convention, thus allowing them to
* work seamlessly within Express.
*
* @param {String} ext
* @param {Function} fn
* @return {app} for chaining
* @api public
*/
app.engine = function(ext, fn){
if ('function' != typeof fn) throw new Error('callback function required');
if ('.' != ext[0]) ext = '.' + ext;
this.engines[ext] = fn;
return this;
};
/**
* Proxy to `Router#param()` with one added api feature. The _name_ parameter
* can be an array of names.
*
* See the Router#param() docs for more details.
*
* @param {String|Array} name
* @param {Function} fn
* @return {app} for chaining
* @api public
*/
app.param = function(name, fn){
this.lazyrouter();
if (Array.isArray(name)) {
name.forEach(function(key) {
this.param(key, fn);
}, this);
return this;
}
this._router.param(name, fn);
return this;
};
/**
* Assign `setting` to `val`, or return `setting`'s value.
*
* app.set('foo', 'bar');
* app.get('foo');
* // => "bar"
*
* Mounted servers inherit their parent server's settings.
*
* @param {String} setting
* @param {*} [val]
* @return {Server} for chaining
* @api public
*/
app.set = function(setting, val){
if (arguments.length === 1) {
// app.get(setting)
return this.settings[setting];
}
// set value
this.settings[setting] = val;
// trigger matched settings
switch (setting) {
case 'etag':
debug('compile etag %s', val);
this.set('etag fn', compileETag(val));
break;
case 'query parser':
debug('compile query parser %s', val);
this.set('query parser fn', compileQueryParser(val));
break;
case 'trust proxy':
debug('compile trust proxy %s', val);
this.set('trust proxy fn', compileTrust(val));
// trust proxy inherit back-compat
Object.defineProperty(this.settings, trustProxyDefaultSymbol, {
configurable: true,
value: false
});
break;
}
return this;
};
/**
* Return the app's absolute pathname
* based on the parent(s) that have
* mounted it.
*
* For example if the application was
* mounted as "/admin", which itself
* was mounted as "/blog" then the
* return value would be "/blog/admin".
*
* @return {String}
* @api private
*/
app.path = function(){
return this.parent
? this.parent.path() + this.mountpath
: '';
};
/**
* Check if `setting` is enabled (truthy).
*
* app.enabled('foo')
* // => false
*
* app.enable('foo')
* app.enabled('foo')
* // => true
*
* @param {String} setting
* @return {Boolean}
* @api public
*/
app.enabled = function(setting){
return !!this.set(setting);
};
/**
* Check if `setting` is disabled.
*
* app.disabled('foo')
* // => true
*
* app.enable('foo')
* app.disabled('foo')
* // => false
*
* @param {String} setting
* @return {Boolean}
* @api public
*/
app.disabled = function(setting){
return !this.set(setting);
};
/**
* Enable `setting`.
*
* @param {String} setting
* @return {app} for chaining
* @api public
*/
app.enable = function(setting){
return this.set(setting, true);
};
/**
* Disable `setting`.
*
* @param {String} setting
* @return {app} for chaining
* @api public
*/
app.disable = function(setting){
return this.set(setting, false);
};
/**
* Delegate `.VERB(...)` calls to `router.VERB(...)`.
*/
methods.forEach(function(method){
app[method] = function(path){
if ('get' == method && 1 == arguments.length) return this.set(path);
this.lazyrouter();
var route = this._router.route(path);
route[method].apply(route, slice.call(arguments, 1));
return this;
};
});
/**
* Special-cased "all" method, applying the given route `path`,
* middleware, and callback to _every_ HTTP method.
*
* @param {String} path
* @param {Function} ...
* @return {app} for chaining
* @api public
*/
app.all = function(path){
this.lazyrouter();
var route = this._router.route(path);
var args = slice.call(arguments, 1);
methods.forEach(function(method){
route[method].apply(route, args);
});
return this;
};
// del -> delete alias
app.del = deprecate.function(app.delete, 'app.del: Use app.delete instead');
/**
* Render the given view `name` name with `options`
* and a callback accepting an error and the
* rendered template string.
*
* Example:
*
* app.render('email', { name: 'Tobi' }, function(err, html){
* // ...
* })
*
* @param {String} name
* @param {String|Function} options or fn
* @param {Function} fn
* @api public
*/
app.render = function(name, options, fn){
var opts = {};
var cache = this.cache;
var engines = this.engines;
var view;
// support callback function as second arg
if ('function' == typeof options) {
fn = options, options = {};
}
// merge app.locals
merge(opts, this.locals);
// merge options._locals
if (options._locals) {
merge(opts, options._locals);
}
// merge options
merge(opts, options);
// set .cache unless explicitly provided
opts.cache = null == opts.cache
? this.enabled('view cache')
: opts.cache;
// primed cache
if (opts.cache) view = cache[name];
// view
if (!view) {
view = new (this.get('view'))(name, {
defaultEngine: this.get('view engine'),
root: this.get('views'),
engines: engines
});
if (!view.path) {
var dirs = Array.isArray(view.root) && view.root.length > 1
? 'directories "' + view.root.slice(0, -1).join('", "') + '" or "' + view.root[view.root.length - 1] + '"'
: 'directory "' + view.root + '"'
var err = new Error('Failed to lookup view "' + name + '" in views ' + dirs);
err.view = view;
return fn(err);
}
// prime the cache
if (opts.cache) cache[name] = view;
}
// render
try {
view.render(opts, fn);
} catch (err) {
fn(err);
}
};
/**
* Listen for connections.
*
* A node `http.Server` is returned, with this
* application (which is a `Function`) as its
* callback. If you wish to create both an HTTP
* and HTTPS server you may do so with the "http"
* and "https" modules as shown here:
*
* var http = require('http')
* , https = require('https')
* , express = require('express')
* , app = express();
*
* http.createServer(app).listen(80);
* https.createServer({ ... }, app).listen(443);
*
* @return {http.Server}
* @api public
*/
app.listen = function(){
var server = http.createServer(this);
return server.listen.apply(server, arguments);
};
/**
* Log error using console.error.
*
* @param {Error} err
* @api private
*/
function logerror(err){
if (this.get('env') !== 'test') console.error(err.stack || err.toString());
}
/**
* Module dependencies.
*/
var EventEmitter = require('events').EventEmitter;
var mixin = require('merge-descriptors');
var proto = require('./application');
var Route = require('./router/route');
var Router = require('./router');
var req = require('./request');
var res = require('./response');
/**
* Expose `createApplication()`.
*/
exports = module.exports = createApplication;
/**
* Create an express application.
*
* @return {Function}
* @api public
*/
function createApplication() {
var app = function(req, res, next) {
app.handle(req, res, next);
};
mixin(app, EventEmitter.prototype, false);
mixin(app, proto, false);
app.request = { __proto__: req, app: app };
app.response = { __proto__: res, app: app };
app.init();
return app;
}
/**
* Expose the prototypes.
*/
exports.application = proto;
exports.request = req;
exports.response = res;
/**
* Expose constructors.
*/
exports.Route = Route;
exports.Router = Router;
/**
* Expose middleware
*/
exports.query = require('./middleware/query');
exports.static = require('serve-static');
/**
* Replace removed middleware with an appropriate error message.
*/
[
'json',
'urlencoded',
'bodyParser',
'compress',
'cookieSession',
'session',
'logger',
'cookieParser',
'favicon',
'responseTime',
'errorHandler',
'timeout',
'methodOverride',
'vhost',
'csrf',
'directory',
'limit',
'multipart',
'staticCache',
].forEach(function (name) {
Object.defineProperty(exports, name, {
get: function () {
throw new Error('Most middleware (like ' + name + ') is no longer bundled with Express and must be installed separately. Please see https://github.com/senchalabs/connect#middleware.');
},
configurable: true
});
});
/**
* Initialization middleware, exposing the
* request and response to each other, as well
* as defaulting the X-Powered-By header field.
*
* @param {Function} app
* @return {Function}
* @api private
*/
exports.init = function(app){
return function expressInit(req, res, next){
if (app.enabled('x-powered-by')) res.setHeader('X-Powered-By', 'Express');
req.res = res;
res.req = req;
req.next = next;
req.__proto__ = app.request;
res.__proto__ = app.response;
res.locals = res.locals || Object.create(null);
next();
};
};
/**
* Module dependencies.
*/
var parseUrl = require('parseurl');
var qs = require('qs');
/**
* @param {Object} options
* @return {Function}
* @api public
*/
module.exports = function query(options) {
var queryparse = qs.parse;
if (typeof options === 'function') {
queryparse = options;
options = undefined;
}
return function query(req, res, next){
if (!req.query) {
var val = parseUrl(req).query;
req.query = queryparse(val, options);
}
next();
};
};
/**
* Module dependencies.
*/
var accepts = require('accepts');
var deprecate = require('depd')('express');
var isIP = require('net').isIP;
var typeis = require('type-is');
var http = require('http');
var fresh = require('fresh');
var parseRange = require('range-parser');
var parse = require('parseurl');
var proxyaddr = require('proxy-addr');
/**
* Request prototype.
*/
var req = exports = module.exports = {
__proto__: http.IncomingMessage.prototype
};
/**
* Return request header.
*
* The `Referrer` header field is special-cased,
* both `Referrer` and `Referer` are interchangeable.
*
* Examples:
*
* req.get('Content-Type');
* // => "text/plain"
*
* req.get('content-type');
* // => "text/plain"
*
* req.get('Something');
* // => undefined
*
* Aliased as `req.header()`.
*
* @param {String} name
* @return {String}
* @api public
*/
req.get =
req.header = function(name){
switch (name = name.toLowerCase()) {
case 'referer':
case 'referrer':
return this.headers.referrer
|| this.headers.referer;
default:
return this.headers[name];
}
};
/**
* To do: update docs.
*
* Check if the given `type(s)` is acceptable, returning
* the best match when true, otherwise `undefined`, in which
* case you should respond with 406 "Not Acceptable".
*
* The `type` value may be a single MIME type string
* such as "application/json", an extension name
* such as "json", a comma-delimited list such as "json, html, text/plain",
* an argument list such as `"json", "html", "text/plain"`,
* or an array `["json", "html", "text/plain"]`. When a list
* or array is given, the _best_ match, if any is returned.
*
* Examples:
*
* // Accept: text/html
* req.accepts('html');
* // => "html"
*
* // Accept: text/*, application/json
* req.accepts('html');
* // => "html"
* req.accepts('text/html');
* // => "text/html"
* req.accepts('json, text');
* // => "json"
* req.accepts('application/json');
* // => "application/json"
*
* // Accept: text/*, application/json
* req.accepts('image/png');
* req.accepts('png');
* // => undefined
*
* // Accept: text/*;q=.5, application/json
* req.accepts(['html', 'json']);
* req.accepts('html', 'json');
* req.accepts('html, json');
* // => "json"
*
* @param {String|Array} type(s)
* @return {String}
* @api public
*/
req.accepts = function(){
var accept = accepts(this);
return accept.types.apply(accept, arguments);
};
/**
* Check if the given `encoding`s are accepted.
*
* @param {String} ...encoding
* @return {Boolean}
* @api public
*/
req.acceptsEncodings = function(){
var accept = accepts(this);
return accept.encodings.apply(accept, arguments);
};
req.acceptsEncoding = deprecate.function(req.acceptsEncodings,
'req.acceptsEncoding: Use acceptsEncodings instead');
/**
* Check if the given `charset`s are acceptable,
* otherwise you should respond with 406 "Not Acceptable".
*
* @param {String} ...charset
* @return {Boolean}
* @api public
*/
req.acceptsCharsets = function(){
var accept = accepts(this);
return accept.charsets.apply(accept, arguments);
};
req.acceptsCharset = deprecate.function(req.acceptsCharsets,
'req.acceptsCharset: Use acceptsCharsets instead');
/**
* Check if the given `lang`s are acceptable,
* otherwise you should respond with 406 "Not Acceptable".
*
* @param {String} ...lang
* @return {Boolean}
* @api public
*/
req.acceptsLanguages = function(){
var accept = accepts(this);
return accept.languages.apply(accept, arguments);
};
req.acceptsLanguage = deprecate.function(req.acceptsLanguages,
'req.acceptsLanguage: Use acceptsLanguages instead');
/**
* Parse Range header field,
* capping to the given `size`.
*
* Unspecified ranges such as "0-" require
* knowledge of your resource length. In
* the case of a byte range this is of course
* the total number of bytes. If the Range
* header field is not given `null` is returned,
* `-1` when unsatisfiable, `-2` when syntactically invalid.
*
* NOTE: remember that ranges are inclusive, so
* for example "Range: users=0-3" should respond
* with 4 users when available, not 3.
*
* @param {Number} size
* @return {Array}
* @api public
*/
req.range = function(size){
var range = this.get('Range');
if (!range) return;
return parseRange(size, range);
};
/**
* Return the value of param `name` when present or `defaultValue`.
*
* - Checks route placeholders, ex: _/user/:id_
* - Checks body params, ex: id=12, {"id":12}
* - Checks query string params, ex: ?id=12
*
* To utilize request bodies, `req.body`
* should be an object. This can be done by using
* the `bodyParser()` middleware.
*
* @param {String} name
* @param {Mixed} [defaultValue]
* @return {String}
* @api public
*/
req.param = function param(name, defaultValue) {
var params = this.params || {};
var body = this.body || {};
var query = this.query || {};
var args = arguments.length === 1
? 'name'
: 'name, default';
deprecate('req.param(' + args + '): Use req.params, req.body, or req.query instead');
if (null != params[name] && params.hasOwnProperty(name)) return params[name];
if (null != body[name]) return body[name];
if (null != query[name]) return query[name];
return defaultValue;
};
/**
* Check if the incoming request contains the "Content-Type"
* header field, and it contains the give mime `type`.
*
* Examples:
*
* // With Content-Type: text/html; charset=utf-8
* req.is('html');
* req.is('text/html');
* req.is('text/*');
* // => true
*
* // When Content-Type is application/json
* req.is('json');
* req.is('application/json');
* req.is('application/*');
* // => true
*
* req.is('html');
* // => false
*
* @param {String} type
* @return {Boolean}
* @api public
*/
req.is = function(types){
if (!Array.isArray(types)) types = [].slice.call(arguments);
return typeis(this, types);
};
/**
* Return the protocol string "http" or "https"
* when requested with TLS. When the "trust proxy"
* setting trusts the socket address, the
* "X-Forwarded-Proto" header field will be trusted
* and used if present.
*
* If you're running behind a reverse proxy that
* supplies https for you this may be enabled.
*
* @return {String}
* @api public
*/
defineGetter(req, 'protocol', function protocol(){
var proto = this.connection.encrypted
? 'https'
: 'http';
var trust = this.app.get('trust proxy fn');
if (!trust(this.connection.remoteAddress, 0)) {
return proto;
}
// Note: X-Forwarded-Proto is normally only ever a
// single value, but this is to be safe.
proto = this.get('X-Forwarded-Proto') || proto;
return proto.split(/\s*,\s*/)[0];
});
/**
* Short-hand for:
*
* req.protocol == 'https'
*
* @return {Boolean}
* @api public
*/
defineGetter(req, 'secure', function secure(){
return 'https' == this.protocol;
});
/**
* Return the remote address from the trusted proxy.
*
* The is the remote address on the socket unless
* "trust proxy" is set.
*
* @return {String}
* @api public
*/
defineGetter(req, 'ip', function ip(){
var trust = this.app.get('trust proxy fn');
return proxyaddr(this, trust);
});
/**
* When "trust proxy" is set, trusted proxy addresses + client.
*
* For example if the value were "client, proxy1, proxy2"
* you would receive the array `["client", "proxy1", "proxy2"]`
* where "proxy2" is the furthest down-stream and "proxy1" and
* "proxy2" were trusted.
*
* @return {Array}
* @api public
*/
defineGetter(req, 'ips', function ips() {
var trust = this.app.get('trust proxy fn');
var addrs = proxyaddr.all(this, trust);
return addrs.slice(1).reverse();
});
/**
* Return subdomains as an array.
*
* Subdomains are the dot-separated parts of the host before the main domain of
* the app. By default, the domain of the app is assumed to be the last two
* parts of the host. This can be changed by setting "subdomain offset".
*
* For example, if the domain is "tobi.ferrets.example.com":
* If "subdomain offset" is not set, req.subdomains is `["ferrets", "tobi"]`.
* If "subdomain offset" is 3, req.subdomains is `["tobi"]`.
*
* @return {Array}
* @api public
*/
defineGetter(req, 'subdomains', function subdomains() {
var hostname = this.hostname;
if (!hostname) return [];
var offset = this.app.get('subdomain offset');
var subdomains = !isIP(hostname)
? hostname.split('.').reverse()
: [hostname];
return subdomains.slice(offset);
});
/**
* Short-hand for `url.parse(req.url).pathname`.
*
* @return {String}
* @api public
*/
defineGetter(req, 'path', function path() {
return parse(this).pathname;
});
/**
* Parse the "Host" header field to a hostname.
*
* When the "trust proxy" setting trusts the socket
* address, the "X-Forwarded-Host" header field will
* be trusted.
*
* @return {String}
* @api public
*/
defineGetter(req, 'hostname', function hostname(){
var trust = this.app.get('trust proxy fn');
var host = this.get('X-Forwarded-Host');
if (!host || !trust(this.connection.remoteAddress, 0)) {
host = this.get('Host');
}
if (!host) return;
// IPv6 literal support
var offset = host[0] === '['
? host.indexOf(']') + 1
: 0;
var index = host.indexOf(':', offset);
return ~index
? host.substring(0, index)
: host;
});
// TODO: change req.host to return host in next major
defineGetter(req, 'host', deprecate.function(function host(){
return this.hostname;
}, 'req.host: Use req.hostname instead'));
/**
* Check if the request is fresh, aka
* Last-Modified and/or the ETag
* still match.
*
* @return {Boolean}
* @api public
*/
defineGetter(req, 'fresh', function(){
var method = this.method;
var s = this.res.statusCode;
// GET or HEAD for weak freshness validation only
if ('GET' != method && 'HEAD' != method) return false;
// 2xx or 304 as per rfc2616 14.26
if ((s >= 200 && s < 300) || 304 == s) {
return fresh(this.headers, (this.res._headers || {}));
}
return false;
});
/**
* Check if the request is stale, aka
* "Last-Modified" and / or the "ETag" for the
* resource has changed.
*
* @return {Boolean}
* @api public
*/
defineGetter(req, 'stale', function stale(){
return !this.fresh;
});
/**
* Check if the request was an _XMLHttpRequest_.
*
* @return {Boolean}
* @api public
*/
defineGetter(req, 'xhr', function xhr(){
var val = this.get('X-Requested-With') || '';
return 'xmlhttprequest' == val.toLowerCase();
});
/**
* Helper function for creating a getter on an object.
*
* @param {Object} obj
* @param {String} name
* @param {Function} getter
* @api private
*/
function defineGetter(obj, name, getter) {
Object.defineProperty(obj, name, {
configurable: true,
enumerable: true,
get: getter
});
};
/*!
* express
* Copyright(c) 2009-2013 TJ Holowaychuk
* Copyright(c) 2014-2015 Douglas Christopher Wilson
* MIT Licensed
*/
/**
* Module dependencies.
* @api private
*/
var contentDisposition = require('content-disposition');
var deprecate = require('depd')('express');
var escapeHtml = require('escape-html');
var http = require('http');
var isAbsolute = require('./utils').isAbsolute;
var onFinished = require('on-finished');
var path = require('path');
var merge = require('utils-merge');
var sign = require('cookie-signature').sign;
var normalizeType = require('./utils').normalizeType;
var normalizeTypes = require('./utils').normalizeTypes;
var setCharset = require('./utils').setCharset;
var statusCodes = http.STATUS_CODES;
var cookie = require('cookie');
var send = require('send');
var extname = path.extname;
var mime = send.mime;
var resolve = path.resolve;
var vary = require('vary');
/**
* Response prototype.
*/
var res = module.exports = {
__proto__: http.ServerResponse.prototype
};
/**
* Set status `code`.
*
* @param {Number} code
* @return {ServerResponse}
* @api public
*/
res.status = function(code){
this.statusCode = code;
return this;
};
/**
* Set Link header field with the given `links`.
*
* Examples:
*
* res.links({
* next: 'http://api.example.com/users?page=2',
* last: 'http://api.example.com/users?page=5'
* });
*
* @param {Object} links
* @return {ServerResponse}
* @api public
*/
res.links = function(links){
var link = this.get('Link') || '';
if (link) link += ', ';
return this.set('Link', link + Object.keys(links).map(function(rel){
return '<' + links[rel] + '>; rel="' + rel + '"';
}).join(', '));
};
/**
* Send a response.
*
* Examples:
*
* res.send(new Buffer('wahoo'));
* res.send({ some: 'json' });
* res.send('<p>some html</p>');
*
* @param {string|number|boolean|object|Buffer} body
* @api public
*/
res.send = function send(body) {
var chunk = body;
var encoding;
var len;
var req = this.req;
var type;
// settings
var app = this.app;
// allow status / body
if (arguments.length === 2) {
// res.send(body, status) backwards compat
if (typeof arguments[0] !== 'number' && typeof arguments[1] === 'number') {
deprecate('res.send(body, status): Use res.status(status).send(body) instead');
this.statusCode = arguments[1];
} else {
deprecate('res.send(status, body): Use res.status(status).send(body) instead');
this.statusCode = arguments[0];
chunk = arguments[1];
}
}
// disambiguate res.send(status) and res.send(status, num)
if (typeof chunk === 'number' && arguments.length === 1) {
// res.send(status) will set status message as text string
if (!this.get('Content-Type')) {
this.type('txt');
}
deprecate('res.send(status): Use res.sendStatus(status) instead');
this.statusCode = chunk;
chunk = http.STATUS_CODES[chunk];
}
switch (typeof chunk) {
// string defaulting to html
case 'string':
if (!this.get('Content-Type')) {
this.type('html');
}
break;
case 'boolean':
case 'number':
case 'object':
if (chunk === null) {
chunk = '';
} else if (Buffer.isBuffer(chunk)) {
if (!this.get('Content-Type')) {
this.type('bin');
}
} else {
return this.json(chunk);
}
break;
}
// write strings in utf-8
if (typeof chunk === 'string') {
encoding = 'utf8';
type = this.get('Content-Type');
// reflect this in content-type
if (typeof type === 'string') {
this.set('Content-Type', setCharset(type, 'utf-8'));
}
}
// populate Content-Length
if (chunk !== undefined) {
if (!Buffer.isBuffer(chunk)) {
// convert chunk to Buffer; saves later double conversions
chunk = new Buffer(chunk, encoding);
encoding = undefined;
}
len = chunk.length;
this.set('Content-Length', len);
}
// populate ETag
var etag;
var generateETag = len !== undefined && app.get('etag fn');
if (typeof generateETag === 'function' && !this.get('ETag')) {
if ((etag = generateETag(chunk, encoding))) {
this.set('ETag', etag);
}
}
// freshness
if (req.fresh) this.statusCode = 304;
// strip irrelevant headers
if (204 == this.statusCode || 304 == this.statusCode) {
this.removeHeader('Content-Type');
this.removeHeader('Content-Length');
this.removeHeader('Transfer-Encoding');
chunk = '';
}
if (req.method === 'HEAD') {
// skip body for HEAD
this.end();
} else {
// respond
this.end(chunk, encoding);
}
return this;
};
/**
* Send JSON response.
*
* Examples:
*
* res.json(null);
* res.json({ user: 'tj' });
*
* @param {string|number|boolean|object} obj
* @api public
*/
res.json = function json(obj) {
var val = obj;
// allow status / body
if (arguments.length === 2) {
// res.json(body, status) backwards compat
if (typeof arguments[1] === 'number') {
deprecate('res.json(obj, status): Use res.status(status).json(obj) instead');
this.statusCode = arguments[1];
} else {
deprecate('res.json(status, obj): Use res.status(status).json(obj) instead');
this.statusCode = arguments[0];
val = arguments[1];
}
}
// settings
var app = this.app;
var replacer = app.get('json replacer');
var spaces = app.get('json spaces');
var body = JSON.stringify(val, replacer, spaces);
// content-type
if (!this.get('Content-Type')) {
this.set('Content-Type', 'application/json');
}
return this.send(body);
};
/**
* Send JSON response with JSONP callback support.
*
* Examples:
*
* res.jsonp(null);
* res.jsonp({ user: 'tj' });
*
* @param {string|number|boolean|object} obj
* @api public
*/
res.jsonp = function jsonp(obj) {
var val = obj;
// allow status / body
if (arguments.length === 2) {
// res.json(body, status) backwards compat
if (typeof arguments[1] === 'number') {
deprecate('res.jsonp(obj, status): Use res.status(status).json(obj) instead');
this.statusCode = arguments[1];
} else {
deprecate('res.jsonp(status, obj): Use res.status(status).jsonp(obj) instead');
this.statusCode = arguments[0];
val = arguments[1];
}
}
// settings
var app = this.app;
var replacer = app.get('json replacer');
var spaces = app.get('json spaces');
var body = JSON.stringify(val, replacer, spaces);
var callback = this.req.query[app.get('jsonp callback name')];
// content-type
if (!this.get('Content-Type')) {
this.set('X-Content-Type-Options', 'nosniff');
this.set('Content-Type', 'application/json');
}
// fixup callback
if (Array.isArray(callback)) {
callback = callback[0];
}
// jsonp
if (typeof callback === 'string' && callback.length !== 0) {
this.charset = 'utf-8';
this.set('X-Content-Type-Options', 'nosniff');
this.set('Content-Type', 'text/javascript');
// restrict callback charset
callback = callback.replace(/[^\[\]\w$.]/g, '');
// replace chars not allowed in JavaScript that are in JSON
body = body
.replace(/\u2028/g, '\\u2028')
.replace(/\u2029/g, '\\u2029');
// the /**/ is a specific security mitigation for "Rosetta Flash JSONP abuse"
// the typeof check is just to reduce client error noise
body = '/**/ typeof ' + callback + ' === \'function\' && ' + callback + '(' + body + ');';
}
return this.send(body);
};
/**
* Send given HTTP status code.
*
* Sets the response status to `statusCode` and the body of the
* response to the standard description from node's http.STATUS_CODES
* or the statusCode number if no description.
*
* Examples:
*
* res.sendStatus(200);
*
* @param {number} statusCode
* @api public
*/
res.sendStatus = function sendStatus(statusCode) {
var body = http.STATUS_CODES[statusCode] || String(statusCode);
this.statusCode = statusCode;
this.type('txt');
return this.send(body);
};
/**
* Transfer the file at the given `path`.
*
* Automatically sets the _Content-Type_ response header field.
* The callback `fn(err)` is invoked when the transfer is complete
* or when an error occurs. Be sure to check `res.sentHeader`
* if you wish to attempt responding, as the header and some data
* may have already been transferred.
*
* Options:
*
* - `maxAge` defaulting to 0 (can be string converted by `ms`)
* - `root` root directory for relative filenames
* - `headers` object of headers to serve with file
* - `dotfiles` serve dotfiles, defaulting to false; can be `"allow"` to send them
*
* Other options are passed along to `send`.
*
* Examples:
*
* The following example illustrates how `res.sendFile()` may
* be used as an alternative for the `static()` middleware for
* dynamic situations. The code backing `res.sendFile()` is actually
* the same code, so HTTP cache support etc is identical.
*
* app.get('/user/:uid/photos/:file', function(req, res){
* var uid = req.params.uid
* , file = req.params.file;
*
* req.user.mayViewFilesFrom(uid, function(yes){
* if (yes) {
* res.sendFile('/uploads/' + uid + '/' + file);
* } else {
* res.send(403, 'Sorry! you cant see that.');
* }
* });
* });
*
* @api public
*/
res.sendFile = function sendFile(path, options, fn) {
var req = this.req;
var res = this;
var next = req.next;
if (!path) {
throw new TypeError('path argument is required to res.sendFile');
}
// support function as second arg
if (typeof options === 'function') {
fn = options;
options = {};
}
options = options || {};
if (!options.root && !isAbsolute(path)) {
throw new TypeError('path must be absolute or specify root to res.sendFile');
}
// create file stream
var pathname = encodeURI(path);
var file = send(req, pathname, options);
// transfer
sendfile(res, file, options, function (err) {
if (fn) return fn(err);
if (err && err.code === 'EISDIR') return next();
// next() all but write errors
if (err && err.code !== 'ECONNABORTED' && err.syscall !== 'write') {
next(err);
}
});
};
/**
* Transfer the file at the given `path`.
*
* Automatically sets the _Content-Type_ response header field.
* The callback `fn(err)` is invoked when the transfer is complete
* or when an error occurs. Be sure to check `res.sentHeader`
* if you wish to attempt responding, as the header and some data
* may have already been transferred.
*
* Options:
*
* - `maxAge` defaulting to 0 (can be string converted by `ms`)
* - `root` root directory for relative filenames
* - `headers` object of headers to serve with file
* - `dotfiles` serve dotfiles, defaulting to false; can be `"allow"` to send them
*
* Other options are passed along to `send`.
*
* Examples:
*
* The following example illustrates how `res.sendfile()` may
* be used as an alternative for the `static()` middleware for
* dynamic situations. The code backing `res.sendfile()` is actually
* the same code, so HTTP cache support etc is identical.
*
* app.get('/user/:uid/photos/:file', function(req, res){
* var uid = req.params.uid
* , file = req.params.file;
*
* req.user.mayViewFilesFrom(uid, function(yes){
* if (yes) {
* res.sendfile('/uploads/' + uid + '/' + file);
* } else {
* res.send(403, 'Sorry! you cant see that.');
* }
* });
* });
*
* @api public
*/
res.sendfile = function(path, options, fn){
var req = this.req;
var res = this;
var next = req.next;
// support function as second arg
if (typeof options === 'function') {
fn = options;
options = {};
}
options = options || {};
// create file stream
var file = send(req, path, options);
// transfer
sendfile(res, file, options, function (err) {
if (fn) return fn(err);
if (err && err.code === 'EISDIR') return next();
// next() all but write errors
if (err && err.code !== 'ECONNABORT' && err.syscall !== 'write') {
next(err);
}
});
};
res.sendfile = deprecate.function(res.sendfile,
'res.sendfile: Use res.sendFile instead');
/**
* Transfer the file at the given `path` as an attachment.
*
* Optionally providing an alternate attachment `filename`,
* and optional callback `fn(err)`. The callback is invoked
* when the data transfer is complete, or when an error has
* ocurred. Be sure to check `res.headersSent` if you plan to respond.
*
* This method uses `res.sendfile()`.
*
* @api public
*/
res.download = function download(path, filename, fn) {
// support function as second arg
if (typeof filename === 'function') {
fn = filename;
filename = null;
}
filename = filename || path;
// set Content-Disposition when file is sent
var headers = {
'Content-Disposition': contentDisposition(filename)
};
// Resolve the full path for sendFile
var fullPath = resolve(path);
return this.sendFile(fullPath, { headers: headers }, fn);
};
/**
* Set _Content-Type_ response header with `type` through `mime.lookup()`
* when it does not contain "/", or set the Content-Type to `type` otherwise.
*
* Examples:
*
* res.type('.html');
* res.type('html');
* res.type('json');
* res.type('application/json');
* res.type('png');
*
* @param {String} type
* @return {ServerResponse} for chaining
* @api public
*/
res.contentType =
res.type = function(type){
return this.set('Content-Type', ~type.indexOf('/')
? type
: mime.lookup(type));
};
/**
* Respond to the Acceptable formats using an `obj`
* of mime-type callbacks.
*
* This method uses `req.accepted`, an array of
* acceptable types ordered by their quality values.
* When "Accept" is not present the _first_ callback
* is invoked, otherwise the first match is used. When
* no match is performed the server responds with
* 406 "Not Acceptable".
*
* Content-Type is set for you, however if you choose
* you may alter this within the callback using `res.type()`
* or `res.set('Content-Type', ...)`.
*
* res.format({
* 'text/plain': function(){
* res.send('hey');
* },
*
* 'text/html': function(){
* res.send('<p>hey</p>');
* },
*
* 'appliation/json': function(){
* res.send({ message: 'hey' });
* }
* });
*
* In addition to canonicalized MIME types you may
* also use extnames mapped to these types:
*
* res.format({
* text: function(){
* res.send('hey');
* },
*
* html: function(){
* res.send('<p>hey</p>');
* },
*
* json: function(){
* res.send({ message: 'hey' });
* }
* });
*
* By default Express passes an `Error`
* with a `.status` of 406 to `next(err)`
* if a match is not made. If you provide
* a `.default` callback it will be invoked
* instead.
*
* @param {Object} obj
* @return {ServerResponse} for chaining
* @api public
*/
res.format = function(obj){
var req = this.req;
var next = req.next;
var fn = obj.default;
if (fn) delete obj.default;
var keys = Object.keys(obj);
var key = req.accepts(keys);
this.vary("Accept");
if (key) {
this.set('Content-Type', normalizeType(key).value);
obj[key](req, this, next);
} else if (fn) {
fn();
} else {
var err = new Error('Not Acceptable');
err.status = 406;
err.types = normalizeTypes(keys).map(function(o){ return o.value });
next(err);
}
return this;
};
/**
* Set _Content-Disposition_ header to _attachment_ with optional `filename`.
*
* @param {String} filename
* @return {ServerResponse}
* @api public
*/
res.attachment = function attachment(filename) {
if (filename) {
this.type(extname(filename));
}
this.set('Content-Disposition', contentDisposition(filename));
return this;
};
/**
* Append additional header `field` with value `val`.
*
* Example:
*
* res.append('Link', ['<http://localhost/>', '<http://localhost:3000/>']);
* res.append('Set-Cookie', 'foo=bar; Path=/; HttpOnly');
* res.append('Warning', '199 Miscellaneous warning');
*
* @param {String} field
* @param {String|Array} val
* @return {ServerResponse} for chaining
* @api public
*/
res.append = function append(field, val) {
var prev = this.get(field);
var value = val;
if (prev) {
// concat the new and prev vals
value = Array.isArray(prev) ? prev.concat(val)
: Array.isArray(val) ? [prev].concat(val)
: [prev, val];
}
return this.set(field, value);
};
/**
* Set header `field` to `val`, or pass
* an object of header fields.
*
* Examples:
*
* res.set('Foo', ['bar', 'baz']);
* res.set('Accept', 'application/json');
* res.set({ Accept: 'text/plain', 'X-API-Key': 'tobi' });
*
* Aliased as `res.header()`.
*
* @param {String|Object|Array} field
* @param {String} val
* @return {ServerResponse} for chaining
* @api public
*/
res.set =
res.header = function header(field, val) {
if (arguments.length === 2) {
if (Array.isArray(val)) val = val.map(String);
else val = String(val);
if ('content-type' == field.toLowerCase() && !/;\s*charset\s*=/.test(val)) {
var charset = mime.charsets.lookup(val.split(';')[0]);
if (charset) val += '; charset=' + charset.toLowerCase();
}
this.setHeader(field, val);
} else {
for (var key in field) {
this.set(key, field[key]);
}
}
return this;
};
/**
* Get value for header `field`.
*
* @param {String} field
* @return {String}
* @api public
*/
res.get = function(field){
return this.getHeader(field);
};
/**
* Clear cookie `name`.
*
* @param {String} name
* @param {Object} options
* @return {ServerResponse} for chaining
* @api public
*/
res.clearCookie = function(name, options){
var opts = { expires: new Date(1), path: '/' };
return this.cookie(name, '', options
? merge(opts, options)
: opts);
};
/**
* Set cookie `name` to `val`, with the given `options`.
*
* Options:
*
* - `maxAge` max-age in milliseconds, converted to `expires`
* - `signed` sign the cookie
* - `path` defaults to "/"
*
* Examples:
*
* // "Remember Me" for 15 minutes
* res.cookie('rememberme', '1', { expires: new Date(Date.now() + 900000), httpOnly: true });
*
* // save as above
* res.cookie('rememberme', '1', { maxAge: 900000, httpOnly: true })
*
* @param {String} name
* @param {String|Object} val
* @param {Options} options
* @return {ServerResponse} for chaining
* @api public
*/
res.cookie = function(name, val, options){
options = merge({}, options);
var secret = this.req.secret;
var signed = options.signed;
if (signed && !secret) throw new Error('cookieParser("secret") required for signed cookies');
if ('number' == typeof val) val = val.toString();
if ('object' == typeof val) val = 'j:' + JSON.stringify(val);
if (signed) val = 's:' + sign(val, secret);
if ('maxAge' in options) {
options.expires = new Date(Date.now() + options.maxAge);
options.maxAge /= 1000;
}
if (null == options.path) options.path = '/';
var headerVal = cookie.serialize(name, String(val), options);
// supports multiple 'res.cookie' calls by getting previous value
var prev = this.get('Set-Cookie');
if (prev) {
if (Array.isArray(prev)) {
headerVal = prev.concat(headerVal);
} else {
headerVal = [prev, headerVal];
}
}
this.set('Set-Cookie', headerVal);
return this;
};
/**
* Set the location header to `url`.
*
* The given `url` can also be "back", which redirects
* to the _Referrer_ or _Referer_ headers or "/".
*
* Examples:
*
* res.location('/foo/bar').;
* res.location('http://example.com');
* res.location('../login');
*
* @param {String} url
* @return {ServerResponse} for chaining
* @api public
*/
res.location = function(url){
var req = this.req;
// "back" is an alias for the referrer
if ('back' == url) url = req.get('Referrer') || '/';
// Respond
this.set('Location', url);
return this;
};
/**
* Redirect to the given `url` with optional response `status`
* defaulting to 302.
*
* The resulting `url` is determined by `res.location()`, so
* it will play nicely with mounted apps, relative paths,
* `"back"` etc.
*
* Examples:
*
* res.redirect('/foo/bar');
* res.redirect('http://example.com');
* res.redirect(301, 'http://example.com');
* res.redirect('../login'); // /blog/post/1 -> /blog/login
*
* @api public
*/
res.redirect = function redirect(url) {
var address = url;
var body;
var status = 302;
// allow status / url
if (arguments.length === 2) {
if (typeof arguments[0] === 'number') {
status = arguments[0];
address = arguments[1];
} else {
deprecate('res.redirect(url, status): Use res.redirect(status, url) instead');
status = arguments[1];
}
}
// Set location header
this.location(address);
address = this.get('Location');
// Support text/{plain,html} by default
this.format({
text: function(){
body = statusCodes[status] + '. Redirecting to ' + encodeURI(address);
},
html: function(){
var u = escapeHtml(address);
body = '<p>' + statusCodes[status] + '. Redirecting to <a href="' + u + '">' + u + '</a></p>';
},
default: function(){
body = '';
}
});
// Respond
this.statusCode = status;
this.set('Content-Length', Buffer.byteLength(body));
if (this.req.method === 'HEAD') {
this.end();
} else {
this.end(body);
}
};
/**
* Add `field` to Vary. If already present in the Vary set, then
* this call is simply ignored.
*
* @param {Array|String} field
* @return {ServerResponse} for chaining
* @api public
*/
res.vary = function(field){
// checks for back-compat
if (!field || (Array.isArray(field) && !field.length)) {
deprecate('res.vary(): Provide a field name');
return this;
}
vary(this, field);
return this;
};
/**
* Render `view` with the given `options` and optional callback `fn`.
* When a callback function is given a response will _not_ be made
* automatically, otherwise a response of _200_ and _text/html_ is given.
*
* Options:
*
* - `cache` boolean hinting to the engine it should cache
* - `filename` filename of the view being rendered
*
* @api public
*/
res.render = function(view, options, fn){
options = options || {};
var self = this;
var req = this.req;
var app = req.app;
// support callback function as second arg
if ('function' == typeof options) {
fn = options, options = {};
}
// merge res.locals
options._locals = self.locals;
// default callback to respond
fn = fn || function(err, str){
if (err) return req.next(err);
self.send(str);
};
// render
app.render(view, options, fn);
};
// pipe the send file stream
function sendfile(res, file, options, callback) {
var done = false;
var streaming;
// request aborted
function onaborted() {
if (done) return;
done = true;
var err = new Error('Request aborted');
err.code = 'ECONNABORTED';
callback(err);
}
// directory
function ondirectory() {
if (done) return;
done = true;
var err = new Error('EISDIR, read');
err.code = 'EISDIR';
callback(err);
}
// errors
function onerror(err) {
if (done) return;
done = true;
callback(err);
}
// ended
function onend() {
if (done) return;
done = true;
callback();
}
// file
function onfile() {
streaming = false;
}
// finished
function onfinish(err) {
if (err && err.code === 'ECONNRESET') return onaborted();
if (err) return onerror(err);
if (done) return;
setImmediate(function () {
if (streaming !== false && !done) {
onaborted();
return;
}
if (done) return;
done = true;
callback();
});
}
// streaming
function onstream() {
streaming = true;
}
file.on('directory', ondirectory);
file.on('end', onend);
file.on('error', onerror);
file.on('file', onfile);
file.on('stream', onstream);
onFinished(res, onfinish);
if (options.headers) {
// set headers on successful transfer
file.on('headers', function headers(res) {
var obj = options.headers;
var keys = Object.keys(obj);
for (var i = 0; i < keys.length; i++) {
var k = keys[i];
res.setHeader(k, obj[k]);
}
});
}
// pipe
file.pipe(res);
}
/**
* Module dependencies.
*/
var Route = require('./route');
var Layer = require('./layer');
var methods = require('methods');
var mixin = require('utils-merge');
var debug = require('debug')('express:router');
var deprecate = require('depd')('express');
var parseUrl = require('parseurl');
var utils = require('../utils');
/**
* Module variables.
*/
var objectRegExp = /^\[object (\S+)\]$/;
var slice = Array.prototype.slice;
var toString = Object.prototype.toString;
/**
* Initialize a new `Router` with the given `options`.
*
* @param {Object} options
* @return {Router} which is an callable function
* @api public
*/
var proto = module.exports = function(options) {
options = options || {};
function router(req, res, next) {
router.handle(req, res, next);
}
// mixin Router class functions
router.__proto__ = proto;
router.params = {};
router._params = [];
router.caseSensitive = options.caseSensitive;
router.mergeParams = options.mergeParams;
router.strict = options.strict;
router.stack = [];
return router;
};
/**
* Map the given param placeholder `name`(s) to the given callback.
*
* Parameter mapping is used to provide pre-conditions to routes
* which use normalized placeholders. For example a _:user_id_ parameter
* could automatically load a user's information from the database without
* any additional code,
*
* The callback uses the same signature as middleware, the only difference
* being that the value of the placeholder is passed, in this case the _id_
* of the user. Once the `next()` function is invoked, just like middleware
* it will continue on to execute the route, or subsequent parameter functions.
*
* Just like in middleware, you must either respond to the request or call next
* to avoid stalling the request.
*
* app.param('user_id', function(req, res, next, id){
* User.find(id, function(err, user){
* if (err) {
* return next(err);
* } else if (!user) {
* return next(new Error('failed to load user'));
* }
* req.user = user;
* next();
* });
* });
*
* @param {String} name
* @param {Function} fn
* @return {app} for chaining
* @api public
*/
proto.param = function param(name, fn) {
// param logic
if (typeof name === 'function') {
deprecate('router.param(fn): Refactor to use path params');
this._params.push(name);
return;
}
// apply param functions
var params = this._params;
var len = params.length;
var ret;
if (name[0] === ':') {
deprecate('router.param(' + JSON.stringify(name) + ', fn): Use router.param(' + JSON.stringify(name.substr(1)) + ', fn) instead');
name = name.substr(1);
}
for (var i = 0; i < len; ++i) {
if (ret = params[i](name, fn)) {
fn = ret;
}
}
// ensure we end up with a
// middleware function
if ('function' != typeof fn) {
throw new Error('invalid param() call for ' + name + ', got ' + fn);
}
(this.params[name] = this.params[name] || []).push(fn);
return this;
};
/**
* Dispatch a req, res into the router.
*
* @api private
*/
proto.handle = function(req, res, done) {
var self = this;
debug('dispatching %s %s', req.method, req.url);
var search = 1 + req.url.indexOf('?');
var pathlength = search ? search - 1 : req.url.length;
var fqdn = req.url[0] !== '/' && 1 + req.url.substr(0, pathlength).indexOf('://');
var protohost = fqdn ? req.url.substr(0, req.url.indexOf('/', 2 + fqdn)) : '';
var idx = 0;
var removed = '';
var slashAdded = false;
var paramcalled = {};
// store options for OPTIONS request
// only used if OPTIONS request
var options = [];
// middleware and routes
var stack = self.stack;
// manage inter-router variables
var parentParams = req.params;
var parentUrl = req.baseUrl || '';
done = restore(done, req, 'baseUrl', 'next', 'params');
// setup next layer
req.next = next;
// for options requests, respond with a default if nothing else responds
if (req.method === 'OPTIONS') {
done = wrap(done, function(old, err) {
if (err || options.length === 0) return old(err);
sendOptionsResponse(res, options, old);
});
}
// setup basic req values
req.baseUrl = parentUrl;
req.originalUrl = req.originalUrl || req.url;
next();
function next(err) {
var layerError = err === 'route'
? null
: err;
// remove added slash
if (slashAdded) {
req.url = req.url.substr(1);
slashAdded = false;
}
// restore altered req.url
if (removed.length !== 0) {
req.baseUrl = parentUrl;
req.url = protohost + removed + req.url.substr(protohost.length);
removed = '';
}
// no more matching layers
if (idx >= stack.length) {
setImmediate(done, layerError);
return;
}
// get pathname of request
var path = getPathname(req);
if (path == null) {
return done(layerError);
}
// find next matching layer
var layer;
var match;
var route;
while (match !== true && idx < stack.length) {
layer = stack[idx++];
match = matchLayer(layer, path);
route = layer.route;
if (typeof match !== 'boolean') {
// hold on to layerError
layerError = layerError || match;
}
if (match !== true) {
continue;
}
if (!route) {
// process non-route handlers normally
continue;
}
if (layerError) {
// routes do not match with a pending error
match = false;
continue;
}
var method = req.method;
var has_method = route._handles_method(method);
// build up automatic options response
if (!has_method && method === 'OPTIONS') {
appendMethods(options, route._options());
}
// don't even bother matching route
if (!has_method && method !== 'HEAD') {
match = false;
continue;
}
}
// no match
if (match !== true) {
return done(layerError);
}
// store route for dispatch on change
if (route) {
req.route = route;
}
// Capture one-time layer values
req.params = self.mergeParams
? mergeParams(layer.params, parentParams)
: layer.params;
var layerPath = layer.path;
// this should be done for the layer
self.process_params(layer, paramcalled, req, res, function (err) {
if (err) {
return next(layerError || err);
}
if (route) {
return layer.handle_request(req, res, next);
}
trim_prefix(layer, layerError, layerPath, path);
});
}
function trim_prefix(layer, layerError, layerPath, path) {
var c = path[layerPath.length];
if (c && '/' !== c && '.' !== c) return next(layerError);
// Trim off the part of the url that matches the route
// middleware (.use stuff) needs to have the path stripped
if (layerPath.length !== 0) {
debug('trim prefix (%s) from url %s', layerPath, req.url);
removed = layerPath;
req.url = protohost + req.url.substr(protohost.length + removed.length);
// Ensure leading slash
if (!fqdn && req.url[0] !== '/') {
req.url = '/' + req.url;
slashAdded = true;
}
// Setup base URL (no trailing slash)
req.baseUrl = parentUrl + (removed[removed.length - 1] === '/'
? removed.substring(0, removed.length - 1)
: removed);
}
debug('%s %s : %s', layer.name, layerPath, req.originalUrl);
if (layerError) {
layer.handle_error(layerError, req, res, next);
} else {
layer.handle_request(req, res, next);
}
}
};
/**
* Process any parameters for the layer.
*
* @api private
*/
proto.process_params = function(layer, called, req, res, done) {
var params = this.params;
// captured parameters from the layer, keys and values
var keys = layer.keys;
// fast track
if (!keys || keys.length === 0) {
return done();
}
var i = 0;
var name;
var paramIndex = 0;
var key;
var paramVal;
var paramCallbacks;
var paramCalled;
// process params in order
// param callbacks can be async
function param(err) {
if (err) {
return done(err);
}
if (i >= keys.length ) {
return done();
}
paramIndex = 0;
key = keys[i++];
if (!key) {
return done();
}
name = key.name;
paramVal = req.params[name];
paramCallbacks = params[name];
paramCalled = called[name];
if (paramVal === undefined || !paramCallbacks) {
return param();
}
// param previously called with same value or error occurred
if (paramCalled && (paramCalled.error || paramCalled.match === paramVal)) {
// restore value
req.params[name] = paramCalled.value;
// next param
return param(paramCalled.error);
}
called[name] = paramCalled = {
error: null,
match: paramVal,
value: paramVal
};
paramCallback();
}
// single param callbacks
function paramCallback(err) {
var fn = paramCallbacks[paramIndex++];
// store updated value
paramCalled.value = req.params[key.name];
if (err) {
// store error
paramCalled.error = err;
param(err);
return;
}
if (!fn) return param();
try {
fn(req, res, paramCallback, paramVal, key.name);
} catch (e) {
paramCallback(e);
}
}
param();
};
/**
* Use the given middleware function, with optional path, defaulting to "/".
*
* Use (like `.all`) will run for any http METHOD, but it will not add
* handlers for those methods so OPTIONS requests will not consider `.use`
* functions even if they could respond.
*
* The other difference is that _route_ path is stripped and not visible
* to the handler function. The main effect of this feature is that mounted
* handlers can operate without any code changes regardless of the "prefix"
* pathname.
*
* @api public
*/
proto.use = function use(fn) {
var offset = 0;
var path = '/';
// default path to '/'
// disambiguate router.use([fn])
if (typeof fn !== 'function') {
var arg = fn;
while (Array.isArray(arg) && arg.length !== 0) {
arg = arg[0];
}
// first arg is the path
if (typeof arg !== 'function') {
offset = 1;
path = fn;
}
}
var callbacks = utils.flatten(slice.call(arguments, offset));
if (callbacks.length === 0) {
throw new TypeError('Router.use() requires middleware functions');
}
callbacks.forEach(function (fn) {
if (typeof fn !== 'function') {
throw new TypeError('Router.use() requires middleware function but got a ' + gettype(fn));
}
// add the middleware
debug('use %s %s', path, fn.name || '<anonymous>');
var layer = new Layer(path, {
sensitive: this.caseSensitive,
strict: false,
end: false
}, fn);
layer.route = undefined;
this.stack.push(layer);
}, this);
return this;
};
/**
* Create a new Route for the given path.
*
* Each route contains a separate middleware stack and VERB handlers.
*
* See the Route api documentation for details on adding handlers
* and middleware to routes.
*
* @param {String} path
* @return {Route}
* @api public
*/
proto.route = function(path){
var route = new Route(path);
var layer = new Layer(path, {
sensitive: this.caseSensitive,
strict: this.strict,
end: true
}, route.dispatch.bind(route));
layer.route = route;
this.stack.push(layer);
return route;
};
// create Router#VERB functions
methods.concat('all').forEach(function(method){
proto[method] = function(path){
var route = this.route(path)
route[method].apply(route, slice.call(arguments, 1));
return this;
};
});
// append methods to a list of methods
function appendMethods(list, addition) {
for (var i = 0; i < addition.length; i++) {
var method = addition[i];
if (list.indexOf(method) === -1) {
list.push(method);
}
}
}
// get pathname of request
function getPathname(req) {
try {
return parseUrl(req).pathname;
} catch (err) {
return undefined;
}
}
// get type for error message
function gettype(obj) {
var type = typeof obj;
if (type !== 'object') {
return type;
}
// inspect [[Class]] for objects
return toString.call(obj)
.replace(objectRegExp, '$1');
}
/**
* Match path to a layer.
*
* @param {Layer} layer
* @param {string} path
* @private
*/
function matchLayer(layer, path) {
try {
return layer.match(path);
} catch (err) {
return err;
}
}
// merge params with parent params
function mergeParams(params, parent) {
if (typeof parent !== 'object' || !parent) {
return params;
}
// make copy of parent for base
var obj = mixin({}, parent);
// simple non-numeric merging
if (!(0 in params) || !(0 in parent)) {
return mixin(obj, params);
}
var i = 0;
var o = 0;
// determine numeric gaps
while (i === o || o in parent) {
if (i in params) i++;
if (o in parent) o++;
}
// offset numeric indices in params before merge
for (i--; i >= 0; i--) {
params[i + o] = params[i];
// create holes for the merge when necessary
if (i < o) {
delete params[i];
}
}
return mixin(parent, params);
}
// restore obj props after function
function restore(fn, obj) {
var props = new Array(arguments.length - 2);
var vals = new Array(arguments.length - 2);
for (var i = 0; i < props.length; i++) {
props[i] = arguments[i + 2];
vals[i] = obj[props[i]];
}
return function(err){
// restore vals
for (var i = 0; i < props.length; i++) {
obj[props[i]] = vals[i];
}
return fn.apply(this, arguments);
};
}
// send an OPTIONS response
function sendOptionsResponse(res, options, next) {
try {
var body = options.join(',');
res.set('Allow', body);
res.send(body);
} catch (err) {
next(err);
}
}
// wrap a function
function wrap(old, fn) {
return function proxy() {
var args = new Array(arguments.length + 1);
args[0] = old;
for (var i = 0, len = arguments.length; i < len; i++) {
args[i + 1] = arguments[i];
}
fn.apply(this, args);
};
}
/**
* Module dependencies.
*/
var pathRegexp = require('path-to-regexp');
var debug = require('debug')('express:router:layer');
/**
* Module variables.
*/
var hasOwnProperty = Object.prototype.hasOwnProperty;
/**
* Expose `Layer`.
*/
module.exports = Layer;
function Layer(path, options, fn) {
if (!(this instanceof Layer)) {
return new Layer(path, options, fn);
}
debug('new %s', path);
options = options || {};
this.handle = fn;
this.name = fn.name || '<anonymous>';
this.params = undefined;
this.path = undefined;
this.regexp = pathRegexp(path, this.keys = [], options);
if (path === '/' && options.end === false) {
this.regexp.fast_slash = true;
}
}
/**
* Handle the error for the layer.
*
* @param {Error} error
* @param {Request} req
* @param {Response} res
* @param {function} next
* @api private
*/
Layer.prototype.handle_error = function handle_error(error, req, res, next) {
var fn = this.handle;
if (fn.length !== 4) {
// not a standard error handler
return next(error);
}
try {
fn(error, req, res, next);
} catch (err) {
next(err);
}
};
/**
* Handle the request for the layer.
*
* @param {Request} req
* @param {Response} res
* @param {function} next
* @api private
*/
Layer.prototype.handle_request = function handle(req, res, next) {
var fn = this.handle;
if (fn.length > 3) {
// not a standard request handler
return next();
}
try {
fn(req, res, next);
} catch (err) {
next(err);
}
};
/**
* Check if this route matches `path`, if so
* populate `.params`.
*
* @param {String} path
* @return {Boolean}
* @api private
*/
Layer.prototype.match = function match(path) {
if (path == null) {
// no path, nothing matches
this.params = undefined;
this.path = undefined;
return false;
}
if (this.regexp.fast_slash) {
// fast path non-ending match for / (everything matches)
this.params = {};
this.path = '';
return true;
}
var m = this.regexp.exec(path);
if (!m) {
this.params = undefined;
this.path = undefined;
return false;
}
// store values
this.params = {};
this.path = m[0];
var keys = this.keys;
var params = this.params;
var prop;
var n = 0;
var key;
var val;
for (var i = 1, len = m.length; i < len; ++i) {
key = keys[i - 1];
prop = key
? key.name
: n++;
val = decode_param(m[i]);
if (val !== undefined || !(hasOwnProperty.call(params, prop))) {
params[prop] = val;
}
}
return true;
};
/**
* Decode param value.
*
* @param {string} val
* @return {string}
* @api private
*/
function decode_param(val){
if (typeof val !== 'string') {
return val;
}
try {
return decodeURIComponent(val);
} catch (e) {
var err = new TypeError("Failed to decode param '" + val + "'");
err.status = 400;
throw err;
}
}
/**
* Module dependencies.
*/
var debug = require('debug')('express:router:route');
var Layer = require('./layer');
var methods = require('methods');
var utils = require('../utils');
/**
* Expose `Route`.
*/
module.exports = Route;
/**
* Initialize `Route` with the given `path`,
*
* @param {String} path
* @api private
*/
function Route(path) {
debug('new %s', path);
this.path = path;
this.stack = [];
// route handlers for various http methods
this.methods = {};
}
/**
* @api private
*/
Route.prototype._handles_method = function _handles_method(method) {
if (this.methods._all) {
return true;
}
method = method.toLowerCase();
if (method === 'head' && !this.methods['head']) {
method = 'get';
}
return Boolean(this.methods[method]);
};
/**
* @return {Array} supported HTTP methods
* @api private
*/
Route.prototype._options = function _options() {
var methods = Object.keys(this.methods);
// append automatic head
if (this.methods.get && !this.methods.head) {
methods.push('head');
}
for (var i = 0; i < methods.length; i++) {
// make upper case
methods[i] = methods[i].toUpperCase();
}
return methods;
};
/**
* dispatch req, res into this route
*
* @api private
*/
Route.prototype.dispatch = function(req, res, done){
var idx = 0;
var stack = this.stack;
if (stack.length === 0) {
return done();
}
var method = req.method.toLowerCase();
if (method === 'head' && !this.methods['head']) {
method = 'get';
}
req.route = this;
next();
function next(err) {
if (err && err === 'route') {
return done();
}
var layer = stack[idx++];
if (!layer) {
return done(err);
}
if (layer.method && layer.method !== method) {
return next(err);
}
if (err) {
layer.handle_error(err, req, res, next);
} else {
layer.handle_request(req, res, next);
}
}
};
/**
* Add a handler for all HTTP verbs to this route.
*
* Behaves just like middleware and can respond or call `next`
* to continue processing.
*
* You can use multiple `.all` call to add multiple handlers.
*
* function check_something(req, res, next){
* next();
* };
*
* function validate_user(req, res, next){
* next();
* };
*
* route
* .all(validate_user)
* .all(check_something)
* .get(function(req, res, next){
* res.send('hello world');
* });
*
* @param {function} handler
* @return {Route} for chaining
* @api public
*/
Route.prototype.all = function(){
var callbacks = utils.flatten([].slice.call(arguments));
callbacks.forEach(function(fn) {
if (typeof fn !== 'function') {
var type = {}.toString.call(fn);
var msg = 'Route.all() requires callback functions but got a ' + type;
throw new Error(msg);
}
var layer = Layer('/', {}, fn);
layer.method = undefined;
this.methods._all = true;
this.stack.push(layer);
}, this);
return this;
};
methods.forEach(function(method){
Route.prototype[method] = function(){
var callbacks = utils.flatten([].slice.call(arguments));
callbacks.forEach(function(fn) {
if (typeof fn !== 'function') {
var type = {}.toString.call(fn);
var msg = 'Route.' + method + '() requires callback functions but got a ' + type;
throw new Error(msg);
}
debug('%s %s', method, this.path);
var layer = Layer('/', {}, fn);
layer.method = method;
this.methods[method] = true;
this.stack.push(layer);
}, this);
return this;
};
});
/*!
* express
* Copyright(c) 2009-2013 TJ Holowaychuk
* Copyright(c) 2014-2015 Douglas Christopher Wilson
* MIT Licensed
*/
/**
* Module dependencies.
* @api private
*/
var contentDisposition = require('content-disposition');
var contentType = require('content-type');
var deprecate = require('depd')('express');
var mime = require('send').mime;
var basename = require('path').basename;
var etag = require('etag');
var proxyaddr = require('proxy-addr');
var qs = require('qs');
var querystring = require('querystring');
/**
* Return strong ETag for `body`.
*
* @param {String|Buffer} body
* @param {String} [encoding]
* @return {String}
* @api private
*/
exports.etag = function (body, encoding) {
var buf = !Buffer.isBuffer(body)
? new Buffer(body, encoding)
: body;
return etag(buf, {weak: false});
};
/**
* Return weak ETag for `body`.
*
* @param {String|Buffer} body
* @param {String} [encoding]
* @return {String}
* @api private
*/
exports.wetag = function wetag(body, encoding){
var buf = !Buffer.isBuffer(body)
? new Buffer(body, encoding)
: body;
return etag(buf, {weak: true});
};
/**
* Check if `path` looks absolute.
*
* @param {String} path
* @return {Boolean}
* @api private
*/
exports.isAbsolute = function(path){
if ('/' == path[0]) return true;
if (':' == path[1] && '\\' == path[2]) return true;
if ('\\\\' == path.substring(0, 2)) return true; // Microsoft Azure absolute path
};
/**
* Flatten the given `arr`.
*
* @param {Array} arr
* @return {Array}
* @api private
*/
exports.flatten = function(arr, ret){
ret = ret || [];
var len = arr.length;
for (var i = 0; i < len; ++i) {
if (Array.isArray(arr[i])) {
exports.flatten(arr[i], ret);
} else {
ret.push(arr[i]);
}
}
return ret;
};
/**
* Normalize the given `type`, for example "html" becomes "text/html".
*
* @param {String} type
* @return {Object}
* @api private
*/
exports.normalizeType = function(type){
return ~type.indexOf('/')
? acceptParams(type)
: { value: mime.lookup(type), params: {} };
};
/**
* Normalize `types`, for example "html" becomes "text/html".
*
* @param {Array} types
* @return {Array}
* @api private
*/
exports.normalizeTypes = function(types){
var ret = [];
for (var i = 0; i < types.length; ++i) {
ret.push(exports.normalizeType(types[i]));
}
return ret;
};
/**
* Generate Content-Disposition header appropriate for the filename.
* non-ascii filenames are urlencoded and a filename* parameter is added
*
* @param {String} filename
* @return {String}
* @api private
*/
exports.contentDisposition = deprecate.function(contentDisposition,
'utils.contentDisposition: use content-disposition npm module instead');
/**
* Parse accept params `str` returning an
* object with `.value`, `.quality` and `.params`.
* also includes `.originalIndex` for stable sorting
*
* @param {String} str
* @return {Object}
* @api private
*/
function acceptParams(str, index) {
var parts = str.split(/ *; */);
var ret = { value: parts[0], quality: 1, params: {}, originalIndex: index };
for (var i = 1; i < parts.length; ++i) {
var pms = parts[i].split(/ *= */);
if ('q' == pms[0]) {
ret.quality = parseFloat(pms[1]);
} else {
ret.params[pms[0]] = pms[1];
}
}
return ret;
}
/**
* Compile "etag" value to function.
*
* @param {Boolean|String|Function} val
* @return {Function}
* @api private
*/
exports.compileETag = function(val) {
var fn;
if (typeof val === 'function') {
return val;
}
switch (val) {
case true:
fn = exports.wetag;
break;
case false:
break;
case 'strong':
fn = exports.etag;
break;
case 'weak':
fn = exports.wetag;
break;
default:
throw new TypeError('unknown value for etag function: ' + val);
}
return fn;
}
/**
* Compile "query parser" value to function.
*
* @param {String|Function} val
* @return {Function}
* @api private
*/
exports.compileQueryParser = function compileQueryParser(val) {
var fn;
if (typeof val === 'function') {
return val;
}
switch (val) {
case true:
fn = querystring.parse;
break;
case false:
fn = newObject;
break;
case 'extended':
fn = qs.parse;
break;
case 'simple':
fn = querystring.parse;
break;
default:
throw new TypeError('unknown value for query parser function: ' + val);
}
return fn;
}
/**
* Compile "proxy trust" value to function.
*
* @param {Boolean|String|Number|Array|Function} val
* @return {Function}
* @api private
*/
exports.compileTrust = function(val) {
if (typeof val === 'function') return val;
if (val === true) {
// Support plain true/false
return function(){ return true };
}
if (typeof val === 'number') {
// Support trusting hop count
return function(a, i){ return i < val };
}
if (typeof val === 'string') {
// Support comma-separated values
val = val.split(/ *, */);
}
return proxyaddr.compile(val || []);
}
/**
* Set the charset in a given Content-Type string.
*
* @param {String} type
* @param {String} charset
* @return {String}
* @api private
*/
exports.setCharset = function setCharset(type, charset) {
if (!type || !charset) {
return type;
}
// parse type
var parsed = contentType.parse(type);
// set charset
parsed.parameters.charset = charset;
// format type
return contentType.format(parsed);
};
/**
* Return new empty object.
*
* @return {Object}
* @api private
*/
function newObject() {
return {};
}
/**
* Module dependencies.
*/
var debug = require('debug')('express:view');
var path = require('path');
var fs = require('fs');
var utils = require('./utils');
/**
* Module variables.
* @private
*/
var dirname = path.dirname;
var basename = path.basename;
var extname = path.extname;
var join = path.join;
var resolve = path.resolve;
/**
* Expose `View`.
*/
module.exports = View;
/**
* Initialize a new `View` with the given `name`.
*
* Options:
*
* - `defaultEngine` the default template engine name
* - `engines` template engine require() cache
* - `root` root path for view lookup
*
* @param {String} name
* @param {Object} options
* @api private
*/
function View(name, options) {
options = options || {};
this.name = name;
this.root = options.root;
var engines = options.engines;
this.defaultEngine = options.defaultEngine;
var ext = this.ext = extname(name);
if (!ext && !this.defaultEngine) throw new Error('No default engine was specified and no extension was provided.');
if (!ext) name += (ext = this.ext = ('.' != this.defaultEngine[0] ? '.' : '') + this.defaultEngine);
this.engine = engines[ext] || (engines[ext] = require(ext.slice(1)).__express);
this.path = this.lookup(name);
}
/**
* Lookup view by the given `name`
*
* @param {String} name
* @return {String}
* @api private
*/
View.prototype.lookup = function lookup(name) {
var path;
var roots = [].concat(this.root);
debug('lookup "%s"', name);
for (var i = 0; i < roots.length && !path; i++) {
var root = roots[i];
// resolve the path
var loc = resolve(root, name);
var dir = dirname(loc);
var file = basename(loc);
// resolve the file
path = this.resolve(dir, file);
}
return path;
};
/**
* Render with the given `options` and callback `fn(err, str)`.
*
* @param {Object} options
* @param {Function} fn
* @api private
*/
View.prototype.render = function render(options, fn) {
debug('render "%s"', this.path);
this.engine(this.path, options, fn);
};
/**
* Resolve the file within the given directory.
*
* @param {string} dir
* @param {string} file
* @private
*/
View.prototype.resolve = function resolve(dir, file) {
var ext = this.ext;
var path;
var stat;
// <path>.<ext>
path = join(dir, file);
stat = tryStat(path);
if (stat && stat.isFile()) {
return path;
}
// <path>/index.<ext>
path = join(dir, basename(file, ext), 'index' + ext);
stat = tryStat(path);
if (stat && stat.isFile()) {
return path;
}
};
/**
* Return a stat, maybe.
*
* @param {string} path
* @return {fs.Stats}
* @private
*/
function tryStat(path) {
debug('stat "%s"', path);
try {
return fs.statSync(path);
} catch (e) {
return undefined;
}
}
(The MIT License)
Copyright (c) 2009-2014 TJ Holowaychuk <tj@vision-media.ca>
Copyright (c) 2013-2014 Roman Shtylman <shtylman+expressjs@gmail.com>
Copyright (c) 2014-2015 Douglas Christopher Wilson <doug@somethingdoug.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

1.2.5 / 2015-03-13

  • deps: mime-types@~2.0.10
    • deps: mime-db@~1.8.0

1.2.4 / 2015-02-14

  • Support Node.js 0.6
  • deps: mime-types@~2.0.9
    • deps: mime-db@~1.7.0
  • deps: negotiator@0.5.1
    • Fix preference sorting to be stable for long acceptable lists

1.2.3 / 2015-01-31

  • deps: mime-types@~2.0.8
    • deps: mime-db@~1.6.0

1.2.2 / 2014-12-30

  • deps: mime-types@~2.0.7
    • deps: mime-db@~1.5.0

1.2.1 / 2014-12-30

  • deps: mime-types@~2.0.5
    • deps: mime-db@~1.3.1

1.2.0 / 2014-12-19

  • deps: negotiator@0.5.0
    • Fix list return order when large accepted list
    • Fix missing identity encoding when q=0 exists
    • Remove dynamic building of Negotiator class

1.1.4 / 2014-12-10

  • deps: mime-types@~2.0.4
    • deps: mime-db@~1.3.0

1.1.3 / 2014-11-09

  • deps: mime-types@~2.0.3
    • deps: mime-db@~1.2.0

1.1.2 / 2014-10-14

  • deps: negotiator@0.4.9
    • Fix error when media type has invalid parameter

1.1.1 / 2014-09-28

  • deps: mime-types@~2.0.2
    • deps: mime-db@~1.1.0
  • deps: negotiator@0.4.8
    • Fix all negotiations to be case-insensitive
    • Stable sort preferences of same quality according to client order

1.1.0 / 2014-09-02

  • update mime-types

1.0.7 / 2014-07-04

  • Fix wrong type returned from type when match after unknown extension

1.0.6 / 2014-06-24

  • deps: negotiator@0.4.7

1.0.5 / 2014-06-20

  • fix crash when unknown extension given

1.0.4 / 2014-06-19

  • use mime-types

1.0.3 / 2014-06-11

  • deps: negotiator@0.4.6
    • Order by specificity when quality is the same

1.0.2 / 2014-05-29

  • Fix interpretation when header not in request
  • deps: pin negotiator@0.4.5

1.0.1 / 2014-01-18

  • Identity encoding isn't always acceptable
  • deps: negotiator@~0.4.0

1.0.0 / 2013-12-27

  • Genesis
var Negotiator = require('negotiator')
var mime = require('mime-types')
var slice = [].slice
module.exports = Accepts
function Accepts(req) {
if (!(this instanceof Accepts))
return new Accepts(req)
this.headers = req.headers
this.negotiator = Negotiator(req)
}
/**
* Check if the given `type(s)` is acceptable, returning
* the best match when true, otherwise `undefined`, in which
* case you should respond with 406 "Not Acceptable".
*
* The `type` value may be a single mime type string
* such as "application/json", the extension name
* such as "json" or an array `["json", "html", "text/plain"]`. When a list
* or array is given the _best_ match, if any is returned.
*
* Examples:
*
* // Accept: text/html
* this.types('html');
* // => "html"
*
* // Accept: text/*, application/json
* this.types('html');
* // => "html"
* this.types('text/html');
* // => "text/html"
* this.types('json', 'text');
* // => "json"
* this.types('application/json');
* // => "application/json"
*
* // Accept: text/*, application/json
* this.types('image/png');
* this.types('png');
* // => undefined
*
* // Accept: text/*;q=.5, application/json
* this.types(['html', 'json']);
* this.types('html', 'json');
* // => "json"
*
* @param {String|Array} type(s)...
* @return {String|Array|Boolean}
* @api public
*/
Accepts.prototype.type =
Accepts.prototype.types = function (types) {
if (!Array.isArray(types)) types = slice.call(arguments);
var n = this.negotiator;
if (!types.length) return n.mediaTypes();
if (!this.headers.accept) return types[0];
var mimes = types.map(extToMime);
var accepts = n.mediaTypes(mimes.filter(validMime));
var first = accepts[0];
if (!first) return false;
return types[mimes.indexOf(first)];
}
/**
* Return accepted encodings or best fit based on `encodings`.
*
* Given `Accept-Encoding: gzip, deflate`
* an array sorted by quality is returned:
*
* ['gzip', 'deflate']
*
* @param {String|Array} encoding(s)...
* @return {String|Array}
* @api public
*/
Accepts.prototype.encoding =
Accepts.prototype.encodings = function (encodings) {
if (!Array.isArray(encodings)) encodings = slice.call(arguments);
var n = this.negotiator;
if (!encodings.length) return n.encodings();
return n.encodings(encodings)[0] || false;
}
/**
* Return accepted charsets or best fit based on `charsets`.
*
* Given `Accept-Charset: utf-8, iso-8859-1;q=0.2, utf-7;q=0.5`
* an array sorted by quality is returned:
*
* ['utf-8', 'utf-7', 'iso-8859-1']
*
* @param {String|Array} charset(s)...
* @return {String|Array}
* @api public
*/
Accepts.prototype.charset =
Accepts.prototype.charsets = function (charsets) {
if (!Array.isArray(charsets)) charsets = [].slice.call(arguments);
var n = this.negotiator;
if (!charsets.length) return n.charsets();
if (!this.headers['accept-charset']) return charsets[0];
return n.charsets(charsets)[0] || false;
}
/**
* Return accepted languages or best fit based on `langs`.
*
* Given `Accept-Language: en;q=0.8, es, pt`
* an array sorted by quality is returned:
*
* ['es', 'pt', 'en']
*
* @param {String|Array} lang(s)...
* @return {Array|String}
* @api public
*/
Accepts.prototype.lang =
Accepts.prototype.langs =
Accepts.prototype.language =
Accepts.prototype.languages = function (langs) {
if (!Array.isArray(langs)) langs = slice.call(arguments);
var n = this.negotiator;
if (!langs.length) return n.languages();
if (!this.headers['accept-language']) return langs[0];
return n.languages(langs)[0] || false;
}
/**
* Convert extnames to mime.
*
* @param {String} type
* @return {String}
* @api private
*/
function extToMime(type) {
if (~type.indexOf('/')) return type;
return mime.lookup(type);
}
/**
* Check if mime is valid.
*
* @param {String} type
* @return {String}
* @api private
*/
function validMime(type) {
return typeof type === 'string';
}
(The MIT License)
Copyright (c) 2014 Jonathan Ong <me@jongleberry.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

2.0.10 / 2015-03-13

  • deps: mime-db@~1.8.0
    • Add new mime types

2.0.9 / 2015-02-09

  • deps: mime-db@~1.7.0
    • Add new mime types
    • Community extensions ownership transferred from node-mime

2.0.8 / 2015-01-29

  • deps: mime-db@~1.6.0
    • Add new mime types

2.0.7 / 2014-12-30

  • deps: mime-db@~1.5.0
    • Add new mime types
    • Fix various invalid MIME type entries

2.0.6 / 2014-12-30

  • deps: mime-db@~1.4.0
    • Add new mime types
    • Fix various invalid MIME type entries
    • Remove example template MIME types

2.0.5 / 2014-12-29

  • deps: mime-db@~1.3.1
    • Fix missing extensions

2.0.4 / 2014-12-10

  • deps: mime-db@~1.3.0
    • Add new mime types

2.0.3 / 2014-11-09

  • deps: mime-db@~1.2.0
    • Add new mime types

2.0.2 / 2014-09-28

  • deps: mime-db@~1.1.0
    • Add new mime types
    • Add additional compressible
    • Update charsets

2.0.1 / 2014-09-07

  • Support Node.js 0.6

2.0.0 / 2014-09-02

  • Use mime-db
  • Remove .define()

1.0.2 / 2014-08-04

  • Set charset=utf-8 for text/javascript

1.0.1 / 2014-06-24

  • Add text/jsx type

1.0.0 / 2014-05-12

  • Return false for unknown types
  • Set charset=utf-8 for application/json

0.1.0 / 2014-05-02

  • Initial release
var db = require('mime-db')
// types[extension] = type
exports.types = Object.create(null)
// extensions[type] = [extensions]
exports.extensions = Object.create(null)
Object.keys(db).forEach(function (name) {
var mime = db[name]
var exts = mime.extensions
if (!exts || !exts.length) return
exports.extensions[name] = exts
exts.forEach(function (ext) {
exports.types[ext] = name
})
})
exports.lookup = function (string) {
if (!string || typeof string !== "string") return false
// remove any leading paths, though we should just use path.basename
string = string.replace(/.*[\.\/\\]/, '').toLowerCase()
if (!string) return false
return exports.types[string] || false
}
exports.extension = function (type) {
if (!type || typeof type !== "string") return false
// to do: use media-typer
type = type.match(/^\s*([^;\s]*)(?:;|\s|$)/)
if (!type) return false
var exts = exports.extensions[type[1].toLowerCase()]
if (!exts || !exts.length) return false
return exts[0]
}
// type has to be an exact mime type
exports.charset = function (type) {
var mime = db[type]
if (mime && mime.charset) return mime.charset
// default text/* to utf-8
if (/^text\//.test(type)) return 'UTF-8'
return false
}
// backwards compatibility
exports.charsets = {
lookup: exports.charset
}
// to do: maybe use set-type module or something
exports.contentType = function (type) {
if (!type || typeof type !== "string") return false
if (!~type.indexOf('/')) type = exports.lookup(type)
if (!type) return false
if (!~type.indexOf('charset')) {
var charset = exports.charset(type)
if (charset) type += '; charset=' + charset.toLowerCase()
}
return type
}
The MIT License (MIT)
Copyright (c) 2014 Jonathan Ong me@jongleberry.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
{
"application/1d-interleaved-parityfec": {
"source": "iana"
},
"application/3gpdash-qoe-report+xml": {
"source": "iana"
},
"application/3gpp-ims+xml": {
"source": "iana"
},
"application/a2l": {
"source": "iana"
},
"application/activemessage": {
"source": "iana"
},
"application/alto-costmap+json": {
"source": "iana",
"compressible": true
},
"application/alto-costmapfilter+json": {
"source": "iana",
"compressible": true
},
"application/alto-directory+json": {
"source": "iana",
"compressible": true
},
"application/alto-endpointcost+json": {
"source": "iana",
"compressible": true
},
"application/alto-endpointcostparams+json": {
"source": "iana",
"compressible": true
},
"application/alto-endpointprop+json": {
"source": "iana",
"compressible": true
},
"application/alto-endpointpropparams+json": {
"source": "iana",
"compressible": true
},
"application/alto-error+json": {
"source": "iana",
"compressible": true
},
"application/alto-networkmap+json": {
"source": "iana",
"compressible": true
},
"application/alto-networkmapfilter+json": {
"source": "iana",
"compressible": true
},
"application/aml": {
"source": "iana"
},
"application/andrew-inset": {
"source": "iana",
"extensions": ["ez"]
},
"application/applefile": {
"source": "iana"
},
"application/applixware": {
"source": "apache",
"extensions": ["aw"]
},
"application/atf": {
"source": "iana"
},
"application/atfx": {
"source": "iana"
},
"application/atom+xml": {
"source": "iana",
"compressible": true,
"extensions": ["atom"]
},
"application/atomcat+xml": {
"source": "iana",
"extensions": ["atomcat"]
},
"application/atomdeleted+xml": {
"source": "iana"
},
"application/atomicmail": {
"source": "iana"
},
"application/atomsvc+xml": {
"source": "iana",
"extensions": ["atomsvc"]
},
"application/atxml": {
"source": "iana"
},
"application/auth-policy+xml": {
"source": "iana"
},
"application/bacnet-xdd+zip": {
"source": "iana"
},
"application/batch-smtp": {
"source": "iana"
},
"application/beep+xml": {
"source": "iana"
},
"application/calendar+json": {
"source": "iana",
"compressible": true
},
"application/calendar+xml": {
"source": "iana"
},
"application/call-completion": {
"source": "iana"
},
"application/cals-1840": {
"source": "iana"
},
"application/cbor": {
"source": "iana"
},
"application/ccmp+xml": {
"source": "iana"
},
"application/ccxml+xml": {
"source": "iana",
"extensions": ["ccxml"]
},
"application/cdfx+xml": {
"source": "iana"
},
"application/cdmi-capability": {
"source": "iana",
"extensions": ["cdmia"]
},
"application/cdmi-container": {
"source": "iana",
"extensions": ["cdmic"]
},
"application/cdmi-domain": {
"source": "iana",
"extensions": ["cdmid"]
},
"application/cdmi-object": {
"source": "iana",
"extensions": ["cdmio"]
},
"application/cdmi-queue": {
"source": "iana",
"extensions": ["cdmiq"]
},
"application/cea": {
"source": "iana"
},
"application/cea-2018+xml": {
"source": "iana"
},
"application/cellml+xml": {
"source": "iana"
},
"application/cfw": {
"source": "iana"
},
"application/cms": {
"source": "iana"
},
"application/cnrp+xml": {
"source": "iana"
},
"application/coap-group+json": {
"source": "iana",
"compressible": true
},
"application/commonground": {
"source": "iana"
},
"application/conference-info+xml": {
"source": "iana"
},
"application/cpl+xml": {
"source": "iana"
},
"application/csrattrs": {
"source": "iana"
},
"application/csta+xml": {
"source": "iana"
},
"application/cstadata+xml": {
"source": "iana"
},
"application/cu-seeme": {
"source": "apache",
"extensions": ["cu"]
},
"application/cybercash": {
"source": "iana"
},
"application/dart": {
"compressible": true
},
"application/dash+xml": {
"source": "iana",
"extensions": ["mdp"]
},
"application/dashdelta": {
"source": "iana"
},
"application/davmount+xml": {
"source": "iana",
"extensions": ["davmount"]
},
"application/dca-rft": {
"source": "iana"
},
"application/dcd": {
"source": "iana"
},
"application/dec-dx": {
"source": "iana"
},
"application/dialog-info+xml": {
"source": "iana"
},
"application/dicom": {
"source": "iana"
},
"application/dii": {
"source": "iana"
},
"application/dit": {
"source": "iana"
},
"application/dns": {
"source": "iana"
},
"application/docbook+xml": {
"source": "apache",
"extensions": ["dbk"]
},
"application/dskpp+xml": {
"source": "iana"
},
"application/dssc+der": {
"source": "iana",
"extensions": ["dssc"]
},
"application/dssc+xml": {
"source": "iana",
"extensions": ["xdssc"]
},
"application/dvcs": {
"source": "iana"
},
"application/ecmascript": {
"source": "iana",
"compressible": true,
"extensions": ["ecma"]
},
"application/edi-consent": {
"source": "iana"
},
"application/edi-x12": {
"source": "iana",
"compressible": false
},
"application/edifact": {
"source": "iana",
"compressible": false
},
"application/emma+xml": {
"source": "iana",
"extensions": ["emma"]
},
"application/emotionml+xml": {
"source": "iana"
},
"application/encaprtp": {
"source": "iana"
},
"application/epp+xml": {
"source": "iana"
},
"application/epub+zip": {
"source": "iana",
"extensions": ["epub"]
},
"application/eshop": {
"source": "iana"
},
"application/exi": {
"source": "iana",
"extensions": ["exi"]
},
"application/fastinfoset": {
"source": "iana"
},
"application/fastsoap": {
"source": "iana"
},
"application/fdt+xml": {
"source": "iana"
},
"application/fits": {
"source": "iana"
},
"application/font-sfnt": {
"source": "iana"
},
"application/font-tdpfr": {
"source": "iana",
"extensions": ["pfr"]
},
"application/font-woff": {
"source": "iana",
"compressible": false,
"extensions": ["woff"]
},
"application/font-woff2": {
"compressible": false,
"extensions": ["woff2"]
},
"application/framework-attributes+xml": {
"source": "iana"
},
"application/gml+xml": {
"source": "apache",
"extensions": ["gml"]
},
"application/gpx+xml": {
"source": "apache",
"extensions": ["gpx"]
},
"application/gxf": {
"source": "apache",
"extensions": ["gxf"]
},
"application/gzip": {
"source": "iana",
"compressible": false
},
"application/h224": {
"source": "iana"
},
"application/held+xml": {
"source": "iana"
},
"application/http": {
"source": "iana"
},
"application/hyperstudio": {
"source": "iana",
"extensions": ["stk"]
},
"application/ibe-key-request+xml": {
"source": "iana"
},
"application/ibe-pkg-reply+xml": {
"source": "iana"
},
"application/ibe-pp-data": {
"source": "iana"
},
"application/iges": {
"source": "iana"
},
"application/im-iscomposing+xml": {
"source": "iana"
},
"application/index": {
"source": "iana"
},
"application/index.cmd": {
"source": "iana"
},
"application/index.obj": {
"source": "iana"
},
"application/index.response": {
"source": "iana"
},
"application/index.vnd": {
"source": "iana"
},
"application/inkml+xml": {
"source": "iana",
"extensions": ["ink","inkml"]
},
"application/iotp": {
"source": "iana"
},
"application/ipfix": {
"source": "iana",
"extensions": ["ipfix"]
},
"application/ipp": {
"source": "iana"
},
"application/isup": {
"source": "iana"
},
"application/its+xml": {
"source": "iana"
},
"application/java-archive": {
"source": "apache",
"compressible": false,
"extensions": ["jar"]
},
"application/java-serialized-object": {
"source": "apache",
"compressible": false,
"extensions": ["ser"]
},
"application/java-vm": {
"source": "apache",
"compressible": false,
"extensions": ["class"]
},
"application/javascript": {
"source": "iana",
"charset": "UTF-8",
"compressible": true,
"extensions": ["js"]
},
"application/jose": {
"source": "iana"
},
"application/jose+json": {
"source": "iana",
"compressible": true
},
"application/jrd+json": {
"source": "iana",
"compressible": true
},
"application/json": {
"source": "iana",
"charset": "UTF-8",
"compressible": true,
"extensions": ["json","map"]
},
"application/json-patch+json": {
"source": "iana",
"compressible": true
},
"application/json-seq": {
"source": "iana"
},
"application/json5": {
"extensions": ["json5"]
},
"application/jsonml+json": {
"source": "apache",
"compressible": true,
"extensions": ["jsonml"]
},
"application/jwk+json": {
"source": "iana",
"compressible": true
},
"application/jwk-set+json": {
"source": "iana",
"compressible": true
},
"application/jwt": {
"source": "iana"
},
"application/kpml-request+xml": {
"source": "iana"
},
"application/kpml-response+xml": {
"source": "iana"
},
"application/ld+json": {
"source": "iana",
"compressible": true,
"extensions": ["jsonld"]
},
"application/link-format": {
"source": "iana"
},
"application/load-control+xml": {
"source": "iana"
},
"application/lost+xml": {
"source": "iana",
"extensions": ["lostxml"]
},
"application/lostsync+xml": {
"source": "iana"
},
"application/lxf": {
"source": "iana"
},
"application/mac-binhex40": {
"source": "iana",
"extensions": ["hqx"]
},
"application/mac-compactpro": {
"source": "apache",
"extensions": ["cpt"]
},
"application/macwriteii": {
"source": "iana"
},
"application/mads+xml": {
"source": "iana",
"extensions": ["mads"]
},
"application/marc": {
"source": "iana",
"extensions": ["mrc"]
},
"application/marcxml+xml": {
"source": "iana",
"extensions": ["mrcx"]
},
"application/mathematica": {
"source": "iana",
"extensions": ["ma","nb","mb"]
},
"application/mathml+xml": {
"source": "iana",
"extensions": ["mathml"]
},
"application/mathml-content+xml": {
"source": "iana"
},
"application/mathml-presentation+xml": {
"source": "iana"
},
"application/mbms-associated-procedure-description+xml": {
"source": "iana"
},
"application/mbms-deregister+xml": {
"source": "iana"
},
"application/mbms-envelope+xml": {
"source": "iana"
},
"application/mbms-msk+xml": {
"source": "iana"
},
"application/mbms-msk-response+xml": {
"source": "iana"
},
"application/mbms-protection-description+xml": {
"source": "iana"
},
"application/mbms-reception-report+xml": {
"source": "iana"
},
"application/mbms-register+xml": {
"source": "iana"
},
"application/mbms-register-response+xml": {
"source": "iana"
},
"application/mbms-schedule+xml": {
"source": "iana"
},
"application/mbms-user-service-description+xml": {
"source": "iana"
},
"application/mbox": {
"source": "iana",
"extensions": ["mbox"]
},
"application/media-policy-dataset+xml": {
"source": "iana"
},
"application/media_control+xml": {
"source": "iana"
},
"application/mediaservercontrol+xml": {
"source": "iana",
"extensions": ["mscml"]
},
"application/merge-patch+json": {
"source": "iana",
"compressible": true
},
"application/metalink+xml": {
"source": "apache",
"extensions": ["metalink"]
},
"application/metalink4+xml": {
"source": "iana",
"extensions": ["meta4"]
},
"application/mets+xml": {
"source": "iana",
"extensions": ["mets"]
},
"application/mf4": {
"source": "iana"
},
"application/mikey": {
"source": "iana"
},
"application/mods+xml": {
"source": "iana",
"extensions": ["mods"]
},
"application/moss-keys": {
"source": "iana"
},
"application/moss-signature": {
"source": "iana"
},
"application/mosskey-data": {
"source": "iana"
},
"application/mosskey-request": {
"source": "iana"
},
"application/mp21": {
"source": "iana",
"extensions": ["m21","mp21"]
},
"application/mp4": {
"source": "iana",
"extensions": ["mp4s","m4p"]
},
"application/mpeg4-generic": {
"source": "iana"
},
"application/mpeg4-iod": {
"source": "iana"
},
"application/mpeg4-iod-xmt": {
"source": "iana"
},
"application/mrb-consumer+xml": {
"source": "iana"
},
"application/mrb-publish+xml": {
"source": "iana"
},
"application/msc-ivr+xml": {
"source": "iana"
},
"application/msc-mixer+xml": {
"source": "iana"
},
"application/msword": {
"source": "iana",
"compressible": false,
"extensions": ["doc","dot"]
},
"application/mxf": {
"source": "iana",
"extensions": ["mxf"]
},
"application/nasdata": {
"source": "iana"
},
"application/news-checkgroups": {
"source": "iana"
},
"application/news-groupinfo": {
"source": "iana"
},
"application/news-transmission": {
"source": "iana"
},
"application/nlsml+xml": {
"source": "iana"
},
"application/nss": {
"source": "iana"
},
"application/ocsp-request": {
"source": "iana"
},
"application/ocsp-response": {
"source": "iana"
},
"application/octet-stream": {
"source": "iana",
"compressible": false,
"extensions": ["bin","dms","lrf","mar","so","dist","distz","pkg","bpk","dump","elc","deploy","buffer"]
},
"application/oda": {
"source": "iana",
"extensions": ["oda"]
},
"application/odx": {
"source": "iana"
},
"application/oebps-package+xml": {
"source": "iana",
"extensions": ["opf"]
},
"application/ogg": {
"source": "iana",
"compressible": false,
"extensions": ["ogx"]
},
"application/omdoc+xml": {
"source": "apache",
"extensions": ["omdoc"]
},
"application/onenote": {
"source": "apache",
"extensions": ["onetoc","onetoc2","onetmp","onepkg"]
},
"application/oxps": {
"source": "iana",
"extensions": ["oxps"]
},
"application/p2p-overlay+xml": {
"source": "iana"
},
"application/parityfec": {
"source": "iana"
},
"application/patch-ops-error+xml": {
"source": "iana",
"extensions": ["xer"]
},
"application/pdf": {
"source": "iana",
"compressible": false,
"extensions": ["pdf"]
},
"application/pdx": {
"source": "iana"
},
"application/pgp-encrypted": {
"source": "iana",
"compressible": false,
"extensions": ["pgp"]
},
"application/pgp-keys": {
"source": "iana"
},
"application/pgp-signature": {
"source": "iana",
"extensions": ["asc","sig"]
},
"application/pics-rules": {
"source": "apache",
"extensions": ["prf"]
},
"application/pidf+xml": {
"source": "iana"
},
"application/pidf-diff+xml": {
"source": "iana"
},
"application/pkcs10": {
"source": "iana",
"extensions": ["p10"]
},
"application/pkcs7-mime": {
"source": "iana",
"extensions": ["p7m","p7c"]
},
"application/pkcs7-signature": {
"source": "iana",
"extensions": ["p7s"]
},
"application/pkcs8": {
"source": "iana",
"extensions": ["p8"]
},
"application/pkix-attr-cert": {
"source": "iana",
"extensions": ["ac"]
},
"application/pkix-cert": {
"source": "iana",
"extensions": ["cer"]
},
"application/pkix-crl": {
"source": "iana",
"extensions": ["crl"]
},
"application/pkix-pkipath": {
"source": "iana",
"extensions": ["pkipath"]
},
"application/pkixcmp": {
"source": "iana",
"extensions": ["pki"]
},
"application/pls+xml": {
"source": "iana",
"extensions": ["pls"]
},
"application/poc-settings+xml": {
"source": "iana"
},
"application/postscript": {
"source": "iana",
"compressible": true,
"extensions": ["ai","eps","ps"]
},
"application/provenance+xml": {
"source": "iana"
},
"application/prs.alvestrand.titrax-sheet": {
"source": "iana"
},
"application/prs.cww": {
"source": "iana",
"extensions": ["cww"]
},
"application/prs.hpub+zip": {
"source": "iana"
},
"application/prs.nprend": {
"source": "iana"
},
"application/prs.plucker": {
"source": "iana"
},
"application/prs.rdf-xml-crypt": {
"source": "iana"
},
"application/prs.xsf+xml": {
"source": "iana"
},
"application/pskc+xml": {
"source": "iana",
"extensions": ["pskcxml"]
},
"application/qsig": {
"source": "iana"
},
"application/raptorfec": {
"source": "iana"
},
"application/rdap+json": {
"source": "iana",
"compressible": true
},
"application/rdf+xml": {
"source": "iana",
"compressible": true,
"extensions": ["rdf"]
},
"application/reginfo+xml": {
"source": "iana",
"extensions": ["rif"]
},
"application/relax-ng-compact-syntax": {
"source": "iana",
"extensions": ["rnc"]
},
"application/remote-printing": {
"source": "iana"
},
"application/reputon+json": {
"source": "iana",
"compressible": true
},
"application/resource-lists+xml": {
"source": "iana",
"extensions": ["rl"]
},
"application/resource-lists-diff+xml": {
"source": "iana",
"extensions": ["rld"]
},
"application/riscos": {
"source": "iana"
},
"application/rlmi+xml": {
"source": "iana"
},
"application/rls-services+xml": {
"source": "iana",
"extensions": ["rs"]
},
"application/rpki-ghostbusters": {
"source": "iana",
"extensions": ["gbr"]
},
"application/rpki-manifest": {
"source": "iana",
"extensions": ["mft"]
},
"application/rpki-roa": {
"source": "iana",
"extensions": ["roa"]
},
"application/rpki-updown": {
"source": "iana"
},
"application/rsd+xml": {
"source": "apache",
"extensions": ["rsd"]
},
"application/rss+xml": {
"source": "apache",
"compressible": true,
"extensions": ["rss"]
},
"application/rtf": {
"source": "iana",
"compressible": true,
"extensions": ["rtf"]
},
"application/rtploopback": {
"source": "iana"
},
"application/rtx": {
"source": "iana"
},
"application/samlassertion+xml": {
"source": "iana"
},
"application/samlmetadata+xml": {
"source": "iana"
},
"application/sbml+xml": {
"source": "iana",
"extensions": ["sbml"]
},
"application/scaip+xml": {
"source": "iana"
},
"application/scvp-cv-request": {
"source": "iana",
"extensions": ["scq"]
},
"application/scvp-cv-response": {
"source": "iana",
"extensions": ["scs"]
},
"application/scvp-vp-request": {
"source": "iana",
"extensions": ["spq"]
},
"application/scvp-vp-response": {
"source": "iana",
"extensions": ["spp"]
},
"application/sdp": {
"source": "iana",
"extensions": ["sdp"]
},
"application/sep+xml": {
"source": "iana"
},
"application/sep-exi": {
"source": "iana"
},
"application/session-info": {
"source": "iana"
},
"application/set-payment": {
"source": "iana"
},
"application/set-payment-initiation": {
"source": "iana",
"extensions": ["setpay"]
},
"application/set-registration": {
"source": "iana"
},
"application/set-registration-initiation": {
"source": "iana",
"extensions": ["setreg"]
},
"application/sgml": {
"source": "iana"
},
"application/sgml-open-catalog": {
"source": "iana"
},
"application/shf+xml": {
"source": "iana",
"extensions": ["shf"]
},
"application/sieve": {
"source": "iana"
},
"application/simple-filter+xml": {
"source": "iana"
},
"application/simple-message-summary": {
"source": "iana"
},
"application/simplesymbolcontainer": {
"source": "iana"
},
"application/slate": {
"source": "iana"
},
"application/smil": {
"source": "iana"
},
"application/smil+xml": {
"source": "iana",
"extensions": ["smi","smil"]
},
"application/smpte336m": {
"source": "iana"
},
"application/soap+fastinfoset": {
"source": "iana"
},
"application/soap+xml": {
"source": "iana",
"compressible": true
},
"application/sparql-query": {
"source": "iana",
"extensions": ["rq"]
},
"application/sparql-results+xml": {
"source": "iana",
"extensions": ["srx"]
},
"application/spirits-event+xml": {
"source": "iana"
},
"application/sql": {
"source": "iana"
},
"application/srgs": {
"source": "iana",
"extensions": ["gram"]
},
"application/srgs+xml": {
"source": "iana",
"extensions": ["grxml"]
},
"application/sru+xml": {
"source": "iana",
"extensions": ["sru"]
},
"application/ssdl+xml": {
"source": "apache",
"extensions": ["ssdl"]
},
"application/ssml+xml": {
"source": "iana",
"extensions": ["ssml"]
},
"application/tamp-apex-update": {
"source": "iana"
},
"application/tamp-apex-update-confirm": {
"source": "iana"
},
"application/tamp-community-update": {
"source": "iana"
},
"application/tamp-community-update-confirm": {
"source": "iana"
},
"application/tamp-error": {
"source": "iana"
},
"application/tamp-sequence-adjust": {
"source": "iana"
},
"application/tamp-sequence-adjust-confirm": {
"source": "iana"
},
"application/tamp-status-query": {
"source": "iana"
},
"application/tamp-status-response": {
"source": "iana"
},
"application/tamp-update": {
"source": "iana"
},
"application/tamp-update-confirm": {
"source": "iana"
},
"application/tar": {
"compressible": true
},
"application/tei+xml": {
"source": "iana",
"extensions": ["tei","teicorpus"]
},
"application/thraud+xml": {
"source": "iana",
"extensions": ["tfi"]
},
"application/timestamp-query": {
"source": "iana"
},
"application/timestamp-reply": {
"source": "iana"
},
"application/timestamped-data": {
"source": "iana",
"extensions": ["tsd"]
},
"application/ttml+xml": {
"source": "iana"
},
"application/tve-trigger": {
"source": "iana"
},
"application/ulpfec": {
"source": "iana"
},
"application/urc-grpsheet+xml": {
"source": "iana"
},
"application/urc-ressheet+xml": {
"source": "iana"
},
"application/urc-targetdesc+xml": {
"source": "iana"
},
"application/urc-uisocketdesc+xml": {
"source": "iana"
},
"application/vcard+json": {
"source": "iana",
"compressible": true
},
"application/vcard+xml": {
"source": "iana"
},
"application/vemmi": {
"source": "iana"
},
"application/vividence.scriptfile": {
"source": "apache"
},
"application/vnd.3gpp.bsf+xml": {
"source": "iana"
},
"application/vnd.3gpp.pic-bw-large": {
"source": "iana",
"extensions": ["plb"]
},
"application/vnd.3gpp.pic-bw-small": {
"source": "iana",
"extensions": ["psb"]
},
"application/vnd.3gpp.pic-bw-var": {
"source": "iana",
"extensions": ["pvb"]
},
"application/vnd.3gpp.sms": {
"source": "iana"
},
"application/vnd.3gpp2.bcmcsinfo+xml": {
"source": "iana"
},
"application/vnd.3gpp2.sms": {
"source": "iana"
},
"application/vnd.3gpp2.tcap": {
"source": "iana",
"extensions": ["tcap"]
},
"application/vnd.3m.post-it-notes": {
"source": "iana",
"extensions": ["pwn"]
},
"application/vnd.accpac.simply.aso": {
"source": "iana",
"extensions": ["aso"]
},
"application/vnd.accpac.simply.imp": {
"source": "iana",
"extensions": ["imp"]
},
"application/vnd.acucobol": {
"source": "iana",
"extensions": ["acu"]
},
"application/vnd.acucorp": {
"source": "iana",
"extensions": ["atc","acutc"]
},
"application/vnd.adobe.air-application-installer-package+zip": {
"source": "apache",
"extensions": ["air"]
},
"application/vnd.adobe.flash.movie": {
"source": "iana"
},
"application/vnd.adobe.formscentral.fcdt": {
"source": "iana",
"extensions": ["fcdt"]
},
"application/vnd.adobe.fxp": {
"source": "iana",
"extensions": ["fxp","fxpl"]
},
"application/vnd.adobe.partial-upload": {
"source": "iana"
},
"application/vnd.adobe.xdp+xml": {
"source": "iana",
"extensions": ["xdp"]
},
"application/vnd.adobe.xfdf": {
"source": "iana",
"extensions": ["xfdf"]
},
"application/vnd.aether.imp": {
"source": "iana"
},
"application/vnd.ah-barcode": {
"source": "iana"
},
"application/vnd.ahead.space": {
"source": "iana",
"extensions": ["ahead"]
},
"application/vnd.airzip.filesecure.azf": {
"source": "iana",
"extensions": ["azf"]
},
"application/vnd.airzip.filesecure.azs": {
"source": "iana",
"extensions": ["azs"]
},
"application/vnd.amazon.ebook": {
"source": "apache",
"extensions": ["azw"]
},
"application/vnd.americandynamics.acc": {
"source": "iana",
"extensions": ["acc"]
},
"application/vnd.amiga.ami": {
"source": "iana",
"extensions": ["ami"]
},
"application/vnd.amundsen.maze+xml": {
"source": "iana"
},
"application/vnd.android.package-archive": {
"source": "apache",
"compressible": false,
"extensions": ["apk"]
},
"application/vnd.anser-web-certificate-issue-initiation": {
"source": "iana",
"extensions": ["cii"]
},
"application/vnd.anser-web-funds-transfer-initiation": {
"source": "apache",
"extensions": ["fti"]
},
"application/vnd.antix.game-component": {
"source": "iana",
"extensions": ["atx"]
},
"application/vnd.apache.thrift.binary": {
"source": "iana"
},
"application/vnd.apache.thrift.compact": {
"source": "iana"
},
"application/vnd.apache.thrift.json": {
"source": "iana"
},
"application/vnd.api+json": {
"source": "iana",
"compressible": true
},
"application/vnd.apple.installer+xml": {
"source": "iana",
"extensions": ["mpkg"]
},
"application/vnd.apple.mpegurl": {
"source": "iana",
"extensions": ["m3u8"]
},
"application/vnd.arastra.swi": {
"source": "iana"
},
"application/vnd.aristanetworks.swi": {
"source": "iana",
"extensions": ["swi"]
},
"application/vnd.artsquare": {
"source": "iana"
},
"application/vnd.astraea-software.iota": {
"source": "iana",
"extensions": ["iota"]
},
"application/vnd.audiograph": {
"source": "iana",
"extensions": ["aep"]
},
"application/vnd.autopackage": {
"source": "iana"
},
"application/vnd.avistar+xml": {
"source": "iana"
},
"application/vnd.balsamiq.bmml+xml": {
"source": "iana"
},
"application/vnd.bekitzur-stech+json": {
"source": "iana",
"compressible": true
},
"application/vnd.blueice.multipass": {
"source": "iana",
"extensions": ["mpm"]
},
"application/vnd.bluetooth.ep.oob": {
"source": "iana"
},
"application/vnd.bluetooth.le.oob": {
"source": "iana"
},
"application/vnd.bmi": {
"source": "iana",
"extensions": ["bmi"]
},
"application/vnd.businessobjects": {
"source": "iana",
"extensions": ["rep"]
},
"application/vnd.cab-jscript": {
"source": "iana"
},
"application/vnd.canon-cpdl": {
"source": "iana"
},
"application/vnd.canon-lips": {
"source": "iana"
},
"application/vnd.cendio.thinlinc.clientconf": {
"source": "iana"
},
"application/vnd.century-systems.tcp_stream": {
"source": "iana"
},
"application/vnd.chemdraw+xml": {
"source": "iana",
"extensions": ["cdxml"]
},
"application/vnd.chipnuts.karaoke-mmd": {
"source": "iana",
"extensions": ["mmd"]
},
"application/vnd.cinderella": {
"source": "iana",
"extensions": ["cdy"]
},
"application/vnd.cirpack.isdn-ext": {
"source": "iana"
},
"application/vnd.citationstyles.style+xml": {
"source": "iana"
},
"application/vnd.claymore": {
"source": "iana",
"extensions": ["cla"]
},
"application/vnd.cloanto.rp9": {
"source": "iana",
"extensions": ["rp9"]
},
"application/vnd.clonk.c4group": {
"source": "iana",
"extensions": ["c4g","c4d","c4f","c4p","c4u"]
},
"application/vnd.cluetrust.cartomobile-config": {
"source": "iana",
"extensions": ["c11amc"]
},
"application/vnd.cluetrust.cartomobile-config-pkg": {
"source": "iana",
"extensions": ["c11amz"]
},
"application/vnd.coffeescript": {
"source": "iana"
},
"application/vnd.collection+json": {
"source": "iana",
"compressible": true
},
"application/vnd.collection.doc+json": {
"source": "iana",
"compressible": true
},
"application/vnd.collection.next+json": {
"source": "iana",
"compressible": true
},
"application/vnd.commerce-battelle": {
"source": "iana"
},
"application/vnd.commonspace": {
"source": "iana",
"extensions": ["csp"]
},
"application/vnd.contact.cmsg": {
"source": "iana",
"extensions": ["cdbcmsg"]
},
"application/vnd.cosmocaller": {
"source": "iana",
"extensions": ["cmc"]
},
"application/vnd.crick.clicker": {
"source": "iana",
"extensions": ["clkx"]
},
"application/vnd.crick.clicker.keyboard": {
"source": "iana",
"extensions": ["clkk"]
},
"application/vnd.crick.clicker.palette": {
"source": "iana",
"extensions": ["clkp"]
},
"application/vnd.crick.clicker.template": {
"source": "iana",
"extensions": ["clkt"]
},
"application/vnd.crick.clicker.wordbank": {
"source": "iana",
"extensions": ["clkw"]
},
"application/vnd.criticaltools.wbs+xml": {
"source": "iana",
"extensions": ["wbs"]
},
"application/vnd.ctc-posml": {
"source": "iana",
"extensions": ["pml"]
},
"application/vnd.ctct.ws+xml": {
"source": "iana"
},
"application/vnd.cups-pdf": {
"source": "iana"
},
"application/vnd.cups-postscript": {
"source": "iana"
},
"application/vnd.cups-ppd": {
"source": "iana",
"extensions": ["ppd"]
},
"application/vnd.cups-raster": {
"source": "iana"
},
"application/vnd.cups-raw": {
"source": "iana"
},
"application/vnd.curl": {
"source": "iana"
},
"application/vnd.curl.car": {
"source": "apache",
"extensions": ["car"]
},
"application/vnd.curl.pcurl": {
"source": "apache",
"extensions": ["pcurl"]
},
"application/vnd.cyan.dean.root+xml": {
"source": "iana"
},
"application/vnd.cybank": {
"source": "iana"
},
"application/vnd.dart": {
"source": "iana",
"compressible": true,
"extensions": ["dart"]
},
"application/vnd.data-vision.rdz": {
"source": "iana",
"extensions": ["rdz"]
},
"application/vnd.debian.binary-package": {
"source": "iana"
},
"application/vnd.dece.data": {
"source": "iana",
"extensions": ["uvf","uvvf","uvd","uvvd"]
},
"application/vnd.dece.ttml+xml": {
"source": "iana",
"extensions": ["uvt","uvvt"]
},
"application/vnd.dece.unspecified": {
"source": "iana",
"extensions": ["uvx","uvvx"]
},
"application/vnd.dece.zip": {
"source": "iana",
"extensions": ["uvz","uvvz"]
},
"application/vnd.denovo.fcselayout-link": {
"source": "iana",
"extensions": ["fe_launch"]
},
"application/vnd.desmume-movie": {
"source": "iana"
},
"application/vnd.dir-bi.plate-dl-nosuffix": {
"source": "iana"
},
"application/vnd.dm.delegation+xml": {
"source": "iana"
},
"application/vnd.dna": {
"source": "iana",
"extensions": ["dna"]
},
"application/vnd.document+json": {
"source": "iana",
"compressible": true
},
"application/vnd.dolby.mlp": {
"source": "apache",
"extensions": ["mlp"]
},
"application/vnd.dolby.mobile.1": {
"source": "iana"
},
"application/vnd.dolby.mobile.2": {
"source": "iana"
},
"application/vnd.doremir.scorecloud-binary-document": {
"source": "iana"
},
"application/vnd.dpgraph": {
"source": "iana",
"extensions": ["dpg"]
},
"application/vnd.dreamfactory": {
"source": "iana",
"extensions": ["dfac"]
},
"application/vnd.ds-keypoint": {
"source": "apache",
"extensions": ["kpxx"]
},
"application/vnd.dtg.local": {
"source": "iana"
},
"application/vnd.dtg.local.flash": {
"source": "iana"
},
"application/vnd.dtg.local.html": {
"source": "iana"
},
"application/vnd.dvb.ait": {
"source": "iana",
"extensions": ["ait"]
},
"application/vnd.dvb.dvbj": {
"source": "iana"
},
"application/vnd.dvb.esgcontainer": {
"source": "iana"
},
"application/vnd.dvb.ipdcdftnotifaccess": {
"source": "iana"
},
"application/vnd.dvb.ipdcesgaccess": {
"source": "iana"
},
"application/vnd.dvb.ipdcesgaccess2": {
"source": "iana"
},
"application/vnd.dvb.ipdcesgpdd": {
"source": "iana"
},
"application/vnd.dvb.ipdcroaming": {
"source": "iana"
},
"application/vnd.dvb.iptv.alfec-base": {
"source": "iana"
},
"application/vnd.dvb.iptv.alfec-enhancement": {
"source": "iana"
},
"application/vnd.dvb.notif-aggregate-root+xml": {
"source": "iana"
},
"application/vnd.dvb.notif-container+xml": {
"source": "iana"
},
"application/vnd.dvb.notif-generic+xml": {
"source": "iana"
},
"application/vnd.dvb.notif-ia-msglist+xml": {
"source": "iana"
},
"application/vnd.dvb.notif-ia-registration-request+xml": {
"source": "iana"
},
"application/vnd.dvb.notif-ia-registration-response+xml": {
"source": "iana"
},
"application/vnd.dvb.notif-init+xml": {
"source": "iana"
},
"application/vnd.dvb.pfr": {
"source": "iana"
},
"application/vnd.dvb.service": {
"source": "iana",
"extensions": ["svc"]
},
"application/vnd.dxr": {
"source": "iana"
},
"application/vnd.dynageo": {
"source": "iana",
"extensions": ["geo"]
},
"application/vnd.dzr": {
"source": "iana"
},
"application/vnd.easykaraoke.cdgdownload": {
"source": "iana"
},
"application/vnd.ecdis-update": {
"source": "iana"
},
"application/vnd.ecowin.chart": {
"source": "iana",
"extensions": ["mag"]
},
"application/vnd.ecowin.filerequest": {
"source": "iana"
},
"application/vnd.ecowin.fileupdate": {
"source": "iana"
},
"application/vnd.ecowin.series": {
"source": "iana"
},
"application/vnd.ecowin.seriesrequest": {
"source": "iana"
},
"application/vnd.ecowin.seriesupdate": {
"source": "iana"
},
"application/vnd.emclient.accessrequest+xml": {
"source": "iana"
},
"application/vnd.enliven": {
"source": "iana",
"extensions": ["nml"]
},
"application/vnd.enphase.envoy": {
"source": "iana"
},
"application/vnd.eprints.data+xml": {
"source": "iana"
},
"application/vnd.epson.esf": {
"source": "iana",
"extensions": ["esf"]
},
"application/vnd.epson.msf": {
"source": "iana",
"extensions": ["msf"]
},
"application/vnd.epson.quickanime": {
"source": "iana",
"extensions": ["qam"]
},
"application/vnd.epson.salt": {
"source": "iana",
"extensions": ["slt"]
},
"application/vnd.epson.ssf": {
"source": "iana",
"extensions": ["ssf"]
},
"application/vnd.ericsson.quickcall": {
"source": "iana"
},
"application/vnd.eszigno3+xml": {
"source": "iana",
"extensions": ["es3","et3"]
},
"application/vnd.etsi.aoc+xml": {
"source": "iana"
},
"application/vnd.etsi.asic-e+zip": {
"source": "iana"
},
"application/vnd.etsi.asic-s+zip": {
"source": "iana"
},
"application/vnd.etsi.cug+xml": {
"source": "iana"
},
"application/vnd.etsi.iptvcommand+xml": {
"source": "iana"
},
"application/vnd.etsi.iptvdiscovery+xml": {
"source": "iana"
},
"application/vnd.etsi.iptvprofile+xml": {
"source": "iana"
},
"application/vnd.etsi.iptvsad-bc+xml": {
"source": "iana"
},
"application/vnd.etsi.iptvsad-cod+xml": {
"source": "iana"
},
"application/vnd.etsi.iptvsad-npvr+xml": {
"source": "iana"
},
"application/vnd.etsi.iptvservice+xml": {
"source": "iana"
},
"application/vnd.etsi.iptvsync+xml": {
"source": "iana"
},
"application/vnd.etsi.iptvueprofile+xml": {
"source": "iana"
},
"application/vnd.etsi.mcid+xml": {
"source": "iana"
},
"application/vnd.etsi.mheg5": {
"source": "iana"
},
"application/vnd.etsi.overload-control-policy-dataset+xml": {
"source": "iana"
},
"application/vnd.etsi.pstn+xml": {
"source": "iana"
},
"application/vnd.etsi.sci+xml": {
"source": "iana"
},
"application/vnd.etsi.simservs+xml": {
"source": "iana"
},
"application/vnd.etsi.timestamp-token": {
"source": "iana"
},
"application/vnd.etsi.tsl+xml": {
"source": "iana"
},
"application/vnd.etsi.tsl.der": {
"source": "iana"
},
"application/vnd.eudora.data": {
"source": "iana"
},
"application/vnd.ezpix-album": {
"source": "iana",
"extensions": ["ez2"]
},
"application/vnd.ezpix-package": {
"source": "iana",
"extensions": ["ez3"]
},
"application/vnd.f-secure.mobile": {
"source": "iana"
},
"application/vnd.fastcopy-disk-image": {
"source": "iana"
},
"application/vnd.fdf": {
"source": "iana",
"extensions": ["fdf"]
},
"application/vnd.fdsn.mseed": {
"source": "iana",
"extensions": ["mseed"]
},
"application/vnd.fdsn.seed": {
"source": "iana",
"extensions": ["seed","dataless"]
},
"application/vnd.ffsns": {
"source": "iana"
},
"application/vnd.fints": {
"source": "iana"
},
"application/vnd.flographit": {
"source": "iana",
"extensions": ["gph"]
},
"application/vnd.fluxtime.clip": {
"source": "iana",
"extensions": ["ftc"]
},
"application/vnd.font-fontforge-sfd": {
"source": "iana"
},
"application/vnd.framemaker": {
"source": "iana",
"extensions": ["fm","frame","maker","book"]
},
"application/vnd.frogans.fnc": {
"source": "iana",
"extensions": ["fnc"]
},
"application/vnd.frogans.ltf": {
"source": "iana",
"extensions": ["ltf"]
},
"application/vnd.fsc.weblaunch": {
"source": "iana",
"extensions": ["fsc"]
},
"application/vnd.fujitsu.oasys": {
"source": "iana",
"extensions": ["oas"]
},
"application/vnd.fujitsu.oasys2": {
"source": "iana",
"extensions": ["oa2"]
},
"application/vnd.fujitsu.oasys3": {
"source": "iana",
"extensions": ["oa3"]
},
"application/vnd.fujitsu.oasysgp": {
"source": "iana",
"extensions": ["fg5"]
},
"application/vnd.fujitsu.oasysprs": {
"source": "iana",
"extensions": ["bh2"]
},
"application/vnd.fujixerox.art-ex": {
"source": "iana"
},
"application/vnd.fujixerox.art4": {
"source": "iana"
},
"application/vnd.fujixerox.ddd": {
"source": "iana",
"extensions": ["ddd"]
},
"application/vnd.fujixerox.docuworks": {
"source": "iana",
"extensions": ["xdw"]
},
"application/vnd.fujixerox.docuworks.binder": {
"source": "iana",
"extensions": ["xbd"]
},
"application/vnd.fujixerox.docuworks.container": {
"source": "iana"
},
"application/vnd.fujixerox.hbpl": {
"source": "iana"
},
"application/vnd.fut-misnet": {
"source": "iana"
},
"application/vnd.fuzzysheet": {
"source": "iana",
"extensions": ["fzs"]
},
"application/vnd.genomatix.tuxedo": {
"source": "iana",
"extensions": ["txd"]
},
"application/vnd.geo+json": {
"source": "iana",
"compressible": true
},
"application/vnd.geocube+xml": {
"source": "iana"
},
"application/vnd.geogebra.file": {
"source": "iana",
"extensions": ["ggb"]
},
"application/vnd.geogebra.tool": {
"source": "iana",
"extensions": ["ggt"]
},
"application/vnd.geometry-explorer": {
"source": "iana",
"extensions": ["gex","gre"]
},
"application/vnd.geonext": {
"source": "iana",
"extensions": ["gxt"]
},
"application/vnd.geoplan": {
"source": "iana",
"extensions": ["g2w"]
},
"application/vnd.geospace": {
"source": "iana",
"extensions": ["g3w"]
},
"application/vnd.gerber": {
"source": "iana"
},
"application/vnd.globalplatform.card-content-mgt": {
"source": "iana"
},
"application/vnd.globalplatform.card-content-mgt-response": {
"source": "iana"
},
"application/vnd.gmx": {
"source": "iana",
"extensions": ["gmx"]
},
"application/vnd.google-earth.kml+xml": {
"source": "iana",
"compressible": true,
"extensions": ["kml"]
},
"application/vnd.google-earth.kmz": {
"source": "iana",
"compressible": false,
"extensions": ["kmz"]
},
"application/vnd.gov.sk.e-form+xml": {
"source": "iana"
},
"application/vnd.gov.sk.e-form+zip": {
"source": "iana"
},
"application/vnd.gov.sk.xmldatacontainer+xml": {
"source": "iana"
},
"application/vnd.grafeq": {
"source": "iana",
"extensions": ["gqf","gqs"]
},
"application/vnd.gridmp": {
"source": "iana"
},
"application/vnd.groove-account": {
"source": "iana",
"extensions": ["gac"]
},
"application/vnd.groove-help": {
"source": "iana",
"extensions": ["ghf"]
},
"application/vnd.groove-identity-message": {
"source": "iana",
"extensions": ["gim"]
},
"application/vnd.groove-injector": {
"source": "iana",
"extensions": ["grv"]
},
"application/vnd.groove-tool-message": {
"source": "iana",
"extensions": ["gtm"]
},
"application/vnd.groove-tool-template": {
"source": "iana",
"extensions": ["tpl"]
},
"application/vnd.groove-vcard": {
"source": "iana",
"extensions": ["vcg"]
},
"application/vnd.hal+json": {
"source": "iana",
"compressible": true
},
"application/vnd.hal+xml": {
"source": "iana",
"extensions": ["hal"]
},
"application/vnd.handheld-entertainment+xml": {
"source": "iana",
"extensions": ["zmm"]
},
"application/vnd.hbci": {
"source": "iana",
"extensions": ["hbci"]
},
"application/vnd.hcl-bireports": {
"source": "iana"
},
"application/vnd.heroku+json": {
"source": "iana",
"compressible": true
},
"application/vnd.hhe.lesson-player": {
"source": "iana",
"extensions": ["les"]
},
"application/vnd.hp-hpgl": {
"source": "iana",
"extensions": ["hpgl"]
},
"application/vnd.hp-hpid": {
"source": "iana",
"extensions": ["hpid"]
},
"application/vnd.hp-hps": {
"source": "iana",
"extensions": ["hps"]
},
"application/vnd.hp-jlyt": {
"source": "iana",
"extensions": ["jlt"]
},
"application/vnd.hp-pcl": {
"source": "iana",
"extensions": ["pcl"]
},
"application/vnd.hp-pclxl": {
"source": "iana",
"extensions": ["pclxl"]
},
"application/vnd.httphone": {
"source": "iana"
},
"application/vnd.hydrostatix.sof-data": {
"source": "iana"
},
"application/vnd.hzn-3d-crossword": {
"source": "iana"
},
"application/vnd.ibm.afplinedata": {
"source": "iana"
},
"application/vnd.ibm.electronic-media": {
"source": "iana"
},
"application/vnd.ibm.minipay": {
"source": "iana",
"extensions": ["mpy"]
},
"application/vnd.ibm.modcap": {
"source": "iana",
"extensions": ["afp","listafp","list3820"]
},
"application/vnd.ibm.rights-management": {
"source": "iana",
"extensions": ["irm"]
},
"application/vnd.ibm.secure-container": {
"source": "iana",
"extensions": ["sc"]
},
"application/vnd.iccprofile": {
"source": "iana",
"extensions": ["icc","icm"]
},
"application/vnd.ieee.1905": {
"source": "iana"
},
"application/vnd.igloader": {
"source": "iana",
"extensions": ["igl"]
},
"application/vnd.immervision-ivp": {
"source": "iana",
"extensions": ["ivp"]
},
"application/vnd.immervision-ivu": {
"source": "iana",
"extensions": ["ivu"]
},
"application/vnd.ims.imsccv1p1": {
"source": "iana"
},
"application/vnd.ims.imsccv1p2": {
"source": "iana"
},
"application/vnd.ims.imsccv1p3": {
"source": "iana"
},
"application/vnd.ims.lis.v2.result+json": {
"source": "iana",
"compressible": true
},
"application/vnd.ims.lti.v2.toolconsumerprofile+json": {
"source": "iana",
"compressible": true
},
"application/vnd.ims.lti.v2.toolproxy+json": {
"source": "iana",
"compressible": true
},
"application/vnd.ims.lti.v2.toolproxy.id+json": {
"source": "iana",
"compressible": true
},
"application/vnd.ims.lti.v2.toolsettings+json": {
"source": "iana",
"compressible": true
},
"application/vnd.ims.lti.v2.toolsettings.simple+json": {
"source": "iana",
"compressible": true
},
"application/vnd.informedcontrol.rms+xml": {
"source": "iana"
},
"application/vnd.informix-visionary": {
"source": "iana"
},
"application/vnd.infotech.project": {
"source": "iana"
},
"application/vnd.infotech.project+xml": {
"source": "iana"
},
"application/vnd.innopath.wamp.notification": {
"source": "iana"
},
"application/vnd.insors.igm": {
"source": "iana",
"extensions": ["igm"]
},
"application/vnd.intercon.formnet": {
"source": "iana",
"extensions": ["xpw","xpx"]
},
"application/vnd.intergeo": {
"source": "iana",
"extensions": ["i2g"]
},
"application/vnd.intertrust.digibox": {
"source": "iana"
},
"application/vnd.intertrust.nncp": {
"source": "iana"
},
"application/vnd.intu.qbo": {
"source": "iana",
"extensions": ["qbo"]
},
"application/vnd.intu.qfx": {
"source": "iana",
"extensions": ["qfx"]
},
"application/vnd.iptc.g2.catalogitem+xml": {
"source": "iana"
},
"application/vnd.iptc.g2.conceptitem+xml": {
"source": "iana"
},
"application/vnd.iptc.g2.knowledgeitem+xml": {
"source": "iana"
},
"application/vnd.iptc.g2.newsitem+xml": {
"source": "iana"
},
"application/vnd.iptc.g2.newsmessage+xml": {
"source": "iana"
},
"application/vnd.iptc.g2.packageitem+xml": {
"source": "iana"
},
"application/vnd.iptc.g2.planningitem+xml": {
"source": "iana"
},
"application/vnd.ipunplugged.rcprofile": {
"source": "iana",
"extensions": ["rcprofile"]
},
"application/vnd.irepository.package+xml": {
"source": "iana",
"extensions": ["irp"]
},
"application/vnd.is-xpr": {
"source": "iana",
"extensions": ["xpr"]
},
"application/vnd.isac.fcs": {
"source": "iana",
"extensions": ["fcs"]
},
"application/vnd.jam": {
"source": "iana",
"extensions": ["jam"]
},
"application/vnd.japannet-directory-service": {
"source": "iana"
},
"application/vnd.japannet-jpnstore-wakeup": {
"source": "iana"
},
"application/vnd.japannet-payment-wakeup": {
"source": "iana"
},
"application/vnd.japannet-registration": {
"source": "iana"
},
"application/vnd.japannet-registration-wakeup": {
"source": "iana"
},
"application/vnd.japannet-setstore-wakeup": {
"source": "iana"
},
"application/vnd.japannet-verification": {
"source": "iana"
},
"application/vnd.japannet-verification-wakeup": {
"source": "iana"
},
"application/vnd.jcp.javame.midlet-rms": {
"source": "iana",
"extensions": ["rms"]
},
"application/vnd.jisp": {
"source": "iana",
"extensions": ["jisp"]
},
"application/vnd.joost.joda-archive": {
"source": "iana",
"extensions": ["joda"]
},
"application/vnd.jsk.isdn-ngn": {
"source": "iana"
},
"application/vnd.kahootz": {
"source": "iana",
"extensions": ["ktz","ktr"]
},
"application/vnd.kde.karbon": {
"source": "iana",
"extensions": ["karbon"]
},
"application/vnd.kde.kchart": {
"source": "iana",
"extensions": ["chrt"]
},
"application/vnd.kde.kformula": {
"source": "iana",
"extensions": ["kfo"]
},
"application/vnd.kde.kivio": {
"source": "iana",
"extensions": ["flw"]
},
"application/vnd.kde.kontour": {
"source": "iana",
"extensions": ["kon"]
},
"application/vnd.kde.kpresenter": {
"source": "iana",
"extensions": ["kpr","kpt"]
},
"application/vnd.kde.kspread": {
"source": "iana",
"extensions": ["ksp"]
},
"application/vnd.kde.kword": {
"source": "iana",
"extensions": ["kwd","kwt"]
},
"application/vnd.kenameaapp": {
"source": "iana",
"extensions": ["htke"]
},
"application/vnd.kidspiration": {
"source": "iana",
"extensions": ["kia"]
},
"application/vnd.kinar": {
"source": "iana",
"extensions": ["kne","knp"]
},
"application/vnd.koan": {
"source": "iana",
"extensions": ["skp","skd","skt","skm"]
},
"application/vnd.kodak-descriptor": {
"source": "iana",
"extensions": ["sse"]
},
"application/vnd.las.las+xml": {
"source": "iana",
"extensions": ["lasxml"]
},
"application/vnd.liberty-request+xml": {
"source": "iana"
},
"application/vnd.llamagraphics.life-balance.desktop": {
"source": "iana",
"extensions": ["lbd"]
},
"application/vnd.llamagraphics.life-balance.exchange+xml": {
"source": "iana",
"extensions": ["lbe"]
},
"application/vnd.lotus-1-2-3": {
"source": "iana",
"extensions": ["123"]
},
"application/vnd.lotus-approach": {
"source": "iana",
"extensions": ["apr"]
},
"application/vnd.lotus-freelance": {
"source": "iana",
"extensions": ["pre"]
},
"application/vnd.lotus-notes": {
"source": "iana",
"extensions": ["nsf"]
},
"application/vnd.lotus-organizer": {
"source": "iana",
"extensions": ["org"]
},
"application/vnd.lotus-screencam": {
"source": "iana",
"extensions": ["scm"]
},
"application/vnd.lotus-wordpro": {
"source": "iana",
"extensions": ["lwp"]
},
"application/vnd.macports.portpkg": {
"source": "iana",
"extensions": ["portpkg"]
},
"application/vnd.marlin.drm.actiontoken+xml": {
"source": "iana"
},
"application/vnd.marlin.drm.conftoken+xml": {
"source": "iana"
},
"application/vnd.marlin.drm.license+xml": {
"source": "iana"
},
"application/vnd.marlin.drm.mdcf": {
"source": "iana"
},
"application/vnd.mason+json": {
"source": "iana",
"compressible": true
},
"application/vnd.maxmind.maxmind-db": {
"source": "iana"
},
"application/vnd.mcd": {
"source": "iana",
"extensions": ["mcd"]
},
"application/vnd.medcalcdata": {
"source": "iana",
"extensions": ["mc1"]
},
"application/vnd.mediastation.cdkey": {
"source": "iana",
"extensions": ["cdkey"]
},
"application/vnd.meridian-slingshot": {
"source": "iana"
},
"application/vnd.mfer": {
"source": "iana",
"extensions": ["mwf"]
},
"application/vnd.mfmp": {
"source": "iana",
"extensions": ["mfm"]
},
"application/vnd.micrografx.flo": {
"source": "iana",
"extensions": ["flo"]
},
"application/vnd.micrografx.igx": {
"source": "iana",
"extensions": ["igx"]
},
"application/vnd.miele+json": {
"source": "iana",
"compressible": true
},
"application/vnd.mif": {
"source": "iana",
"extensions": ["mif"]
},
"application/vnd.minisoft-hp3000-save": {
"source": "iana"
},
"application/vnd.mitsubishi.misty-guard.trustweb": {
"source": "iana"
},
"application/vnd.mobius.daf": {
"source": "iana",
"extensions": ["daf"]
},
"application/vnd.mobius.dis": {
"source": "iana",
"extensions": ["dis"]
},
"application/vnd.mobius.mbk": {
"source": "iana",
"extensions": ["mbk"]
},
"application/vnd.mobius.mqy": {
"source": "iana",
"extensions": ["mqy"]
},
"application/vnd.mobius.msl": {
"source": "iana",
"extensions": ["msl"]
},
"application/vnd.mobius.plc": {
"source": "iana",
"extensions": ["plc"]
},
"application/vnd.mobius.txf": {
"source": "iana",
"extensions": ["txf"]
},
"application/vnd.mophun.application": {
"source": "iana",
"extensions": ["mpn"]
},
"application/vnd.mophun.certificate": {
"source": "iana",
"extensions": ["mpc"]
},
"application/vnd.motorola.flexsuite": {
"source": "iana"
},
"application/vnd.motorola.flexsuite.adsi": {
"source": "iana"
},
"application/vnd.motorola.flexsuite.fis": {
"source": "iana"
},
"application/vnd.motorola.flexsuite.gotap": {
"source": "iana"
},
"application/vnd.motorola.flexsuite.kmr": {
"source": "iana"
},
"application/vnd.motorola.flexsuite.ttc": {
"source": "iana"
},
"application/vnd.motorola.flexsuite.wem": {
"source": "iana"
},
"application/vnd.motorola.iprm": {
"source": "iana"
},
"application/vnd.mozilla.xul+xml": {
"source": "iana",
"compressible": true,
"extensions": ["xul"]
},
"application/vnd.ms-3mfdocument": {
"source": "iana"
},
"application/vnd.ms-artgalry": {
"source": "iana",
"extensions": ["cil"]
},
"application/vnd.ms-asf": {
"source": "iana"
},
"application/vnd.ms-cab-compressed": {
"source": "iana",
"extensions": ["cab"]
},
"application/vnd.ms-color.iccprofile": {
"source": "apache"
},
"application/vnd.ms-excel": {
"source": "iana",
"compressible": false,
"extensions": ["xls","xlm","xla","xlc","xlt","xlw"]
},
"application/vnd.ms-excel.addin.macroenabled.12": {
"source": "iana",
"extensions": ["xlam"]
},
"application/vnd.ms-excel.sheet.binary.macroenabled.12": {
"source": "iana",
"extensions": ["xlsb"]
},
"application/vnd.ms-excel.sheet.macroenabled.12": {
"source": "iana",
"extensions": ["xlsm"]
},
"application/vnd.ms-excel.template.macroenabled.12": {
"source": "iana",
"extensions": ["xltm"]
},
"application/vnd.ms-fontobject": {
"source": "iana",
"compressible": true,
"extensions": ["eot"]
},
"application/vnd.ms-htmlhelp": {
"source": "iana",
"extensions": ["chm"]
},
"application/vnd.ms-ims": {
"source": "iana",
"extensions": ["ims"]
},
"application/vnd.ms-lrm": {
"source": "iana",
"extensions": ["lrm"]
},
"application/vnd.ms-office.activex+xml": {
"source": "iana"
},
"application/vnd.ms-officetheme": {
"source": "iana",
"extensions": ["thmx"]
},
"application/vnd.ms-opentype": {
"source": "apache",
"compressible": true
},
"application/vnd.ms-package.obfuscated-opentype": {
"source": "apache"
},
"application/vnd.ms-pki.seccat": {
"source": "apache",
"extensions": ["cat"]
},
"application/vnd.ms-pki.stl": {
"source": "apache",
"extensions": ["stl"]
},
"application/vnd.ms-playready.initiator+xml": {
"source": "iana"
},
"application/vnd.ms-powerpoint": {
"source": "iana",
"compressible": false,
"extensions": ["ppt","pps","pot"]
},
"application/vnd.ms-powerpoint.addin.macroenabled.12": {
"source": "iana",
"extensions": ["ppam"]
},
"application/vnd.ms-powerpoint.presentation.macroenabled.12": {
"source": "iana",
"extensions": ["pptm"]
},
"application/vnd.ms-powerpoint.slide.macroenabled.12": {
"source": "iana",
"extensions": ["sldm"]
},
"application/vnd.ms-powerpoint.slideshow.macroenabled.12": {
"source": "iana",
"extensions": ["ppsm"]
},
"application/vnd.ms-powerpoint.template.macroenabled.12": {
"source": "iana",
"extensions": ["potm"]
},
"application/vnd.ms-printing.printticket+xml": {
"source": "apache"
},
"application/vnd.ms-project": {
"source": "iana",
"extensions": ["mpp","mpt"]
},
"application/vnd.ms-tnef": {
"source": "iana"
},
"application/vnd.ms-windows.printerpairing": {
"source": "iana"
},
"application/vnd.ms-wmdrm.lic-chlg-req": {
"source": "iana"
},
"application/vnd.ms-wmdrm.lic-resp": {
"source": "iana"
},
"application/vnd.ms-wmdrm.meter-chlg-req": {
"source": "iana"
},
"application/vnd.ms-wmdrm.meter-resp": {
"source": "iana"
},
"application/vnd.ms-word.document.macroenabled.12": {
"source": "iana",
"extensions": ["docm"]
},
"application/vnd.ms-word.template.macroenabled.12": {
"source": "iana",
"extensions": ["dotm"]
},
"application/vnd.ms-works": {
"source": "iana",
"extensions": ["wps","wks","wcm","wdb"]
},
"application/vnd.ms-wpl": {
"source": "iana",
"extensions": ["wpl"]
},
"application/vnd.ms-xpsdocument": {
"source": "iana",
"compressible": false,
"extensions": ["xps"]
},
"application/vnd.msa-disk-image": {
"source": "iana"
},
"application/vnd.mseq": {
"source": "iana",
"extensions": ["mseq"]
},
"application/vnd.msign": {
"source": "iana"
},
"application/vnd.multiad.creator": {
"source": "iana"
},
"application/vnd.multiad.creator.cif": {
"source": "iana"
},
"application/vnd.music-niff": {
"source": "iana"
},
"application/vnd.musician": {
"source": "iana",
"extensions": ["mus"]
},
"application/vnd.muvee.style": {
"source": "iana",
"extensions": ["msty"]
},
"application/vnd.mynfc": {
"source": "iana",
"extensions": ["taglet"]
},
"application/vnd.ncd.control": {
"source": "iana"
},
"application/vnd.ncd.reference": {
"source": "iana"
},
"application/vnd.nervana": {
"source": "iana"
},
"application/vnd.netfpx": {
"source": "iana"
},
"application/vnd.neurolanguage.nlu": {
"source": "iana",
"extensions": ["nlu"]
},
"application/vnd.nintendo.nitro.rom": {
"source": "iana"
},
"application/vnd.nintendo.snes.rom": {
"source": "iana"
},
"application/vnd.nitf": {
"source": "iana",
"extensions": ["ntf","nitf"]
},
"application/vnd.noblenet-directory": {
"source": "iana",
"extensions": ["nnd"]
},
"application/vnd.noblenet-sealer": {
"source": "iana",
"extensions": ["nns"]
},
"application/vnd.noblenet-web": {
"source": "iana",
"extensions": ["nnw"]
},
"application/vnd.nokia.catalogs": {
"source": "iana"
},
"application/vnd.nokia.conml+wbxml": {
"source": "iana"
},
"application/vnd.nokia.conml+xml": {
"source": "iana"
},
"application/vnd.nokia.iptv.config+xml": {
"source": "iana"
},
"application/vnd.nokia.isds-radio-presets": {
"source": "iana"
},
"application/vnd.nokia.landmark+wbxml": {
"source": "iana"
},
"application/vnd.nokia.landmark+xml": {
"source": "iana"
},
"application/vnd.nokia.landmarkcollection+xml": {
"source": "iana"
},
"application/vnd.nokia.n-gage.ac+xml": {
"source": "iana"
},
"application/vnd.nokia.n-gage.data": {
"source": "iana",
"extensions": ["ngdat"]
},
"application/vnd.nokia.n-gage.symbian.install": {
"source": "iana"
},
"application/vnd.nokia.ncd": {
"source": "iana"
},
"application/vnd.nokia.pcd+wbxml": {
"source": "iana"
},
"application/vnd.nokia.pcd+xml": {
"source": "iana"
},
"application/vnd.nokia.radio-preset": {
"source": "iana",
"extensions": ["rpst"]
},
"application/vnd.nokia.radio-presets": {
"source": "iana",
"extensions": ["rpss"]
},
"application/vnd.novadigm.edm": {
"source": "iana",
"extensions": ["edm"]
},
"application/vnd.novadigm.edx": {
"source": "iana",
"extensions": ["edx"]
},
"application/vnd.novadigm.ext": {
"source": "iana",
"extensions": ["ext"]
},
"application/vnd.ntt-local.content-share": {
"source": "iana"
},
"application/vnd.ntt-local.file-transfer": {
"source": "iana"
},
"application/vnd.ntt-local.ogw_remote-access": {
"source": "iana"
},
"application/vnd.ntt-local.sip-ta_remote": {
"source": "iana"
},
"application/vnd.ntt-local.sip-ta_tcp_stream": {
"source": "iana"
},
"application/vnd.oasis.opendocument.chart": {
"source": "iana",
"extensions": ["odc"]
},
"application/vnd.oasis.opendocument.chart-template": {
"source": "iana",
"extensions": ["otc"]
},
"application/vnd.oasis.opendocument.database": {
"source": "iana",
"extensions": ["odb"]
},
"application/vnd.oasis.opendocument.formula": {
"source": "iana",
"extensions": ["odf"]
},
"application/vnd.oasis.opendocument.formula-template": {
"source": "iana",
"extensions": ["odft"]
},
"application/vnd.oasis.opendocument.graphics": {
"source": "iana",
"compressible": false,
"extensions": ["odg"]
},
"application/vnd.oasis.opendocument.graphics-template": {
"source": "iana",
"extensions": ["otg"]
},
"application/vnd.oasis.opendocument.image": {
"source": "iana",
"extensions": ["odi"]
},
"application/vnd.oasis.opendocument.image-template": {
"source": "iana",
"extensions": ["oti"]
},
"application/vnd.oasis.opendocument.presentation": {
"source": "iana",
"compressible": false,
"extensions": ["odp"]
},
"application/vnd.oasis.opendocument.presentation-template": {
"source": "iana",
"extensions": ["otp"]
},
"application/vnd.oasis.opendocument.spreadsheet": {
"source": "iana",
"compressible": false,
"extensions": ["ods"]
},
"application/vnd.oasis.opendocument.spreadsheet-template": {
"source": "iana",
"extensions": ["ots"]
},
"application/vnd.oasis.opendocument.text": {
"source": "iana",
"compressible": false,
"extensions": ["odt"]
},
"application/vnd.oasis.opendocument.text-master": {
"source": "iana",
"extensions": ["odm"]
},
"application/vnd.oasis.opendocument.text-template": {
"source": "iana",
"extensions": ["ott"]
},
"application/vnd.oasis.opendocument.text-web": {
"source": "iana",
"extensions": ["oth"]
},
"application/vnd.obn": {
"source": "iana"
},
"application/vnd.oftn.l10n+json": {
"source": "iana",
"compressible": true
},
"application/vnd.oipf.contentaccessdownload+xml": {
"source": "iana"
},
"application/vnd.oipf.contentaccessstreaming+xml": {
"source": "iana"
},
"application/vnd.oipf.cspg-hexbinary": {
"source": "iana"
},
"application/vnd.oipf.dae.svg+xml": {
"source": "iana"
},
"application/vnd.oipf.dae.xhtml+xml": {
"source": "iana"
},
"application/vnd.oipf.mippvcontrolmessage+xml": {
"source": "iana"
},
"application/vnd.oipf.pae.gem": {
"source": "iana"
},
"application/vnd.oipf.spdiscovery+xml": {
"source": "iana"
},
"application/vnd.oipf.spdlist+xml": {
"source": "iana"
},
"application/vnd.oipf.ueprofile+xml": {
"source": "iana"
},
"application/vnd.oipf.userprofile+xml": {
"source": "iana"
},
"application/vnd.olpc-sugar": {
"source": "iana",
"extensions": ["xo"]
},
"application/vnd.oma-scws-config": {
"source": "iana"
},
"application/vnd.oma-scws-http-request": {
"source": "iana"
},
"application/vnd.oma-scws-http-response": {
"source": "iana"
},
"application/vnd.oma.bcast.associated-procedure-parameter+xml": {
"source": "iana"
},
"application/vnd.oma.bcast.drm-trigger+xml": {
"source": "iana"
},
"application/vnd.oma.bcast.imd+xml": {
"source": "iana"
},
"application/vnd.oma.bcast.ltkm": {
"source": "iana"
},
"application/vnd.oma.bcast.notification+xml": {
"source": "iana"
},
"application/vnd.oma.bcast.provisioningtrigger": {
"source": "iana"
},
"application/vnd.oma.bcast.sgboot": {
"source": "iana"
},
"application/vnd.oma.bcast.sgdd+xml": {
"source": "iana"
},
"application/vnd.oma.bcast.sgdu": {
"source": "iana"
},
"application/vnd.oma.bcast.simple-symbol-container": {
"source": "iana"
},
"application/vnd.oma.bcast.smartcard-trigger+xml": {
"source": "iana"
},
"application/vnd.oma.bcast.sprov+xml": {
"source": "iana"
},
"application/vnd.oma.bcast.stkm": {
"source": "iana"
},
"application/vnd.oma.cab-address-book+xml": {
"source": "iana"
},
"application/vnd.oma.cab-feature-handler+xml": {
"source": "iana"
},
"application/vnd.oma.cab-pcc+xml": {
"source": "iana"
},
"application/vnd.oma.cab-subs-invite+xml": {
"source": "iana"
},
"application/vnd.oma.cab-user-prefs+xml": {
"source": "iana"
},
"application/vnd.oma.dcd": {
"source": "iana"
},
"application/vnd.oma.dcdc": {
"source": "iana"
},
"application/vnd.oma.dd2+xml": {
"source": "iana",
"extensions": ["dd2"]
},
"application/vnd.oma.drm.risd+xml": {
"source": "iana"
},
"application/vnd.oma.group-usage-list+xml": {
"source": "iana"
},
"application/vnd.oma.pal+xml": {
"source": "iana"
},
"application/vnd.oma.poc.detailed-progress-report+xml": {
"source": "iana"
},
"application/vnd.oma.poc.final-report+xml": {
"source": "iana"
},
"application/vnd.oma.poc.groups+xml": {
"source": "iana"
},
"application/vnd.oma.poc.invocation-descriptor+xml": {
"source": "iana"
},
"application/vnd.oma.poc.optimized-progress-report+xml": {
"source": "iana"
},
"application/vnd.oma.push": {
"source": "iana"
},
"application/vnd.oma.scidm.messages+xml": {
"source": "iana"
},
"application/vnd.oma.xcap-directory+xml": {
"source": "iana"
},
"application/vnd.omads-email+xml": {
"source": "iana"
},
"application/vnd.omads-file+xml": {
"source": "iana"
},
"application/vnd.omads-folder+xml": {
"source": "iana"
},
"application/vnd.omaloc-supl-init": {
"source": "iana"
},
"application/vnd.openeye.oeb": {
"source": "iana"
},
"application/vnd.openofficeorg.extension": {
"source": "apache",
"extensions": ["oxt"]
},
"application/vnd.openxmlformats-officedocument.custom-properties+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.customxmlproperties+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.drawing+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.drawingml.chart+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.drawingml.chartshapes+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.drawingml.diagramcolors+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.drawingml.diagramdata+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.drawingml.diagramlayout+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.drawingml.diagramstyle+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.extended-properties+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.presentationml-template": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.presentationml.commentauthors+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.presentationml.comments+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.presentationml.handoutmaster+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.presentationml.notesmaster+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.presentationml.notesslide+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.presentationml.presentation": {
"source": "iana",
"compressible": false,
"extensions": ["pptx"]
},
"application/vnd.openxmlformats-officedocument.presentationml.presentation.main+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.presentationml.presprops+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.presentationml.slide": {
"source": "iana",
"extensions": ["sldx"]
},
"application/vnd.openxmlformats-officedocument.presentationml.slide+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.presentationml.slidelayout+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.presentationml.slidemaster+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.presentationml.slideshow": {
"source": "iana",
"extensions": ["ppsx"]
},
"application/vnd.openxmlformats-officedocument.presentationml.slideshow.main+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.presentationml.slideupdateinfo+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.presentationml.tablestyles+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.presentationml.tags+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.presentationml.template": {
"source": "apache",
"extensions": ["potx"]
},
"application/vnd.openxmlformats-officedocument.presentationml.template.main+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.presentationml.viewprops+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.spreadsheetml-template": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.calcchain+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.chartsheet+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.comments+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.connections+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.dialogsheet+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.externallink+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.pivotcachedefinition+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.pivotcacherecords+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.pivottable+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.querytable+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.revisionheaders+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.revisionlog+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.sharedstrings+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": {
"source": "iana",
"compressible": false,
"extensions": ["xlsx"]
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheetmetadata+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.table+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.tablesinglecells+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.template": {
"source": "apache",
"extensions": ["xltx"]
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.template.main+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.usernames+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.volatiledependencies+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.theme+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.themeoverride+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.vmldrawing": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.wordprocessingml-template": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": {
"source": "iana",
"compressible": false,
"extensions": ["docx"]
},
"application/vnd.openxmlformats-officedocument.wordprocessingml.document.glossary+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.wordprocessingml.endnotes+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.wordprocessingml.fonttable+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.wordprocessingml.footnotes+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.wordprocessingml.template": {
"source": "apache",
"extensions": ["dotx"]
},
"application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-officedocument.wordprocessingml.websettings+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-package.core-properties+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-package.digital-signature-xmlsignature+xml": {
"source": "iana"
},
"application/vnd.openxmlformats-package.relationships+xml": {
"source": "iana"
},
"application/vnd.oracle.resource+json": {
"source": "iana",
"compressible": true
},
"application/vnd.orange.indata": {
"source": "iana"
},
"application/vnd.osa.netdeploy": {
"source": "iana"
},
"application/vnd.osgeo.mapguide.package": {
"source": "iana",
"extensions": ["mgp"]
},
"application/vnd.osgi.bundle": {
"source": "iana"
},
"application/vnd.osgi.dp": {
"source": "iana",
"extensions": ["dp"]
},
"application/vnd.osgi.subsystem": {
"source": "iana",
"extensions": ["esa"]
},
"application/vnd.otps.ct-kip+xml": {
"source": "iana"
},
"application/vnd.palm": {
"source": "iana",
"extensions": ["pdb","pqa","oprc"]
},
"application/vnd.panoply": {
"source": "iana"
},
"application/vnd.paos+xml": {
"source": "iana"
},
"application/vnd.paos.xml": {
"source": "apache"
},
"application/vnd.pawaafile": {
"source": "iana",
"extensions": ["paw"]
},
"application/vnd.pcos": {
"source": "iana"
},
"application/vnd.pg.format": {
"source": "iana",
"extensions": ["str"]
},
"application/vnd.pg.osasli": {
"source": "iana",
"extensions": ["ei6"]
},
"application/vnd.piaccess.application-licence": {
"source": "iana"
},
"application/vnd.picsel": {
"source": "iana",
"extensions": ["efif"]
},
"application/vnd.pmi.widget": {
"source": "iana",
"extensions": ["wg"]
},
"application/vnd.poc.group-advertisement+xml": {
"source": "iana"
},
"application/vnd.pocketlearn": {
"source": "iana",
"extensions": ["plf"]
},
"application/vnd.powerbuilder6": {
"source": "iana",
"extensions": ["pbd"]
},
"application/vnd.powerbuilder6-s": {
"source": "iana"
},
"application/vnd.powerbuilder7": {
"source": "iana"
},
"application/vnd.powerbuilder7-s": {
"source": "iana"
},
"application/vnd.powerbuilder75": {
"source": "iana"
},
"application/vnd.powerbuilder75-s": {
"source": "iana"
},
"application/vnd.preminet": {
"source": "iana"
},
"application/vnd.previewsystems.box": {
"source": "iana",
"extensions": ["box"]
},
"application/vnd.proteus.magazine": {
"source": "iana",
"extensions": ["mgz"]
},
"application/vnd.publishare-delta-tree": {
"source": "iana",
"extensions": ["qps"]
},
"application/vnd.pvi.ptid1": {
"source": "iana",
"extensions": ["ptid"]
},
"application/vnd.pwg-multiplexed": {
"source": "iana"
},
"application/vnd.pwg-xhtml-print+xml": {
"source": "iana"
},
"application/vnd.qualcomm.brew-app-res": {
"source": "iana"
},
"application/vnd.quark.quarkxpress": {
"source": "iana",
"extensions": ["qxd","qxt","qwd","qwt","qxl","qxb"]
},
"application/vnd.quobject-quoxdocument": {
"source": "iana"
},
"application/vnd.radisys.moml+xml": {
"source": "iana"
},
"application/vnd.radisys.msml+xml": {
"source": "iana"
},
"application/vnd.radisys.msml-audit+xml": {
"source": "iana"
},
"application/vnd.radisys.msml-audit-conf+xml": {
"source": "iana"
},
"application/vnd.radisys.msml-audit-conn+xml": {
"source": "iana"
},
"application/vnd.radisys.msml-audit-dialog+xml": {
"source": "iana"
},
"application/vnd.radisys.msml-audit-stream+xml": {
"source": "iana"
},
"application/vnd.radisys.msml-conf+xml": {
"source": "iana"
},
"application/vnd.radisys.msml-dialog+xml": {
"source": "iana"
},
"application/vnd.radisys.msml-dialog-base+xml": {
"source": "iana"
},
"application/vnd.radisys.msml-dialog-fax-detect+xml": {
"source": "iana"
},
"application/vnd.radisys.msml-dialog-fax-sendrecv+xml": {
"source": "iana"
},
"application/vnd.radisys.msml-dialog-group+xml": {
"source": "iana"
},
"application/vnd.radisys.msml-dialog-speech+xml": {
"source": "iana"
},
"application/vnd.radisys.msml-dialog-transform+xml": {
"source": "iana"
},
"application/vnd.rainstor.data": {
"source": "iana"
},
"application/vnd.rapid": {
"source": "iana"
},
"application/vnd.realvnc.bed": {
"source": "iana",
"extensions": ["bed"]
},
"application/vnd.recordare.musicxml": {
"source": "iana",
"extensions": ["mxl"]
},
"application/vnd.recordare.musicxml+xml": {
"source": "iana",
"extensions": ["musicxml"]
},
"application/vnd.renlearn.rlprint": {
"source": "iana"
},
"application/vnd.rig.cryptonote": {
"source": "iana",
"extensions": ["cryptonote"]
},
"application/vnd.rim.cod": {
"source": "apache",
"extensions": ["cod"]
},
"application/vnd.rn-realmedia": {
"source": "apache",
"extensions": ["rm"]
},
"application/vnd.rn-realmedia-vbr": {
"source": "apache",
"extensions": ["rmvb"]
},
"application/vnd.route66.link66+xml": {
"source": "iana",
"extensions": ["link66"]
},
"application/vnd.rs-274x": {
"source": "iana"
},
"application/vnd.ruckus.download": {
"source": "iana"
},
"application/vnd.s3sms": {
"source": "iana"
},
"application/vnd.sailingtracker.track": {
"source": "iana",
"extensions": ["st"]
},
"application/vnd.sbm.cid": {
"source": "iana"
},
"application/vnd.sbm.mid2": {
"source": "iana"
},
"application/vnd.scribus": {
"source": "iana"
},
"application/vnd.sealed.3df": {
"source": "iana"
},
"application/vnd.sealed.csf": {
"source": "iana"
},
"application/vnd.sealed.doc": {
"source": "iana"
},
"application/vnd.sealed.eml": {
"source": "iana"
},
"application/vnd.sealed.mht": {
"source": "iana"
},
"application/vnd.sealed.net": {
"source": "iana"
},
"application/vnd.sealed.ppt": {
"source": "iana"
},
"application/vnd.sealed.tiff": {
"source": "iana"
},
"application/vnd.sealed.xls": {
"source": "iana"
},
"application/vnd.sealedmedia.softseal.html": {
"source": "iana"
},
"application/vnd.sealedmedia.softseal.pdf": {
"source": "iana"
},
"application/vnd.seemail": {
"source": "iana",
"extensions": ["see"]
},
"application/vnd.sema": {
"source": "iana",
"extensions": ["sema"]
},
"application/vnd.semd": {
"source": "iana",
"extensions": ["semd"]
},
"application/vnd.semf": {
"source": "iana",
"extensions": ["semf"]
},
"application/vnd.shana.informed.formdata": {
"source": "iana",
"extensions": ["ifm"]
},
"application/vnd.shana.informed.formtemplate": {
"source": "iana",
"extensions": ["itp"]
},
"application/vnd.shana.informed.interchange": {
"source": "iana",
"extensions": ["iif"]
},
"application/vnd.shana.informed.package": {
"source": "iana",
"extensions": ["ipk"]
},
"application/vnd.simtech-mindmapper": {
"source": "iana",
"extensions": ["twd","twds"]
},
"application/vnd.siren+json": {
"source": "iana",
"compressible": true
},
"application/vnd.smaf": {
"source": "iana",
"extensions": ["mmf"]
},
"application/vnd.smart.notebook": {
"source": "iana"
},
"application/vnd.smart.teacher": {
"source": "iana",
"extensions": ["teacher"]
},
"application/vnd.software602.filler.form+xml": {
"source": "iana"
},
"application/vnd.software602.filler.form-xml-zip": {
"source": "iana"
},
"application/vnd.solent.sdkm+xml": {
"source": "iana",
"extensions": ["sdkm","sdkd"]
},
"application/vnd.spotfire.dxp": {
"source": "iana",
"extensions": ["dxp"]
},
"application/vnd.spotfire.sfs": {
"source": "iana",
"extensions": ["sfs"]
},
"application/vnd.sss-cod": {
"source": "iana"
},
"application/vnd.sss-dtf": {
"source": "iana"
},
"application/vnd.sss-ntf": {
"source": "iana"
},
"application/vnd.stardivision.calc": {
"source": "apache",
"extensions": ["sdc"]
},
"application/vnd.stardivision.draw": {
"source": "apache",
"extensions": ["sda"]
},
"application/vnd.stardivision.impress": {
"source": "apache",
"extensions": ["sdd"]
},
"application/vnd.stardivision.math": {
"source": "apache",
"extensions": ["smf"]
},
"application/vnd.stardivision.writer": {
"source": "apache",
"extensions": ["sdw","vor"]
},
"application/vnd.stardivision.writer-global": {
"source": "apache",
"extensions": ["sgl"]
},
"application/vnd.stepmania.package": {
"source": "iana",
"extensions": ["smzip"]
},
"application/vnd.stepmania.stepchart": {
"source": "iana",
"extensions": ["sm"]
},
"application/vnd.street-stream": {
"source": "iana"
},
"application/vnd.sun.wadl+xml": {
"source": "iana"
},
"application/vnd.sun.xml.calc": {
"source": "apache",
"extensions": ["sxc"]
},
"application/vnd.sun.xml.calc.template": {
"source": "apache",
"extensions": ["stc"]
},
"application/vnd.sun.xml.draw": {
"source": "apache",
"extensions": ["sxd"]
},
"application/vnd.sun.xml.draw.template": {
"source": "apache",
"extensions": ["std"]
},
"application/vnd.sun.xml.impress": {
"source": "apache",
"extensions": ["sxi"]
},
"application/vnd.sun.xml.impress.template": {
"source": "apache",
"extensions": ["sti"]
},
"application/vnd.sun.xml.math": {
"source": "apache",
"extensions": ["sxm"]
},
"application/vnd.sun.xml.writer": {
"source": "apache",
"extensions": ["sxw"]
},
"application/vnd.sun.xml.writer.global": {
"source": "apache",
"extensions": ["sxg"]
},
"application/vnd.sun.xml.writer.template": {
"source": "apache",
"extensions": ["stw"]
},
"application/vnd.sus-calendar": {
"source": "iana",
"extensions": ["sus","susp"]
},
"application/vnd.svd": {
"source": "iana",
"extensions": ["svd"]
},
"application/vnd.swiftview-ics": {
"source": "iana"
},
"application/vnd.symbian.install": {
"source": "apache",
"extensions": ["sis","sisx"]
},
"application/vnd.syncml+xml": {
"source": "iana",
"extensions": ["xsm"]
},
"application/vnd.syncml.dm+wbxml": {
"source": "iana",
"extensions": ["bdm"]
},
"application/vnd.syncml.dm+xml": {
"source": "iana",
"extensions": ["xdm"]
},
"application/vnd.syncml.dm.notification": {
"source": "iana"
},
"application/vnd.syncml.dmddf+wbxml": {
"source": "iana"
},
"application/vnd.syncml.dmddf+xml": {
"source": "iana"
},
"application/vnd.syncml.dmtnds+wbxml": {
"source": "iana"
},
"application/vnd.syncml.dmtnds+xml": {
"source": "iana"
},
"application/vnd.syncml.ds.notification": {
"source": "iana"
},
"application/vnd.tao.intent-module-archive": {
"source": "iana",
"extensions": ["tao"]
},
"application/vnd.tcpdump.pcap": {
"source": "iana",
"extensions": ["pcap","cap","dmp"]
},
"application/vnd.tmd.mediaflex.api+xml": {
"source": "iana"
},
"application/vnd.tmobile-livetv": {
"source": "iana",
"extensions": ["tmo"]
},
"application/vnd.trid.tpt": {
"source": "iana",
"extensions": ["tpt"]
},
"application/vnd.triscape.mxs": {
"source": "iana",
"extensions": ["mxs"]
},
"application/vnd.trueapp": {
"source": "iana",
"extensions": ["tra"]
},
"application/vnd.truedoc": {
"source": "iana"
},
"application/vnd.ubisoft.webplayer": {
"source": "iana"
},
"application/vnd.ufdl": {
"source": "iana",
"extensions": ["ufd","ufdl"]
},
"application/vnd.uiq.theme": {
"source": "iana",
"extensions": ["utz"]
},
"application/vnd.umajin": {
"source": "iana",
"extensions": ["umj"]
},
"application/vnd.unity": {
"source": "iana",
"extensions": ["unityweb"]
},
"application/vnd.uoml+xml": {
"source": "iana",
"extensions": ["uoml"]
},
"application/vnd.uplanet.alert": {
"source": "iana"
},
"application/vnd.uplanet.alert-wbxml": {
"source": "iana"
},
"application/vnd.uplanet.bearer-choice": {
"source": "iana"
},
"application/vnd.uplanet.bearer-choice-wbxml": {
"source": "iana"
},
"application/vnd.uplanet.cacheop": {
"source": "iana"
},
"application/vnd.uplanet.cacheop-wbxml": {
"source": "iana"
},
"application/vnd.uplanet.channel": {
"source": "iana"
},
"application/vnd.uplanet.channel-wbxml": {
"source": "iana"
},
"application/vnd.uplanet.list": {
"source": "iana"
},
"application/vnd.uplanet.list-wbxml": {
"source": "iana"
},
"application/vnd.uplanet.listcmd": {
"source": "iana"
},
"application/vnd.uplanet.listcmd-wbxml": {
"source": "iana"
},
"application/vnd.uplanet.signal": {
"source": "iana"
},
"application/vnd.valve.source.material": {
"source": "iana"
},
"application/vnd.vcx": {
"source": "iana",
"extensions": ["vcx"]
},
"application/vnd.vd-study": {
"source": "iana"
},
"application/vnd.vectorworks": {
"source": "iana"
},
"application/vnd.verimatrix.vcas": {
"source": "iana"
},
"application/vnd.vidsoft.vidconference": {
"source": "iana"
},
"application/vnd.visio": {
"source": "iana",
"extensions": ["vsd","vst","vss","vsw"]
},
"application/vnd.visionary": {
"source": "iana",
"extensions": ["vis"]
},
"application/vnd.vividence.scriptfile": {
"source": "iana"
},
"application/vnd.vsf": {
"source": "iana",
"extensions": ["vsf"]
},
"application/vnd.wap.sic": {
"source": "iana"
},
"application/vnd.wap.slc": {
"source": "iana"
},
"application/vnd.wap.wbxml": {
"source": "iana",
"extensions": ["wbxml"]
},
"application/vnd.wap.wmlc": {
"source": "iana",
"extensions": ["wmlc"]
},
"application/vnd.wap.wmlscriptc": {
"source": "iana",
"extensions": ["wmlsc"]
},
"application/vnd.webturbo": {
"source": "iana",
"extensions": ["wtb"]
},
"application/vnd.wfa.p2p": {
"source": "iana"
},
"application/vnd.wfa.wsc": {
"source": "iana"
},
"application/vnd.windows.devicepairing": {
"source": "iana"
},
"application/vnd.wmc": {
"source": "iana"
},
"application/vnd.wmf.bootstrap": {
"source": "iana"
},
"application/vnd.wolfram.mathematica": {
"source": "iana"
},
"application/vnd.wolfram.mathematica.package": {
"source": "iana"
},
"application/vnd.wolfram.player": {
"source": "iana",
"extensions": ["nbp"]
},
"application/vnd.wordperfect": {
"source": "iana",
"extensions": ["wpd"]
},
"application/vnd.wqd": {
"source": "iana",
"extensions": ["wqd"]
},
"application/vnd.wrq-hp3000-labelled": {
"source": "iana"
},
"application/vnd.wt.stf": {
"source": "iana",
"extensions": ["stf"]
},
"application/vnd.wv.csp+wbxml": {
"source": "iana"
},
"application/vnd.wv.csp+xml": {
"source": "iana"
},
"application/vnd.wv.ssp+xml": {
"source": "iana"
},
"application/vnd.xacml+json": {
"source": "iana",
"compressible": true
},
"application/vnd.xara": {
"source": "iana",
"extensions": ["xar"]
},
"application/vnd.xfdl": {
"source": "iana",
"extensions": ["xfdl"]
},
"application/vnd.xfdl.webform": {
"source": "iana"
},
"application/vnd.xmi+xml": {
"source": "iana"
},
"application/vnd.xmpie.cpkg": {
"source": "iana"
},
"application/vnd.xmpie.dpkg": {
"source": "iana"
},
"application/vnd.xmpie.plan": {
"source": "iana"
},
"application/vnd.xmpie.ppkg": {
"source": "iana"
},
"application/vnd.xmpie.xlim": {
"source": "iana"
},
"application/vnd.yamaha.hv-dic": {
"source": "iana",
"extensions": ["hvd"]
},
"application/vnd.yamaha.hv-script": {
"source": "iana",
"extensions": ["hvs"]
},
"application/vnd.yamaha.hv-voice": {
"source": "iana",
"extensions": ["hvp"]
},
"application/vnd.yamaha.openscoreformat": {
"source": "iana",
"extensions": ["osf"]
},
"application/vnd.yamaha.openscoreformat.osfpvg+xml": {
"source": "iana",
"extensions": ["osfpvg"]
},
"application/vnd.yamaha.remote-setup": {
"source": "iana"
},
"application/vnd.yamaha.smaf-audio": {
"source": "iana",
"extensions": ["saf"]
},
"application/vnd.yamaha.smaf-phrase": {
"source": "iana",
"extensions": ["spf"]
},
"application/vnd.yamaha.through-ngn": {
"source": "iana"
},
"application/vnd.yamaha.tunnel-udpencap": {
"source": "iana"
},
"application/vnd.yaoweme": {
"source": "iana"
},
"application/vnd.yellowriver-custom-menu": {
"source": "iana",
"extensions": ["cmp"]
},
"application/vnd.zul": {
"source": "iana",
"extensions": ["zir","zirz"]
},
"application/vnd.zzazz.deck+xml": {
"source": "iana",
"extensions": ["zaz"]
},
"application/voicexml+xml": {
"source": "iana",
"extensions": ["vxml"]
},
"application/vq-rtcpxr": {
"source": "iana"
},
"application/watcherinfo+xml": {
"source": "iana"
},
"application/whoispp-query": {
"source": "iana"
},
"application/whoispp-response": {
"source": "iana"
},
"application/widget": {
"source": "iana",
"extensions": ["wgt"]
},
"application/winhlp": {
"source": "apache",
"extensions": ["hlp"]
},
"application/wita": {
"source": "iana"
},
"application/wordperfect5.1": {
"source": "iana"
},
"application/wsdl+xml": {
"source": "iana",
"extensions": ["wsdl"]
},
"application/wspolicy+xml": {
"source": "iana",
"extensions": ["wspolicy"]
},
"application/x-7z-compressed": {
"source": "apache",
"compressible": false,
"extensions": ["7z"]
},
"application/x-abiword": {
"source": "apache",
"extensions": ["abw"]
},
"application/x-ace-compressed": {
"source": "apache",
"extensions": ["ace"]
},
"application/x-amf": {
"source": "apache"
},
"application/x-apple-diskimage": {
"source": "apache",
"extensions": ["dmg"]
},
"application/x-authorware-bin": {
"source": "apache",
"extensions": ["aab","x32","u32","vox"]
},
"application/x-authorware-map": {
"source": "apache",
"extensions": ["aam"]
},
"application/x-authorware-seg": {
"source": "apache",
"extensions": ["aas"]
},
"application/x-bcpio": {
"source": "apache",
"extensions": ["bcpio"]
},
"application/x-bittorrent": {
"source": "apache",
"extensions": ["torrent"]
},
"application/x-blorb": {
"source": "apache",
"extensions": ["blb","blorb"]
},
"application/x-bzip": {
"source": "apache",
"compressible": false,
"extensions": ["bz"]
},
"application/x-bzip2": {
"source": "apache",
"compressible": false,
"extensions": ["bz2","boz"]
},
"application/x-cbr": {
"source": "apache",
"extensions": ["cbr","cba","cbt","cbz","cb7"]
},
"application/x-cdlink": {
"source": "apache",
"extensions": ["vcd"]
},
"application/x-cfs-compressed": {
"source": "apache",
"extensions": ["cfs"]
},
"application/x-chat": {
"source": "apache",
"extensions": ["chat"]
},
"application/x-chess-pgn": {
"source": "apache",
"extensions": ["pgn"]
},
"application/x-chrome-extension": {
"extensions": ["crx"]
},
"application/x-compress": {
"source": "apache"
},
"application/x-conference": {
"source": "apache",
"extensions": ["nsc"]
},
"application/x-cpio": {
"source": "apache",
"extensions": ["cpio"]
},
"application/x-csh": {
"source": "apache",
"extensions": ["csh"]
},
"application/x-deb": {
"compressible": false
},
"application/x-debian-package": {
"source": "apache",
"extensions": ["deb","udeb"]
},
"application/x-dgc-compressed": {
"source": "apache",
"extensions": ["dgc"]
},
"application/x-director": {
"source": "apache",
"extensions": ["dir","dcr","dxr","cst","cct","cxt","w3d","fgd","swa"]
},
"application/x-doom": {
"source": "apache",
"extensions": ["wad"]
},
"application/x-dtbncx+xml": {
"source": "apache",
"extensions": ["ncx"]
},
"application/x-dtbook+xml": {
"source": "apache",
"extensions": ["dtb"]
},
"application/x-dtbresource+xml": {
"source": "apache",
"extensions": ["res"]
},
"application/x-dvi": {
"source": "apache",
"compressible": false,
"extensions": ["dvi"]
},
"application/x-envoy": {
"source": "apache",
"extensions": ["evy"]
},
"application/x-eva": {
"source": "apache",
"extensions": ["eva"]
},
"application/x-font-bdf": {
"source": "apache",
"extensions": ["bdf"]
},
"application/x-font-dos": {
"source": "apache"
},
"application/x-font-framemaker": {
"source": "apache"
},
"application/x-font-ghostscript": {
"source": "apache",
"extensions": ["gsf"]
},
"application/x-font-libgrx": {
"source": "apache"
},
"application/x-font-linux-psf": {
"source": "apache",
"extensions": ["psf"]
},
"application/x-font-otf": {
"source": "apache",
"compressible": true,
"extensions": ["otf"]
},
"application/x-font-pcf": {
"source": "apache",
"extensions": ["pcf"]
},
"application/x-font-snf": {
"source": "apache",
"extensions": ["snf"]
},
"application/x-font-speedo": {
"source": "apache"
},
"application/x-font-sunos-news": {
"source": "apache"
},
"application/x-font-ttf": {
"source": "apache",
"compressible": true,
"extensions": ["ttf","ttc"]
},
"application/x-font-type1": {
"source": "apache",
"extensions": ["pfa","pfb","pfm","afm"]
},
"application/x-font-vfont": {
"source": "apache"
},
"application/x-freearc": {
"source": "apache",
"extensions": ["arc"]
},
"application/x-futuresplash": {
"source": "apache",
"extensions": ["spl"]
},
"application/x-gca-compressed": {
"source": "apache",
"extensions": ["gca"]
},
"application/x-glulx": {
"source": "apache",
"extensions": ["ulx"]
},
"application/x-gnumeric": {
"source": "apache",
"extensions": ["gnumeric"]
},
"application/x-gramps-xml": {
"source": "apache",
"extensions": ["gramps"]
},
"application/x-gtar": {
"source": "apache",
"extensions": ["gtar"]
},
"application/x-gzip": {
"source": "apache"
},
"application/x-hdf": {
"source": "apache",
"extensions": ["hdf"]
},
"application/x-install-instructions": {
"source": "apache",
"extensions": ["install"]
},
"application/x-iso9660-image": {
"source": "apache",
"extensions": ["iso"]
},
"application/x-java-jnlp-file": {
"source": "apache",
"compressible": false,
"extensions": ["jnlp"]
},
"application/x-javascript": {
"compressible": true
},
"application/x-latex": {
"source": "apache",
"compressible": false,
"extensions": ["latex"]
},
"application/x-lua-bytecode": {
"extensions": ["luac"]
},
"application/x-lzh-compressed": {
"source": "apache",
"extensions": ["lzh","lha"]
},
"application/x-mie": {
"source": "apache",
"extensions": ["mie"]
},
"application/x-mobipocket-ebook": {
"source": "apache",
"extensions": ["prc","mobi"]
},
"application/x-mpegurl": {
"compressible": false
},
"application/x-ms-application": {
"source": "apache",
"extensions": ["application"]
},
"application/x-ms-shortcut": {
"source": "apache",
"extensions": ["lnk"]
},
"application/x-ms-wmd": {
"source": "apache",
"extensions": ["wmd"]
},
"application/x-ms-wmz": {
"source": "apache",
"extensions": ["wmz"]
},
"application/x-ms-xbap": {
"source": "apache",
"extensions": ["xbap"]
},
"application/x-msaccess": {
"source": "apache",
"extensions": ["mdb"]
},
"application/x-msbinder": {
"source": "apache",
"extensions": ["obd"]
},
"application/x-mscardfile": {
"source": "apache",
"extensions": ["crd"]
},
"application/x-msclip": {
"source": "apache",
"extensions": ["clp"]
},
"application/x-msdownload": {
"source": "apache",
"extensions": ["exe","dll","com","bat","msi"]
},
"application/x-msmediaview": {
"source": "apache",
"extensions": ["mvb","m13","m14"]
},
"application/x-msmetafile": {
"source": "apache",
"extensions": ["wmf","wmz","emf","emz"]
},
"application/x-msmoney": {
"source": "apache",
"extensions": ["mny"]
},
"application/x-mspublisher": {
"source": "apache",
"extensions": ["pub"]
},
"application/x-msschedule": {
"source": "apache",
"extensions": ["scd"]
},
"application/x-msterminal": {
"source": "apache",
"extensions": ["trm"]
},
"application/x-mswrite": {
"source": "apache",
"extensions": ["wri"]
},
"application/x-netcdf": {
"source": "apache",
"extensions": ["nc","cdf"]
},
"application/x-nzb": {
"source": "apache",
"extensions": ["nzb"]
},
"application/x-pkcs12": {
"source": "apache",
"compressible": false,
"extensions": ["p12","pfx"]
},
"application/x-pkcs7-certificates": {
"source": "apache",
"extensions": ["p7b","spc"]
},
"application/x-pkcs7-certreqresp": {
"source": "apache",
"extensions": ["p7r"]
},
"application/x-rar-compressed": {
"source": "apache",
"compressible": false,
"extensions": ["rar"]
},
"application/x-research-info-systems": {
"source": "apache",
"extensions": ["ris"]
},
"application/x-sh": {
"source": "apache",
"compressible": true,
"extensions": ["sh"]
},
"application/x-shar": {
"source": "apache",
"extensions": ["shar"]
},
"application/x-shockwave-flash": {
"source": "apache",
"compressible": false,
"extensions": ["swf"]
},
"application/x-silverlight-app": {
"source": "apache",
"extensions": ["xap"]
},
"application/x-sql": {
"source": "apache",
"extensions": ["sql"]
},
"application/x-stuffit": {
"source": "apache",
"compressible": false,
"extensions": ["sit"]
},
"application/x-stuffitx": {
"source": "apache",
"extensions": ["sitx"]
},
"application/x-subrip": {
"source": "apache",
"extensions": ["srt"]
},
"application/x-sv4cpio": {
"source": "apache",
"extensions": ["sv4cpio"]
},
"application/x-sv4crc": {
"source": "apache",
"extensions": ["sv4crc"]
},
"application/x-t3vm-image": {
"source": "apache",
"extensions": ["t3"]
},
"application/x-tads": {
"source": "apache",
"extensions": ["gam"]
},
"application/x-tar": {
"source": "apache",
"compressible": true,
"extensions": ["tar"]
},
"application/x-tcl": {
"source": "apache",
"extensions": ["tcl"]
},
"application/x-tex": {
"source": "apache",
"extensions": ["tex"]
},
"application/x-tex-tfm": {
"source": "apache",
"extensions": ["tfm"]
},
"application/x-texinfo": {
"source": "apache",
"extensions": ["texinfo","texi"]
},
"application/x-tgif": {
"source": "apache",
"extensions": ["obj"]
},
"application/x-ustar": {
"source": "apache",
"extensions": ["ustar"]
},
"application/x-wais-source": {
"source": "apache",
"extensions": ["src"]
},
"application/x-web-app-manifest+json": {
"compressible": true,
"extensions": ["webapp"]
},
"application/x-www-form-urlencoded": {
"source": "iana",
"compressible": true
},
"application/x-x509-ca-cert": {
"source": "apache",
"extensions": ["der","crt"]
},
"application/x-xfig": {
"source": "apache",
"extensions": ["fig"]
},
"application/x-xliff+xml": {
"source": "apache",
"extensions": ["xlf"]
},
"application/x-xpinstall": {
"source": "apache",
"compressible": false,
"extensions": ["xpi"]
},
"application/x-xz": {
"source": "apache",
"extensions": ["xz"]
},
"application/x-zmachine": {
"source": "apache",
"extensions": ["z1","z2","z3","z4","z5","z6","z7","z8"]
},
"application/x400-bp": {
"source": "iana"
},
"application/xacml+xml": {
"source": "iana"
},
"application/xaml+xml": {
"source": "apache",
"extensions": ["xaml"]
},
"application/xcap-att+xml": {
"source": "iana"
},
"application/xcap-caps+xml": {
"source": "iana"
},
"application/xcap-diff+xml": {
"source": "iana",
"extensions": ["xdf"]
},
"application/xcap-el+xml": {
"source": "iana"
},
"application/xcap-error+xml": {
"source": "iana"
},
"application/xcap-ns+xml": {
"source": "iana"
},
"application/xcon-conference-info+xml": {
"source": "iana"
},
"application/xcon-conference-info-diff+xml": {
"source": "iana"
},
"application/xenc+xml": {
"source": "iana",
"extensions": ["xenc"]
},
"application/xhtml+xml": {
"source": "iana",
"compressible": true,
"extensions": ["xhtml","xht"]
},
"application/xhtml-voice+xml": {
"source": "iana"
},
"application/xml": {
"source": "iana",
"compressible": true,
"extensions": ["xml","xsl","xsd"]
},
"application/xml-dtd": {
"source": "iana",
"compressible": true,
"extensions": ["dtd"]
},
"application/xml-external-parsed-entity": {
"source": "iana"
},
"application/xml-patch+xml": {
"source": "iana"
},
"application/xmpp+xml": {
"source": "iana"
},
"application/xop+xml": {
"source": "iana",
"compressible": true,
"extensions": ["xop"]
},
"application/xproc+xml": {
"source": "apache",
"extensions": ["xpl"]
},
"application/xslt+xml": {
"source": "iana",
"extensions": ["xslt"]
},
"application/xspf+xml": {
"source": "apache",
"extensions": ["xspf"]
},
"application/xv+xml": {
"source": "iana",
"extensions": ["mxml","xhvml","xvml","xvm"]
},
"application/yang": {
"source": "iana",
"extensions": ["yang"]
},
"application/yin+xml": {
"source": "iana",
"extensions": ["yin"]
},
"application/zip": {
"source": "iana",
"compressible": false,
"extensions": ["zip"]
},
"application/zlib": {
"source": "iana"
},
"audio/1d-interleaved-parityfec": {
"source": "iana"
},
"audio/32kadpcm": {
"source": "iana"
},
"audio/3gpp": {
"source": "iana"
},
"audio/3gpp2": {
"source": "iana"
},
"audio/ac3": {
"source": "iana"
},
"audio/adpcm": {
"source": "apache",
"extensions": ["adp"]
},
"audio/amr": {
"source": "iana"
},
"audio/amr-wb": {
"source": "iana"
},
"audio/amr-wb+": {
"source": "iana"
},
"audio/aptx": {
"source": "iana"
},
"audio/asc": {
"source": "iana"
},
"audio/atrac-advanced-lossless": {
"source": "iana"
},
"audio/atrac-x": {
"source": "iana"
},
"audio/atrac3": {
"source": "iana"
},
"audio/basic": {
"source": "iana",
"compressible": false,
"extensions": ["au","snd"]
},
"audio/bv16": {
"source": "iana"
},
"audio/bv32": {
"source": "iana"
},
"audio/clearmode": {
"source": "iana"
},
"audio/cn": {
"source": "iana"
},
"audio/dat12": {
"source": "iana"
},
"audio/dls": {
"source": "iana"
},
"audio/dsr-es201108": {
"source": "iana"
},
"audio/dsr-es202050": {
"source": "iana"
},
"audio/dsr-es202211": {
"source": "iana"
},
"audio/dsr-es202212": {
"source": "iana"
},
"audio/dv": {
"source": "iana"
},
"audio/dvi4": {
"source": "iana"
},
"audio/eac3": {
"source": "iana"
},
"audio/encaprtp": {
"source": "iana"
},
"audio/evrc": {
"source": "iana"
},
"audio/evrc-qcp": {
"source": "iana"
},
"audio/evrc0": {
"source": "iana"
},
"audio/evrc1": {
"source": "iana"
},
"audio/evrcb": {
"source": "iana"
},
"audio/evrcb0": {
"source": "iana"
},
"audio/evrcb1": {
"source": "iana"
},
"audio/evrcnw": {
"source": "iana"
},
"audio/evrcnw0": {
"source": "iana"
},
"audio/evrcnw1": {
"source": "iana"
},
"audio/evrcwb": {
"source": "iana"
},
"audio/evrcwb0": {
"source": "iana"
},
"audio/evrcwb1": {
"source": "iana"
},
"audio/fwdred": {
"source": "iana"
},
"audio/g719": {
"source": "iana"
},
"audio/g722": {
"source": "iana"
},
"audio/g7221": {
"source": "iana"
},
"audio/g723": {
"source": "iana"
},
"audio/g726-16": {
"source": "iana"
},
"audio/g726-24": {
"source": "iana"
},
"audio/g726-32": {
"source": "iana"
},
"audio/g726-40": {
"source": "iana"
},
"audio/g728": {
"source": "iana"
},
"audio/g729": {
"source": "iana"
},
"audio/g7291": {
"source": "iana"
},
"audio/g729d": {
"source": "iana"
},
"audio/g729e": {
"source": "iana"
},
"audio/gsm": {
"source": "iana"
},
"audio/gsm-efr": {
"source": "iana"
},
"audio/gsm-hr-08": {
"source": "iana"
},
"audio/ilbc": {
"source": "iana"
},
"audio/ip-mr_v2.5": {
"source": "iana"
},
"audio/isac": {
"source": "apache"
},
"audio/l16": {
"source": "iana"
},
"audio/l20": {
"source": "iana"
},
"audio/l24": {
"source": "iana",
"compressible": false
},
"audio/l8": {
"source": "iana"
},
"audio/lpc": {
"source": "iana"
},
"audio/midi": {
"source": "apache",
"extensions": ["mid","midi","kar","rmi"]
},
"audio/mobile-xmf": {
"source": "iana"
},
"audio/mp4": {
"source": "iana",
"compressible": false,
"extensions": ["mp4a","m4a"]
},
"audio/mp4a-latm": {
"source": "iana"
},
"audio/mpa": {
"source": "iana"
},
"audio/mpa-robust": {
"source": "iana"
},
"audio/mpeg": {
"source": "iana",
"compressible": false,
"extensions": ["mpga","mp2","mp2a","mp3","m2a","m3a"]
},
"audio/mpeg4-generic": {
"source": "iana"
},
"audio/musepack": {
"source": "apache"
},
"audio/ogg": {
"source": "iana",
"compressible": false,
"extensions": ["oga","ogg","spx"]
},
"audio/opus": {
"source": "apache"
},
"audio/parityfec": {
"source": "iana"
},
"audio/pcma": {
"source": "iana"
},
"audio/pcma-wb": {
"source": "iana"
},
"audio/pcmu": {
"source": "iana"
},
"audio/pcmu-wb": {
"source": "iana"
},
"audio/prs.sid": {
"source": "iana"
},
"audio/qcelp": {
"source": "iana"
},
"audio/raptorfec": {
"source": "iana"
},
"audio/red": {
"source": "iana"
},
"audio/rtp-enc-aescm128": {
"source": "iana"
},
"audio/rtp-midi": {
"source": "iana"
},
"audio/rtploopback": {
"source": "iana"
},
"audio/rtx": {
"source": "iana"
},
"audio/s3m": {
"source": "apache",
"extensions": ["s3m"]
},
"audio/silk": {
"source": "apache",
"extensions": ["sil"]
},
"audio/smv": {
"source": "iana"
},
"audio/smv-qcp": {
"source": "iana"
},
"audio/smv0": {
"source": "iana"
},
"audio/sp-midi": {
"source": "iana"
},
"audio/speex": {
"source": "iana"
},
"audio/t140c": {
"source": "iana"
},
"audio/t38": {
"source": "iana"
},
"audio/telephone-event": {
"source": "iana"
},
"audio/tone": {
"source": "iana"
},
"audio/uemclip": {
"source": "iana"
},
"audio/ulpfec": {
"source": "iana"
},
"audio/vdvi": {
"source": "iana"
},
"audio/vmr-wb": {
"source": "iana"
},
"audio/vnd.3gpp.iufp": {
"source": "iana"
},
"audio/vnd.4sb": {
"source": "iana"
},
"audio/vnd.audiokoz": {
"source": "iana"
},
"audio/vnd.celp": {
"source": "iana"
},
"audio/vnd.cisco.nse": {
"source": "iana"
},
"audio/vnd.cmles.radio-events": {
"source": "iana"
},
"audio/vnd.cns.anp1": {
"source": "iana"
},
"audio/vnd.cns.inf1": {
"source": "iana"
},
"audio/vnd.dece.audio": {
"source": "iana",
"extensions": ["uva","uvva"]
},
"audio/vnd.digital-winds": {
"source": "iana",
"extensions": ["eol"]
},
"audio/vnd.dlna.adts": {
"source": "iana"
},
"audio/vnd.dolby.heaac.1": {
"source": "iana"
},
"audio/vnd.dolby.heaac.2": {
"source": "iana"
},
"audio/vnd.dolby.mlp": {
"source": "iana"
},
"audio/vnd.dolby.mps": {
"source": "iana"
},
"audio/vnd.dolby.pl2": {
"source": "iana"
},
"audio/vnd.dolby.pl2x": {
"source": "iana"
},
"audio/vnd.dolby.pl2z": {
"source": "iana"
},
"audio/vnd.dolby.pulse.1": {
"source": "iana"
},
"audio/vnd.dra": {
"source": "iana",
"extensions": ["dra"]
},
"audio/vnd.dts": {
"source": "iana",
"extensions": ["dts"]
},
"audio/vnd.dts.hd": {
"source": "iana",
"extensions": ["dtshd"]
},
"audio/vnd.dvb.file": {
"source": "iana"
},
"audio/vnd.everad.plj": {
"source": "iana"
},
"audio/vnd.hns.audio": {
"source": "iana"
},
"audio/vnd.lucent.voice": {
"source": "iana",
"extensions": ["lvp"]
},
"audio/vnd.ms-playready.media.pya": {
"source": "iana",
"extensions": ["pya"]
},
"audio/vnd.nokia.mobile-xmf": {
"source": "iana"
},
"audio/vnd.nortel.vbk": {
"source": "iana"
},
"audio/vnd.nuera.ecelp4800": {
"source": "iana",
"extensions": ["ecelp4800"]
},
"audio/vnd.nuera.ecelp7470": {
"source": "iana",
"extensions": ["ecelp7470"]
},
"audio/vnd.nuera.ecelp9600": {
"source": "iana",
"extensions": ["ecelp9600"]
},
"audio/vnd.octel.sbc": {
"source": "iana"
},
"audio/vnd.qcelp": {
"source": "iana"
},
"audio/vnd.rhetorex.32kadpcm": {
"source": "iana"
},
"audio/vnd.rip": {
"source": "iana",
"extensions": ["rip"]
},
"audio/vnd.rn-realaudio": {
"compressible": false
},
"audio/vnd.sealedmedia.softseal.mpeg": {
"source": "iana"
},
"audio/vnd.vmx.cvsd": {
"source": "iana"
},
"audio/vnd.wave": {
"compressible": false
},
"audio/vorbis": {
"source": "iana",
"compressible": false
},
"audio/vorbis-config": {
"source": "iana"
},
"audio/webm": {
"source": "apache",
"compressible": false,
"extensions": ["weba"]
},
"audio/x-aac": {
"source": "apache",
"compressible": false,
"extensions": ["aac"]
},
"audio/x-aiff": {
"source": "apache",
"extensions": ["aif","aiff","aifc"]
},
"audio/x-caf": {
"source": "apache",
"compressible": false,
"extensions": ["caf"]
},
"audio/x-flac": {
"source": "apache",
"extensions": ["flac"]
},
"audio/x-matroska": {
"source": "apache",
"extensions": ["mka"]
},
"audio/x-mpegurl": {
"source": "apache",
"extensions": ["m3u"]
},
"audio/x-ms-wax": {
"source": "apache",
"extensions": ["wax"]
},
"audio/x-ms-wma": {
"source": "apache",
"extensions": ["wma"]
},
"audio/x-pn-realaudio": {
"source": "apache",
"extensions": ["ram","ra"]
},
"audio/x-pn-realaudio-plugin": {
"source": "apache",
"extensions": ["rmp"]
},
"audio/x-tta": {
"source": "apache"
},
"audio/x-wav": {
"source": "apache",
"extensions": ["wav"]
},
"audio/xm": {
"source": "apache",
"extensions": ["xm"]
},
"chemical/x-cdx": {
"source": "apache",
"extensions": ["cdx"]
},
"chemical/x-cif": {
"source": "apache",
"extensions": ["cif"]
},
"chemical/x-cmdf": {
"source": "apache",
"extensions": ["cmdf"]
},
"chemical/x-cml": {
"source": "apache",
"extensions": ["cml"]
},
"chemical/x-csml": {
"source": "apache",
"extensions": ["csml"]
},
"chemical/x-pdb": {
"source": "apache"
},
"chemical/x-xyz": {
"source": "apache",
"extensions": ["xyz"]
},
"font/opentype": {
"compressible": true,
"extensions": ["otf"]
},
"image/bmp": {
"source": "apache",
"compressible": true,
"extensions": ["bmp"]
},
"image/cgm": {
"source": "iana",
"extensions": ["cgm"]
},
"image/fits": {
"source": "iana"
},
"image/g3fax": {
"source": "iana",
"extensions": ["g3"]
},
"image/gif": {
"source": "iana",
"compressible": false,
"extensions": ["gif"]
},
"image/ief": {
"source": "iana",
"extensions": ["ief"]
},
"image/jp2": {
"source": "iana"
},
"image/jpeg": {
"source": "iana",
"compressible": false,
"extensions": ["jpeg","jpg","jpe"]
},
"image/jpm": {
"source": "iana"
},
"image/jpx": {
"source": "iana"
},
"image/ktx": {
"source": "iana",
"extensions": ["ktx"]
},
"image/naplps": {
"source": "iana"
},
"image/pjpeg": {
"compressible": false
},
"image/png": {
"source": "iana",
"compressible": false,
"extensions": ["png"]
},
"image/prs.btif": {
"source": "iana",
"extensions": ["btif"]
},
"image/prs.pti": {
"source": "iana"
},
"image/pwg-raster": {
"source": "iana"
},
"image/sgi": {
"source": "apache",
"extensions": ["sgi"]
},
"image/svg+xml": {
"source": "iana",
"compressible": true,
"extensions": ["svg","svgz"]
},
"image/t38": {
"source": "iana"
},
"image/tiff": {
"source": "iana",
"compressible": false,
"extensions": ["tiff","tif"]
},
"image/tiff-fx": {
"source": "iana"
},
"image/vnd.adobe.photoshop": {
"source": "iana",
"compressible": true,
"extensions": ["psd"]
},
"image/vnd.airzip.accelerator.azv": {
"source": "iana"
},
"image/vnd.cns.inf2": {
"source": "iana"
},
"image/vnd.dece.graphic": {
"source": "iana",
"extensions": ["uvi","uvvi","uvg","uvvg"]
},
"image/vnd.djvu": {
"source": "iana",
"extensions": ["djvu","djv"]
},
"image/vnd.dvb.subtitle": {
"source": "iana",
"extensions": ["sub"]
},
"image/vnd.dwg": {
"source": "iana",
"extensions": ["dwg"]
},
"image/vnd.dxf": {
"source": "iana",
"extensions": ["dxf"]
},
"image/vnd.fastbidsheet": {
"source": "iana",
"extensions": ["fbs"]
},
"image/vnd.fpx": {
"source": "iana",
"extensions": ["fpx"]
},
"image/vnd.fst": {
"source": "iana",
"extensions": ["fst"]
},
"image/vnd.fujixerox.edmics-mmr": {
"source": "iana",
"extensions": ["mmr"]
},
"image/vnd.fujixerox.edmics-rlc": {
"source": "iana",
"extensions": ["rlc"]
},
"image/vnd.globalgraphics.pgb": {
"source": "iana"
},
"image/vnd.microsoft.icon": {
"source": "iana"
},
"image/vnd.mix": {
"source": "iana"
},
"image/vnd.ms-modi": {
"source": "iana",
"extensions": ["mdi"]
},
"image/vnd.ms-photo": {
"source": "apache",
"extensions": ["wdp"]
},
"image/vnd.net-fpx": {
"source": "iana",
"extensions": ["npx"]
},
"image/vnd.radiance": {
"source": "iana"
},
"image/vnd.sealed.png": {
"source": "iana"
},
"image/vnd.sealedmedia.softseal.gif": {
"source": "iana"
},
"image/vnd.sealedmedia.softseal.jpg": {
"source": "iana"
},
"image/vnd.svf": {
"source": "iana"
},
"image/vnd.tencent.tap": {
"source": "iana"
},
"image/vnd.valve.source.texture": {
"source": "iana"
},
"image/vnd.wap.wbmp": {
"source": "iana",
"extensions": ["wbmp"]
},
"image/vnd.xiff": {
"source": "iana",
"extensions": ["xif"]
},
"image/webp": {
"source": "apache",
"extensions": ["webp"]
},
"image/x-3ds": {
"source": "apache",
"extensions": ["3ds"]
},
"image/x-cmu-raster": {
"source": "apache",
"extensions": ["ras"]
},
"image/x-cmx": {
"source": "apache",
"extensions": ["cmx"]
},
"image/x-freehand": {
"source": "apache",
"extensions": ["fh","fhc","fh4","fh5","fh7"]
},
"image/x-icon": {
"source": "apache",
"compressible": true,
"extensions": ["ico"]
},
"image/x-mrsid-image": {
"source": "apache",
"extensions": ["sid"]
},
"image/x-pcx": {
"source": "apache",
"extensions": ["pcx"]
},
"image/x-pict": {
"source": "apache",
"extensions": ["pic","pct"]
},
"image/x-portable-anymap": {
"source": "apache",
"extensions": ["pnm"]
},
"image/x-portable-bitmap": {
"source": "apache",
"extensions": ["pbm"]
},
"image/x-portable-graymap": {
"source": "apache",
"extensions": ["pgm"]
},
"image/x-portable-pixmap": {
"source": "apache",
"extensions": ["ppm"]
},
"image/x-rgb": {
"source": "apache",
"extensions": ["rgb"]
},
"image/x-tga": {
"source": "apache",
"extensions": ["tga"]
},
"image/x-xbitmap": {
"source": "apache",
"extensions": ["xbm"]
},
"image/x-xcf": {
"compressible": false
},
"image/x-xpixmap": {
"source": "apache",
"extensions": ["xpm"]
},
"image/x-xwindowdump": {
"source": "apache",
"extensions": ["xwd"]
},
"message/cpim": {
"source": "iana"
},
"message/delivery-status": {
"source": "iana"
},
"message/disposition-notification": {
"source": "iana"
},
"message/external-body": {
"source": "iana"
},
"message/feedback-report": {
"source": "iana"
},
"message/global": {
"source": "iana"
},
"message/global-delivery-status": {
"source": "iana"
},
"message/global-disposition-notification": {
"source": "iana"
},
"message/global-headers": {
"source": "iana"
},
"message/http": {
"source": "iana",
"compressible": false
},
"message/imdn+xml": {
"source": "iana",
"compressible": true
},
"message/news": {
"source": "iana"
},
"message/partial": {
"source": "iana",
"compressible": false
},
"message/rfc822": {
"source": "iana",
"compressible": true,
"extensions": ["eml","mime"]
},
"message/s-http": {
"source": "iana"
},
"message/sip": {
"source": "iana"
},
"message/sipfrag": {
"source": "iana"
},
"message/tracking-status": {
"source": "iana"
},
"message/vnd.si.simp": {
"source": "iana"
},
"message/vnd.wfa.wsc": {
"source": "iana"
},
"model/iges": {
"source": "iana",
"compressible": false,
"extensions": ["igs","iges"]
},
"model/mesh": {
"source": "iana",
"compressible": false,
"extensions": ["msh","mesh","silo"]
},
"model/vnd.collada+xml": {
"source": "iana",
"extensions": ["dae"]
},
"model/vnd.dwf": {
"source": "iana",
"extensions": ["dwf"]
},
"model/vnd.flatland.3dml": {
"source": "iana"
},
"model/vnd.gdl": {
"source": "iana",
"extensions": ["gdl"]
},
"model/vnd.gs-gdl": {
"source": "apache"
},
"model/vnd.gs.gdl": {
"source": "iana"
},
"model/vnd.gtw": {
"source": "iana",
"extensions": ["gtw"]
},
"model/vnd.moml+xml": {
"source": "iana"
},
"model/vnd.mts": {
"source": "iana",
"extensions": ["mts"]
},
"model/vnd.opengex": {
"source": "iana"
},
"model/vnd.parasolid.transmit.binary": {
"source": "iana"
},
"model/vnd.parasolid.transmit.text": {
"source": "iana"
},
"model/vnd.valve.source.compiled-map": {
"source": "iana"
},
"model/vnd.vtu": {
"source": "iana",
"extensions": ["vtu"]
},
"model/vrml": {
"source": "iana",
"compressible": false,
"extensions": ["wrl","vrml"]
},
"model/x3d+binary": {
"source": "apache",
"compressible": false,
"extensions": ["x3db","x3dbz"]
},
"model/x3d+fastinfoset": {
"source": "iana"
},
"model/x3d+vrml": {
"source": "apache",
"compressible": false,
"extensions": ["x3dv","x3dvz"]
},
"model/x3d+xml": {
"source": "iana",
"compressible": true,
"extensions": ["x3d","x3dz"]
},
"model/x3d-vrml": {
"source": "iana"
},
"multipart/alternative": {
"source": "iana",
"compressible": false
},
"multipart/appledouble": {
"source": "iana"
},
"multipart/byteranges": {
"source": "iana"
},
"multipart/digest": {
"source": "iana"
},
"multipart/encrypted": {
"source": "iana",
"compressible": false
},
"multipart/form-data": {
"source": "iana",
"compressible": false
},
"multipart/header-set": {
"source": "iana"
},
"multipart/mixed": {
"source": "iana",
"compressible": false
},
"multipart/parallel": {
"source": "iana"
},
"multipart/related": {
"source": "iana",
"compressible": false
},
"multipart/report": {
"source": "iana"
},
"multipart/signed": {
"source": "iana",
"compressible": false
},
"multipart/voice-message": {
"source": "iana"
},
"multipart/x-mixed-replace": {
"source": "iana"
},
"text/1d-interleaved-parityfec": {
"source": "iana"
},
"text/cache-manifest": {
"source": "iana",
"compressible": true,
"extensions": ["appcache","manifest"]
},
"text/calendar": {
"source": "iana",
"extensions": ["ics","ifb"]
},
"text/calender": {
"compressible": true
},
"text/cmd": {
"compressible": true
},
"text/coffeescript": {
"extensions": ["coffee"]
},
"text/css": {
"source": "iana",
"compressible": true,
"extensions": ["css"]
},
"text/csv": {
"source": "iana",
"compressible": true,
"extensions": ["csv"]
},
"text/csv-schema": {
"source": "iana"
},
"text/directory": {
"source": "iana"
},
"text/dns": {
"source": "iana"
},
"text/ecmascript": {
"source": "iana"
},
"text/encaprtp": {
"source": "iana"
},
"text/enriched": {
"source": "iana"
},
"text/fwdred": {
"source": "iana"
},
"text/grammar-ref-list": {
"source": "iana"
},
"text/hjson": {
"extensions": ["hjson"]
},
"text/html": {
"source": "iana",
"compressible": true,
"extensions": ["html","htm"]
},
"text/jade": {
"extensions": ["jade"]
},
"text/javascript": {
"source": "iana",
"compressible": true
},
"text/jcr-cnd": {
"source": "iana"
},
"text/jsx": {
"compressible": true,
"extensions": ["jsx"]
},
"text/less": {
"extensions": ["less"]
},
"text/markdown": {
"source": "iana"
},
"text/mizar": {
"source": "iana"
},
"text/n3": {
"source": "iana",
"compressible": true,
"extensions": ["n3"]
},
"text/parameters": {
"source": "iana"
},
"text/parityfec": {
"source": "iana"
},
"text/plain": {
"source": "iana",
"compressible": true,
"extensions": ["txt","text","conf","def","list","log","in","ini"]
},
"text/provenance-notation": {
"source": "iana"
},
"text/prs.fallenstein.rst": {
"source": "iana"
},
"text/prs.lines.tag": {
"source": "iana",
"extensions": ["dsc"]
},
"text/raptorfec": {
"source": "iana"
},
"text/red": {
"source": "iana"
},
"text/rfc822-headers": {
"source": "iana"
},
"text/richtext": {
"source": "iana",
"compressible": true,
"extensions": ["rtx"]
},
"text/rtf": {
"source": "iana"
},
"text/rtp-enc-aescm128": {
"source": "iana"
},
"text/rtploopback": {
"source": "iana"
},
"text/rtx": {
"source": "iana"
},
"text/sgml": {
"source": "iana",
"extensions": ["sgml","sgm"]
},
"text/stylus": {
"extensions": ["stylus","styl"]
},
"text/t140": {
"source": "iana"
},
"text/tab-separated-values": {
"source": "iana",
"compressible": true,
"extensions": ["tsv"]
},
"text/troff": {
"source": "iana",
"extensions": ["t","tr","roff","man","me","ms"]
},
"text/turtle": {
"source": "iana",
"extensions": ["ttl"]
},
"text/ulpfec": {
"source": "iana"
},
"text/uri-list": {
"source": "iana",
"compressible": true,
"extensions": ["uri","uris","urls"]
},
"text/vcard": {
"source": "iana",
"compressible": true,
"extensions": ["vcard"]
},
"text/vnd.a": {
"source": "iana"
},
"text/vnd.abc": {
"source": "iana"
},
"text/vnd.curl": {
"source": "iana",
"extensions": ["curl"]
},
"text/vnd.curl.dcurl": {
"source": "apache",
"extensions": ["dcurl"]
},
"text/vnd.curl.mcurl": {
"source": "apache",
"extensions": ["mcurl"]
},
"text/vnd.curl.scurl": {
"source": "apache",
"extensions": ["scurl"]
},
"text/vnd.debian.copyright": {
"source": "iana"
},
"text/vnd.dmclientscript": {
"source": "iana"
},
"text/vnd.dvb.subtitle": {
"source": "iana",
"extensions": ["sub"]
},
"text/vnd.esmertec.theme-descriptor": {
"source": "iana"
},
"text/vnd.fly": {
"source": "iana",
"extensions": ["fly"]
},
"text/vnd.fmi.flexstor": {
"source": "iana",
"extensions": ["flx"]
},
"text/vnd.graphviz": {
"source": "iana",
"extensions": ["gv"]
},
"text/vnd.in3d.3dml": {
"source": "iana",
"extensions": ["3dml"]
},
"text/vnd.in3d.spot": {
"source": "iana",
"extensions": ["spot"]
},
"text/vnd.iptc.newsml": {
"source": "iana"
},
"text/vnd.iptc.nitf": {
"source": "iana"
},
"text/vnd.latex-z": {
"source": "iana"
},
"text/vnd.motorola.reflex": {
"source": "iana"
},
"text/vnd.ms-mediapackage": {
"source": "iana"
},
"text/vnd.net2phone.commcenter.command": {
"source": "iana"
},
"text/vnd.radisys.msml-basic-layout": {
"source": "iana"
},
"text/vnd.si.uricatalogue": {
"source": "iana"
},
"text/vnd.sun.j2me.app-descriptor": {
"source": "iana",
"extensions": ["jad"]
},
"text/vnd.trolltech.linguist": {
"source": "iana"
},
"text/vnd.wap.si": {
"source": "iana"
},
"text/vnd.wap.sl": {
"source": "iana"
},
"text/vnd.wap.wml": {
"source": "iana",
"extensions": ["wml"]
},
"text/vnd.wap.wmlscript": {
"source": "iana",
"extensions": ["wmls"]
},
"text/vtt": {
"charset": "UTF-8",
"compressible": true,
"extensions": ["vtt"]
},
"text/x-asm": {
"source": "apache",
"extensions": ["s","asm"]
},
"text/x-c": {
"source": "apache",
"extensions": ["c","cc","cxx","cpp","h","hh","dic"]
},
"text/x-component": {
"extensions": ["htc"]
},
"text/x-fortran": {
"source": "apache",
"extensions": ["f","for","f77","f90"]
},
"text/x-gwt-rpc": {
"compressible": true
},
"text/x-handlebars-template": {
"extensions": ["hbs"]
},
"text/x-java-source": {
"source": "apache",
"extensions": ["java"]
},
"text/x-jquery-tmpl": {
"compressible": true
},
"text/x-lua": {
"extensions": ["lua"]
},
"text/x-markdown": {
"compressible": true,
"extensions": ["markdown","md","mkd"]
},
"text/x-nfo": {
"source": "apache",
"extensions": ["nfo"]
},
"text/x-opml": {
"source": "apache",
"extensions": ["opml"]
},
"text/x-pascal": {
"source": "apache",
"extensions": ["p","pas"]
},
"text/x-sass": {
"extensions": ["sass"]
},
"text/x-scss": {
"extensions": ["scss"]
},
"text/x-setext": {
"source": "apache",
"extensions": ["etx"]
},
"text/x-sfv": {
"source": "apache",
"extensions": ["sfv"]
},
"text/x-uuencode": {
"source": "apache",
"extensions": ["uu"]
},
"text/x-vcalendar": {
"source": "apache",
"extensions": ["vcs"]
},
"text/x-vcard": {
"source": "apache",
"extensions": ["vcf"]
},
"text/xml": {
"source": "iana",
"compressible": true
},
"text/xml-external-parsed-entity": {
"source": "iana"
},
"text/yaml": {
"extensions": ["yaml","yml"]
},
"video/1d-interleaved-parityfec": {
"source": "apache"
},
"video/3gpp": {
"source": "apache",
"extensions": ["3gp"]
},
"video/3gpp-tt": {
"source": "apache"
},
"video/3gpp2": {
"source": "apache",
"extensions": ["3g2"]
},
"video/bmpeg": {
"source": "apache"
},
"video/bt656": {
"source": "apache"
},
"video/celb": {
"source": "apache"
},
"video/dv": {
"source": "apache"
},
"video/h261": {
"source": "apache",
"extensions": ["h261"]
},
"video/h263": {
"source": "apache",
"extensions": ["h263"]
},
"video/h263-1998": {
"source": "apache"
},
"video/h263-2000": {
"source": "apache"
},
"video/h264": {
"source": "apache",
"extensions": ["h264"]
},
"video/h264-rcdo": {
"source": "apache"
},
"video/h264-svc": {
"source": "apache"
},
"video/jpeg": {
"source": "apache",
"extensions": ["jpgv"]
},
"video/jpeg2000": {
"source": "apache"
},
"video/jpm": {
"source": "apache",
"extensions": ["jpm","jpgm"]
},
"video/mj2": {
"source": "apache",
"extensions": ["mj2","mjp2"]
},
"video/mp1s": {
"source": "apache"
},
"video/mp2p": {
"source": "apache"
},
"video/mp2t": {
"source": "apache",
"extensions": ["ts"]
},
"video/mp4": {
"source": "apache",
"compressible": false,
"extensions": ["mp4","mp4v","mpg4"]
},
"video/mp4v-es": {
"source": "apache"
},
"video/mpeg": {
"source": "apache",
"compressible": false,
"extensions": ["mpeg","mpg","mpe","m1v","m2v"]
},
"video/mpeg4-generic": {
"source": "apache"
},
"video/mpv": {
"source": "apache"
},
"video/nv": {
"source": "apache"
},
"video/ogg": {
"source": "apache",
"compressible": false,
"extensions": ["ogv"]
},
"video/parityfec": {
"source": "apache"
},
"video/pointer": {
"source": "apache"
},
"video/quicktime": {
"source": "apache",
"compressible": false,
"extensions": ["qt","mov"]
},
"video/raw": {
"source": "apache"
},
"video/rtp-enc-aescm128": {
"source": "apache"
},
"video/rtx": {
"source": "apache"
},
"video/smpte292m": {
"source": "apache"
},
"video/ulpfec": {
"source": "apache"
},
"video/vc1": {
"source": "apache"
},
"video/vnd.cctv": {
"source": "apache"
},
"video/vnd.dece.hd": {
"source": "apache",
"extensions": ["uvh","uvvh"]
},
"video/vnd.dece.mobile": {
"source": "apache",
"extensions": ["uvm","uvvm"]
},
"video/vnd.dece.mp4": {
"source": "apache"
},
"video/vnd.dece.pd": {
"source": "apache",
"extensions": ["uvp","uvvp"]
},
"video/vnd.dece.sd": {
"source": "apache",
"extensions": ["uvs","uvvs"]
},
"video/vnd.dece.video": {
"source": "apache",
"extensions": ["uvv","uvvv"]
},
"video/vnd.directv.mpeg": {
"source": "apache"
},
"video/vnd.directv.mpeg-tts": {
"source": "apache"
},
"video/vnd.dlna.mpeg-tts": {
"source": "apache"
},
"video/vnd.dvb.file": {
"source": "apache",
"extensions": ["dvb"]
},
"video/vnd.fvt": {
"source": "apache",
"extensions": ["fvt"]
},
"video/vnd.hns.video": {
"source": "apache"
},
"video/vnd.iptvforum.1dparityfec-1010": {
"source": "apache"
},
"video/vnd.iptvforum.1dparityfec-2005": {
"source": "apache"
},
"video/vnd.iptvforum.2dparityfec-1010": {
"source": "apache"
},
"video/vnd.iptvforum.2dparityfec-2005": {
"source": "apache"
},
"video/vnd.iptvforum.ttsavc": {
"source": "apache"
},
"video/vnd.iptvforum.ttsmpeg2": {
"source": "apache"
},
"video/vnd.motorola.video": {
"source": "apache"
},
"video/vnd.motorola.videop": {
"source": "apache"
},
"video/vnd.mpegurl": {
"source": "apache",
"extensions": ["mxu","m4u"]
},
"video/vnd.ms-playready.media.pyv": {
"source": "apache",
"extensions": ["pyv"]
},
"video/vnd.nokia.interleaved-multimedia": {
"source": "apache"
},
"video/vnd.nokia.videovoip": {
"source": "apache"
},
"video/vnd.objectvideo": {
"source": "apache"
},
"video/vnd.sealed.mpeg1": {
"source": "apache"
},
"video/vnd.sealed.mpeg4": {
"source": "apache"
},
"video/vnd.sealed.swf": {
"source": "apache"
},
"video/vnd.sealedmedia.softseal.mov": {
"source": "apache"
},
"video/vnd.uvvu.mp4": {
"source": "apache",
"extensions": ["uvu","uvvu"]
},
"video/vnd.vivo": {
"source": "apache",
"extensions": ["viv"]
},
"video/webm": {
"source": "apache",
"compressible": false,
"extensions": ["webm"]
},
"video/x-f4v": {
"source": "apache",
"extensions": ["f4v"]
},
"video/x-fli": {
"source": "apache",
"extensions": ["fli"]
},
"video/x-flv": {
"source": "apache",
"compressible": false,
"extensions": ["flv"]
},
"video/x-m4v": {
"source": "apache",
"extensions": ["m4v"]
},
"video/x-matroska": {
"source": "apache",
"compressible": false,
"extensions": ["mkv","mk3d","mks"]
},
"video/x-mng": {
"source": "apache",
"extensions": ["mng"]
},
"video/x-ms-asf": {
"source": "apache",
"extensions": ["asf","asx"]
},
"video/x-ms-vob": {
"source": "apache",
"extensions": ["vob"]
},
"video/x-ms-wm": {
"source": "apache",
"extensions": ["wm"]
},
"video/x-ms-wmv": {
"source": "apache",
"compressible": false,
"extensions": ["wmv"]
},
"video/x-ms-wmx": {
"source": "apache",
"extensions": ["wmx"]
},
"video/x-ms-wvx": {
"source": "apache",
"extensions": ["wvx"]
},
"video/x-msvideo": {
"source": "apache",
"extensions": ["avi"]
},
"video/x-sgi-movie": {
"source": "apache",
"extensions": ["movie"]
},
"video/x-smv": {
"source": "apache",
"extensions": ["smv"]
},
"x-conference/x-cooltalk": {
"source": "apache",
"extensions": ["ice"]
},
"x-shader/x-fragment": {
"compressible": true
},
"x-shader/x-vertex": {
"compressible": true
}
}

1.8.0 / 2015-03-13

  • Add application/vnd.citationstyles.style+xml
  • Add application/vnd.fastcopy-disk-image
  • Add application/vnd.gov.sk.xmldatacontainer+xml
  • Add extension .jsonld to application/ld+json

1.7.0 / 2015-02-08

  • Add application/vnd.gerber
  • Add application/vnd.msa-disk-image

1.6.1 / 2015-02-05

  • Community extensions ownership transferred from node-mime

1.6.0 / 2015-01-29

  • Add application/jose
  • Add application/jose+json
  • Add application/json-seq
  • Add application/jwk+json
  • Add application/jwk-set+json
  • Add application/jwt
  • Add application/rdap+json
  • Add application/vnd.gov.sk.e-form+xml
  • Add application/vnd.ims.imsccv1p3

1.5.0 / 2014-12-30

  • Add application/vnd.oracle.resource+json
  • Fix various invalid MIME type entries
    • application/mbox+xml
    • application/oscp-response
    • application/vwg-multiplexed
    • audio/g721

1.4.0 / 2014-12-21

  • Add application/vnd.ims.imsccv1p2
  • Fix various invalid MIME type entries
    • application/vnd-acucobol
    • application/vnd-curl
    • application/vnd-dart
    • application/vnd-dxr
    • application/vnd-fdf
    • application/vnd-mif
    • application/vnd-sema
    • application/vnd-wap-wmlc
    • application/vnd.adobe.flash-movie
    • application/vnd.dece-zip
    • application/vnd.dvb_service
    • application/vnd.micrografx-igx
    • application/vnd.sealed-doc
    • application/vnd.sealed-eml
    • application/vnd.sealed-mht
    • application/vnd.sealed-ppt
    • application/vnd.sealed-tiff
    • application/vnd.sealed-xls
    • application/vnd.sealedmedia.softseal-html
    • application/vnd.sealedmedia.softseal-pdf
    • application/vnd.wap-slc
    • application/vnd.wap-wbxml
    • audio/vnd.sealedmedia.softseal-mpeg
    • image/vnd-djvu
    • image/vnd-svf
    • image/vnd-wap-wbmp
    • image/vnd.sealed-png
    • image/vnd.sealedmedia.softseal-gif
    • image/vnd.sealedmedia.softseal-jpg
    • model/vnd-dwf
    • model/vnd.parasolid.transmit-binary
    • model/vnd.parasolid.transmit-text
    • text/vnd-a
    • text/vnd-curl
    • text/vnd.wap-wml
  • Remove example template MIME types
    • application/example
    • audio/example
    • image/example
    • message/example
    • model/example
    • multipart/example
    • text/example
    • video/example

1.3.1 / 2014-12-16

  • Fix missing extensions
    • application/json5
    • text/hjson

1.3.0 / 2014-12-07

  • Add application/a2l
  • Add application/aml
  • Add application/atfx
  • Add application/atxml
  • Add application/cdfx+xml
  • Add application/dii
  • Add application/json5
  • Add application/lxf
  • Add application/mf4
  • Add application/vnd.apache.thrift.compact
  • Add application/vnd.apache.thrift.json
  • Add application/vnd.coffeescript
  • Add application/vnd.enphase.envoy
  • Add application/vnd.ims.imsccv1p1
  • Add text/csv-schema
  • Add text/hjson
  • Add text/markdown
  • Add text/yaml

1.2.0 / 2014-11-09

  • Add application/cea
  • Add application/dit
  • Add application/vnd.gov.sk.e-form+zip
  • Add application/vnd.tmd.mediaflex.api+xml
  • Type application/epub+zip is now IANA-registered

1.1.2 / 2014-10-23

  • Rebuild database for application/x-www-form-urlencoded change

1.1.1 / 2014-10-20

  • Mark application/x-www-form-urlencoded as compressible.

1.1.0 / 2014-09-28

  • Add application/font-woff2

1.0.3 / 2014-09-25

  • Fix engine requirement in package

1.0.2 / 2014-09-25

  • Add application/coap-group+json
  • Add application/dcd
  • Add application/vnd.apache.thrift.binary
  • Add image/vnd.tencent.tap
  • Mark all JSON-derived types as compressible
  • Update text/vtt data

1.0.1 / 2014-08-30

  • Fix extension ordering

1.0.0 / 2014-08-30

  • Add application/atf
  • Add application/merge-patch+json
  • Add multipart/x-mixed-replace
  • Add source: 'apache' metadata
  • Add source: 'iana' metadata
  • Remove badly-assumed charset data
/*!
* mime-db
* Copyright(c) 2014 Jonathan Ong
* MIT Licensed
*/
/**
* Module exports.
*/
module.exports = require('./db.json')
The MIT License (MIT)
Copyright (c) 2014 Jonathan Ong me@jongleberry.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
{
"name": "mime-db",
"description": "Media Type Database",
"version": "1.8.0",
"contributors": [
{
"name": "Douglas Christopher Wilson",
"email": "doug@somethingdoug.com"
},
{
"name": "Jonathan Ong",
"email": "me@jongleberry.com",
"url": "http://jongleberry.com"
},
{
"name": "Robert Kieffer",
"email": "robert@broofa.com",
"url": "http://github.com/broofa"
}
],
"license": "MIT",
"keywords": [
"mime",
"db",
"type",
"types",
"database",
"charset",
"charsets"
],
"repository": {
"type": "git",
"url": "https://github.com/jshttp/mime-db"
},
"devDependencies": {
"bluebird": "~2.9.14",
"co": "~4.4.0",
"cogent": "1",
"csv-parse": "0.0.9",
"gnode": "0.1.1",
"istanbul": "0.3.7",
"mocha": "~1.21.4",
"raw-body": "~1.3.3",
"stream-to-array": "2"
},
"files": [
"HISTORY.md",
"LICENSE",
"README.md",
"db.json",
"index.js"
],
"engines": {
"node": ">= 0.6"
},
"scripts": {
"build": "node scripts/build",
"fetch": "gnode scripts/extensions && gnode scripts/types",
"test": "mocha --reporter spec --bail --check-leaks test/",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/",
"update": "npm run fetch && npm run build"
},
"gitHead": "cd5730a475ff03d2ef49fc571d5510a548b63494",
"bugs": {
"url": "https://github.com/jshttp/mime-db/issues"
},
"homepage": "https://github.com/jshttp/mime-db",
"_id": "mime-db@1.8.0",
"_shasum": "82a9b385f22b0f5954dec4d445faba0722c4ad25",
"_from": "mime-db@>=1.8.0 <1.9.0",
"_npmVersion": "1.4.28",
"_npmUser": {
"name": "dougwilson",
"email": "doug@somethingdoug.com"
},
"maintainers": [
{
"name": "jongleberry",
"email": "jonathanrichardong@gmail.com"
},
{
"name": "dougwilson",
"email": "doug@somethingdoug.com"
}
],
"dist": {
"shasum": "82a9b385f22b0f5954dec4d445faba0722c4ad25",
"tarball": "http://registry.npmjs.org/mime-db/-/mime-db-1.8.0.tgz"
},
"directories": {},
"_resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.8.0.tgz",
"readme": "ERROR: No README data found!"
}

mime-db

NPM Version NPM Downloads Node.js Version Build Status Coverage Status

This is a database of all mime types. It consists of a single, public JSON file and does not include any logic, allowing it to remain as un-opinionated as possible with an API. It aggregates data from the following sources:

Installation

npm install mime-db

If you're crazy enough to use this in the browser, you can just grab the JSON file:

https://cdn.rawgit.com/jshttp/mime-db/master/db.json

Usage

var db = require('mime-db');

// grab data on .js files
var data = db['application/javascript'];

Data Structure

The JSON file is a map lookup for lowercased mime types. Each mime type has the following properties:

  • .source - where the mime type is defined. If not set, it's probably a custom media type.
  • .extensions[] - known extensions associated with this mime type.
  • .compressible - whether a file of this type is can be gzipped.
  • .charset - the default charset associated with this type, if any.

If unknown, every property could be undefined.

Contributing

To edit the database, only make PRs against src/custom.json or src/custom-suffix.json.

To update the build, run npm run update.

Adding Custom Media Types

The best way to get new media types included in this library is to register them with the IANA. The community registration procedure is outlined in RFC 6838 section 5. Types registered with the IANA are automatically pulled into this library.

{
"name": "mime-types",
"description": "The ultimate javascript content-type utility.",
"version": "2.0.10",
"contributors": [
{
"name": "Douglas Christopher Wilson",
"email": "doug@somethingdoug.com"
},
{
"name": "Jeremiah Senkpiel",
"email": "fishrock123@rocketmail.com",
"url": "https://searchbeam.jit.su"
},
{
"name": "Jonathan Ong",
"email": "me@jongleberry.com",
"url": "http://jongleberry.com"
}
],
"license": "MIT",
"keywords": [
"mime",
"types"
],
"repository": {
"type": "git",
"url": "https://github.com/jshttp/mime-types"
},
"dependencies": {
"mime-db": "~1.8.0"
},
"devDependencies": {
"istanbul": "0.3.7",
"mocha": "~1.21.5"
},
"files": [
"HISTORY.md",
"LICENSE",
"index.js"
],
"engines": {
"node": ">= 0.6"
},
"scripts": {
"test": "mocha --reporter spec test/test.js",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot test/test.js",
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter dot test/test.js"
},
"gitHead": "9d4533a2b3a68af48a7f3ded9f8f525648e7bcc1",
"bugs": {
"url": "https://github.com/jshttp/mime-types/issues"
},
"homepage": "https://github.com/jshttp/mime-types",
"_id": "mime-types@2.0.10",
"_shasum": "eacd81bb73cab2a77447549a078d4f2018c67b4d",
"_from": "mime-types@>=2.0.10 <2.1.0",
"_npmVersion": "1.4.28",
"_npmUser": {
"name": "dougwilson",
"email": "doug@somethingdoug.com"
},
"maintainers": [
{
"name": "jongleberry",
"email": "jonathanrichardong@gmail.com"
},
{
"name": "fishrock123",
"email": "fishrock123@rocketmail.com"
},
{
"name": "dougwilson",
"email": "doug@somethingdoug.com"
}
],
"dist": {
"shasum": "eacd81bb73cab2a77447549a078d4f2018c67b4d",
"tarball": "http://registry.npmjs.org/mime-types/-/mime-types-2.0.10.tgz"
},
"directories": {},
"_resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.0.10.tgz",
"readme": "ERROR: No README data found!"
}

mime-types

NPM Version NPM Downloads Node.js Version Build Status Test Coverage

The ultimate javascript content-type utility.

Similar to node-mime, except:

  • No fallbacks. Instead of naively returning the first available type, mime-types simply returns false, so do var type = mime.lookup('unrecognized') || 'application/octet-stream'.
  • No new Mime() business, so you could do var lookup = require('mime-types').lookup.
  • Additional mime types are added such as jade and stylus via mime-db
  • No .define() functionality

Otherwise, the API is compatible.

Install

$ npm install mime-types

Adding Types

All mime types are based on mime-db, so open a PR there if you'd like to add mime types.

API

var mime = require('mime-types')

All functions return false if input is invalid or not found.

mime.lookup(path)

Lookup the content-type associated with a file.

mime.lookup('json')           // 'application/json'
mime.lookup('.md')            // 'text/x-markdown'
mime.lookup('file.html')      // 'text/html'
mime.lookup('folder/file.js') // 'application/javascript'

mime.lookup('cats') // false

mime.contentType(type)

Create a full content-type header given a content-type or extension.

mime.contentType('markdown')  // 'text/x-markdown; charset=utf-8'
mime.contentType('file.json') // 'application/json; charset=utf-8'

// from a full path
mime.contentType(path.extname('/path/to/file.json')) // 'application/json; charset=utf-8'

mime.extension(type)

Get the default extension for a content-type.

mime.extension('application/octet-stream') // 'bin'

mime.charset(type)

Lookup the implied default charset of a content-type.

mime.charset('text/x-markdown') // 'UTF-8'

var type = mime.types[extension]

A map of content-types by extension.

[extensions...] = mime.extensions[type]

A map of extensions by content-type.

License

MIT

0.5.1 / 2015-02-14

  • Fix preference sorting to be stable for long acceptable lists

0.5.0 / 2014-12-18

  • Fix list return order when large accepted list
  • Fix missing identity encoding when q=0 exists
  • Remove dynamic building of Negotiator class

0.4.9 / 2014-10-14

  • Fix error when media type has invalid parameter

0.4.8 / 2014-09-28

  • Fix all negotiations to be case-insensitive
  • Stable sort preferences of same quality according to client order
  • Support Node.js 0.6

0.4.7 / 2014-06-24

  • Handle invalid provided languages
  • Handle invalid provided media types

0.4.6 / 2014-06-11

  • Order by specificity when quality is the same

0.4.5 / 2014-05-29

  • Fix regression in empty header handling

0.4.4 / 2014-05-29

  • Fix behaviors when headers are not present

0.4.3 / 2014-04-16

  • Handle slashes on media params correctly

0.4.2 / 2014-02-28

  • Fix media type sorting
  • Handle media types params strictly

0.4.1 / 2014-01-16

  • Use most specific matches

0.4.0 / 2014-01-09

  • Remove preferred prefix from methods
var preferredCharsets = require('./lib/charset');
var preferredEncodings = require('./lib/encoding');
var preferredLanguages = require('./lib/language');
var preferredMediaTypes = require('./lib/mediaType');
module.exports = Negotiator;
Negotiator.Negotiator = Negotiator;
function Negotiator(request) {
if (!(this instanceof Negotiator)) {
return new Negotiator(request);
}
this.request = request;
}
Negotiator.prototype.charset = function charset(available) {
var set = this.charsets(available);
return set && set[0];
};
Negotiator.prototype.charsets = function charsets(available) {
return preferredCharsets(this.request.headers['accept-charset'], available);
};
Negotiator.prototype.encoding = function encoding(available) {
var set = this.encodings(available);
return set && set[0];
};
Negotiator.prototype.encodings = function encodings(available) {
return preferredEncodings(this.request.headers['accept-encoding'], available);
};
Negotiator.prototype.language = function language(available) {
var set = this.languages(available);
return set && set[0];
};
Negotiator.prototype.languages = function languages(available) {
return preferredLanguages(this.request.headers['accept-language'], available);
};
Negotiator.prototype.mediaType = function mediaType(available) {
var set = this.mediaTypes(available);
return set && set[0];
};
Negotiator.prototype.mediaTypes = function mediaTypes(available) {
return preferredMediaTypes(this.request.headers.accept, available);
};
// Backwards compatibility
Negotiator.prototype.preferredCharset = Negotiator.prototype.charset;
Negotiator.prototype.preferredCharsets = Negotiator.prototype.charsets;
Negotiator.prototype.preferredEncoding = Negotiator.prototype.encoding;
Negotiator.prototype.preferredEncodings = Negotiator.prototype.encodings;
Negotiator.prototype.preferredLanguage = Negotiator.prototype.language;
Negotiator.prototype.preferredLanguages = Negotiator.prototype.languages;
Negotiator.prototype.preferredMediaType = Negotiator.prototype.mediaType;
Negotiator.prototype.preferredMediaTypes = Negotiator.prototype.mediaTypes;
module.exports = preferredCharsets;
preferredCharsets.preferredCharsets = preferredCharsets;
function parseAcceptCharset(accept) {
var accepts = accept.split(',');
for (var i = 0, j = 0; i < accepts.length; i++) {
var charset = parseCharset(accepts[i].trim(), i);
if (charset) {
accepts[j++] = charset;
}
}
// trim accepts
accepts.length = j;
return accepts;
}
function parseCharset(s, i) {
var match = s.match(/^\s*(\S+?)\s*(?:;(.*))?$/);
if (!match) return null;
var charset = match[1];
var q = 1;
if (match[2]) {
var params = match[2].split(';')
for (var i = 0; i < params.length; i ++) {
var p = params[i].trim().split('=');
if (p[0] === 'q') {
q = parseFloat(p[1]);
break;
}
}
}
return {
charset: charset,
q: q,
i: i
};
}
function getCharsetPriority(charset, accepted, index) {
var priority = {o: -1, q: 0, s: 0};
for (var i = 0; i < accepted.length; i++) {
var spec = specify(charset, accepted[i], index);
if (spec && (priority.s - spec.s || priority.q - spec.q || priority.o - spec.o) < 0) {
priority = spec;
}
}
return priority;
}
function specify(charset, spec, index) {
var s = 0;
if(spec.charset.toLowerCase() === charset.toLowerCase()){
s |= 1;
} else if (spec.charset !== '*' ) {
return null
}
return {
i: index,
o: spec.i,
q: spec.q,
s: s
}
}
function preferredCharsets(accept, provided) {
// RFC 2616 sec 14.2: no header = *
var accepts = parseAcceptCharset(accept === undefined ? '*' : accept || '');
if (!provided) {
// sorted list of all charsets
return accepts.filter(isQuality).sort(compareSpecs).map(function getCharset(spec) {
return spec.charset;
});
}
var priorities = provided.map(function getPriority(type, index) {
return getCharsetPriority(type, accepts, index);
});
// sorted list of accepted charsets
return priorities.filter(isQuality).sort(compareSpecs).map(function getCharset(priority) {
return provided[priorities.indexOf(priority)];
});
}
function compareSpecs(a, b) {
return (b.q - a.q) || (b.s - a.s) || (a.o - b.o) || (a.i - b.i) || 0;
}
function isQuality(spec) {
return spec.q > 0;
}
module.exports = preferredEncodings;
preferredEncodings.preferredEncodings = preferredEncodings;
function parseAcceptEncoding(accept) {
var accepts = accept.split(',');
var hasIdentity = false;
var minQuality = 1;
for (var i = 0, j = 0; i < accepts.length; i++) {
var encoding = parseEncoding(accepts[i].trim(), i);
if (encoding) {
accepts[j++] = encoding;
hasIdentity = hasIdentity || specify('identity', encoding);
minQuality = Math.min(minQuality, encoding.q || 1);
}
}
if (!hasIdentity) {
/*
* If identity doesn't explicitly appear in the accept-encoding header,
* it's added to the list of acceptable encoding with the lowest q
*/
accepts[j++] = {
encoding: 'identity',
q: minQuality,
i: i
};
}
// trim accepts
accepts.length = j;
return accepts;
}
function parseEncoding(s, i) {
var match = s.match(/^\s*(\S+?)\s*(?:;(.*))?$/);
if (!match) return null;
var encoding = match[1];
var q = 1;
if (match[2]) {
var params = match[2].split(';');
for (var i = 0; i < params.length; i ++) {
var p = params[i].trim().split('=');
if (p[0] === 'q') {
q = parseFloat(p[1]);
break;
}
}
}
return {
encoding: encoding,
q: q,
i: i
};
}
function getEncodingPriority(encoding, accepted, index) {
var priority = {o: -1, q: 0, s: 0};
for (var i = 0; i < accepted.length; i++) {
var spec = specify(encoding, accepted[i], index);
if (spec && (priority.s - spec.s || priority.q - spec.q || priority.o - spec.o) < 0) {
priority = spec;
}
}
return priority;
}
function specify(encoding, spec, index) {
var s = 0;
if(spec.encoding.toLowerCase() === encoding.toLowerCase()){
s |= 1;
} else if (spec.encoding !== '*' ) {
return null
}
return {
i: index,
o: spec.i,
q: spec.q,
s: s
}
};
function preferredEncodings(accept, provided) {
var accepts = parseAcceptEncoding(accept || '');
if (!provided) {
// sorted list of all encodings
return accepts.filter(isQuality).sort(compareSpecs).map(function getEncoding(spec) {
return spec.encoding;
});
}
var priorities = provided.map(function getPriority(type, index) {
return getEncodingPriority(type, accepts, index);
});
// sorted list of accepted encodings
return priorities.filter(isQuality).sort(compareSpecs).map(function getEncoding(priority) {
return provided[priorities.indexOf(priority)];
});
}
function compareSpecs(a, b) {
return (b.q - a.q) || (b.s - a.s) || (a.o - b.o) || (a.i - b.i) || 0;
}
function isQuality(spec) {
return spec.q > 0;
}
module.exports = preferredLanguages;
preferredLanguages.preferredLanguages = preferredLanguages;
function parseAcceptLanguage(accept) {
var accepts = accept.split(',');
for (var i = 0, j = 0; i < accepts.length; i++) {
var langauge = parseLanguage(accepts[i].trim(), i);
if (langauge) {
accepts[j++] = langauge;
}
}
// trim accepts
accepts.length = j;
return accepts;
}
function parseLanguage(s, i) {
var match = s.match(/^\s*(\S+?)(?:-(\S+?))?\s*(?:;(.*))?$/);
if (!match) return null;
var prefix = match[1],
suffix = match[2],
full = prefix;
if (suffix) full += "-" + suffix;
var q = 1;
if (match[3]) {
var params = match[3].split(';')
for (var i = 0; i < params.length; i ++) {
var p = params[i].split('=');
if (p[0] === 'q') q = parseFloat(p[1]);
}
}
return {
prefix: prefix,
suffix: suffix,
q: q,
i: i,
full: full
};
}
function getLanguagePriority(language, accepted, index) {
var priority = {o: -1, q: 0, s: 0};
for (var i = 0; i < accepted.length; i++) {
var spec = specify(language, accepted[i], index);
if (spec && (priority.s - spec.s || priority.q - spec.q || priority.o - spec.o) < 0) {
priority = spec;
}
}
return priority;
}
function specify(language, spec, index) {
var p = parseLanguage(language)
if (!p) return null;
var s = 0;
if(spec.full.toLowerCase() === p.full.toLowerCase()){
s |= 4;
} else if (spec.prefix.toLowerCase() === p.full.toLowerCase()) {
s |= 2;
} else if (spec.full.toLowerCase() === p.prefix.toLowerCase()) {
s |= 1;
} else if (spec.full !== '*' ) {
return null
}
return {
i: index,
o: spec.i,
q: spec.q,
s: s
}
};
function preferredLanguages(accept, provided) {
// RFC 2616 sec 14.4: no header = *
var accepts = parseAcceptLanguage(accept === undefined ? '*' : accept || '');
if (!provided) {
// sorted list of all languages
return accepts.filter(isQuality).sort(compareSpecs).map(function getLanguage(spec) {
return spec.full;
});
}
var priorities = provided.map(function getPriority(type, index) {
return getLanguagePriority(type, accepts, index);
});
// sorted list of accepted languages
return priorities.filter(isQuality).sort(compareSpecs).map(function getLanguage(priority) {
return provided[priorities.indexOf(priority)];
});
}
function compareSpecs(a, b) {
return (b.q - a.q) || (b.s - a.s) || (a.o - b.o) || (a.i - b.i) || 0;
}
function isQuality(spec) {
return spec.q > 0;
}
module.exports = preferredMediaTypes;
preferredMediaTypes.preferredMediaTypes = preferredMediaTypes;
function parseAccept(accept) {
var accepts = accept.split(',');
for (var i = 0, j = 0; i < accepts.length; i++) {
var mediaType = parseMediaType(accepts[i].trim(), i);
if (mediaType) {
accepts[j++] = mediaType;
}
}
// trim accepts
accepts.length = j;
return accepts;
};
function parseMediaType(s, i) {
var match = s.match(/\s*(\S+?)\/([^;\s]+)\s*(?:;(.*))?/);
if (!match) return null;
var type = match[1],
subtype = match[2],
full = "" + type + "/" + subtype,
params = {},
q = 1;
if (match[3]) {
params = match[3].split(';').map(function(s) {
return s.trim().split('=');
}).reduce(function (set, p) {
set[p[0]] = p[1];
return set
}, params);
if (params.q != null) {
q = parseFloat(params.q);
delete params.q;
}
}
return {
type: type,
subtype: subtype,
params: params,
q: q,
i: i,
full: full
};
}
function getMediaTypePriority(type, accepted, index) {
var priority = {o: -1, q: 0, s: 0};
for (var i = 0; i < accepted.length; i++) {
var spec = specify(type, accepted[i], index);
if (spec && (priority.s - spec.s || priority.q - spec.q || priority.o - spec.o) < 0) {
priority = spec;
}
}
return priority;
}
function specify(type, spec, index) {
var p = parseMediaType(type);
var s = 0;
if (!p) {
return null;
}
if(spec.type.toLowerCase() == p.type.toLowerCase()) {
s |= 4
} else if(spec.type != '*') {
return null;
}
if(spec.subtype.toLowerCase() == p.subtype.toLowerCase()) {
s |= 2
} else if(spec.subtype != '*') {
return null;
}
var keys = Object.keys(spec.params);
if (keys.length > 0) {
if (keys.every(function (k) {
return spec.params[k] == '*' || (spec.params[k] || '').toLowerCase() == (p.params[k] || '').toLowerCase();
})) {
s |= 1
} else {
return null
}
}
return {
i: index,
o: spec.i,
q: spec.q,
s: s,
}
}
function preferredMediaTypes(accept, provided) {
// RFC 2616 sec 14.2: no header = */*
var accepts = parseAccept(accept === undefined ? '*/*' : accept || '');
if (!provided) {
// sorted list of all types
return accepts.filter(isQuality).sort(compareSpecs).map(function getType(spec) {
return spec.full;
});
}
var priorities = provided.map(function getPriority(type, index) {
return getMediaTypePriority(type, accepts, index);
});
// sorted list of accepted types
return priorities.filter(isQuality).sort(compareSpecs).map(function getType(priority) {
return provided[priorities.indexOf(priority)];
});
}
function compareSpecs(a, b) {
return (b.q - a.q) || (b.s - a.s) || (a.o - b.o) || (a.i - b.i) || 0;
}
function isQuality(spec) {
return spec.q > 0;
}
(The MIT License)
Copyright (c) 2012 Federico Romero
Copyright (c) 2012-2014 Isaac Z. Schlueter
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
{
"name": "negotiator",
"description": "HTTP content negotiation",
"version": "0.5.1",
"contributors": [
{
"name": "Douglas Christopher Wilson",
"email": "doug@somethingdoug.com"
},
{
"name": "Federico Romero",
"email": "federico.romero@outboxlabs.com"
},
{
"name": "Isaac Z. Schlueter",
"email": "i@izs.me",
"url": "http://blog.izs.me/"
}
],
"license": "MIT",
"keywords": [
"http",
"content negotiation",
"accept",
"accept-language",
"accept-encoding",
"accept-charset"
],
"repository": {
"type": "git",
"url": "https://github.com/jshttp/negotiator"
},
"devDependencies": {
"istanbul": "0.3.5",
"nodeunit": "0.9.0",
"tap": "0.5.0"
},
"files": [
"lib/",
"HISTORY.md",
"LICENSE",
"index.js",
"README.md"
],
"engines": {
"node": ">= 0.6"
},
"scripts": {
"test": "nodeunit test",
"test-cov": "istanbul cover ./node_modules/nodeunit/bin/nodeunit test"
},
"gitHead": "bfee971fe0503518cc93d1956518212203b7e68c",
"bugs": {
"url": "https://github.com/jshttp/negotiator/issues"
},
"homepage": "https://github.com/jshttp/negotiator",
"_id": "negotiator@0.5.1",
"_shasum": "498f661c522470153c6086ac83019cb3eb66f61c",
"_from": "negotiator@0.5.1",
"_npmVersion": "1.4.28",
"_npmUser": {
"name": "dougwilson",
"email": "doug@somethingdoug.com"
},
"maintainers": [
{
"name": "federomero",
"email": "federomero@gmail.com"
},
{
"name": "dougwilson",
"email": "doug@somethingdoug.com"
},
{
"name": "jongleberry",
"email": "jonathanrichardong@gmail.com"
}
],
"dist": {
"shasum": "498f661c522470153c6086ac83019cb3eb66f61c",
"tarball": "http://registry.npmjs.org/negotiator/-/negotiator-0.5.1.tgz"
},
"directories": {},
"_resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.5.1.tgz",
"readme": "ERROR: No README data found!"
}

negotiator

NPM Version NPM Downloads Node.js Version Build Status Test Coverage

An HTTP content negotiator for Node.js

Installation

$ npm install negotiator

API

var Negotiator = require('negotiator')

Accept Negotiation

availableMediaTypes = ['text/html', 'text/plain', 'application/json']

// The negotiator constructor receives a request object
negotiator = new Negotiator(request)

// Let's say Accept header is 'text/html, application/*;q=0.2, image/jpeg;q=0.8'

negotiator.mediaTypes()
// -> ['text/html', 'image/jpeg', 'application/*']

negotiator.mediaTypes(availableMediaTypes)
// -> ['text/html', 'application/json']

negotiator.mediaType(availableMediaTypes)
// -> 'text/html'

You can check a working example at examples/accept.js.

Methods

mediaType()

Returns the most preferred media type from the client.

mediaType(availableMediaType)

Returns the most preferred media type from a list of available media types.

mediaTypes()

Returns an array of preferred media types ordered by the client preference.

mediaTypes(availableMediaTypes)

Returns an array of preferred media types ordered by priority from a list of available media types.

Accept-Language Negotiation

negotiator = new Negotiator(request)

availableLanguages = 'en', 'es', 'fr'

// Let's say Accept-Language header is 'en;q=0.8, es, pt'

negotiator.languages()
// -> ['es', 'pt', 'en']

negotiator.languages(availableLanguages)
// -> ['es', 'en']

language = negotiator.language(availableLanguages)
// -> 'es'

You can check a working example at examples/language.js.

Methods

language()

Returns the most preferred language from the client.

language(availableLanguages)

Returns the most preferred language from a list of available languages.

languages()

Returns an array of preferred languages ordered by the client preference.

languages(availableLanguages)

Returns an array of preferred languages ordered by priority from a list of available languages.

Accept-Charset Negotiation

availableCharsets = ['utf-8', 'iso-8859-1', 'iso-8859-5']

negotiator = new Negotiator(request)

// Let's say Accept-Charset header is 'utf-8, iso-8859-1;q=0.8, utf-7;q=0.2'

negotiator.charsets()
// -> ['utf-8', 'iso-8859-1', 'utf-7']

negotiator.charsets(availableCharsets)
// -> ['utf-8', 'iso-8859-1']

negotiator.charset(availableCharsets)
// -> 'utf-8'

You can check a working example at examples/charset.js.

Methods

charset()

Returns the most preferred charset from the client.

charset(availableCharsets)

Returns the most preferred charset from a list of available charsets.

charsets()

Returns an array of preferred charsets ordered by the client preference.

charsets(availableCharsets)

Returns an array of preferred charsets ordered by priority from a list of available charsets.

Accept-Encoding Negotiation

availableEncodings = ['identity', 'gzip']

negotiator = new Negotiator(request)

// Let's say Accept-Encoding header is 'gzip, compress;q=0.2, identity;q=0.5'

negotiator.encodings()
// -> ['gzip', 'identity', 'compress']

negotiator.encodings(availableEncodings)
// -> ['gzip', 'identity']

negotiator.encoding(availableEncodings)
// -> 'gzip'

You can check a working example at examples/encoding.js.

Methods

encoding()

Returns the most preferred encoding from the client.

encoding(availableEncodings)

Returns the most preferred encoding from a list of available encodings.

encodings()

Returns an array of preferred encodings ordered by the client preference.

encodings(availableEncodings)

Returns an array of preferred encodings ordered by priority from a list of available encodings.

See Also

The accepts module builds on this module and provides an alternative interface, mime type validation, and more.

License

MIT

{
"name": "accepts",
"description": "Higher-level content negotiation",
"version": "1.2.5",
"contributors": [
{
"name": "Douglas Christopher Wilson",
"email": "doug@somethingdoug.com"
},
{
"name": "Jonathan Ong",
"email": "me@jongleberry.com",
"url": "http://jongleberry.com"
}
],
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/jshttp/accepts"
},
"dependencies": {
"mime-types": "~2.0.10",
"negotiator": "0.5.1"
},
"devDependencies": {
"istanbul": "0.3.7",
"mocha": "~1.21.5"
},
"files": [
"LICENSE",
"HISTORY.md",
"index.js"
],
"engines": {
"node": ">= 0.6"
},
"scripts": {
"test": "mocha --reporter spec --check-leaks --bail test/",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/"
},
"keywords": [
"content",
"negotiation",
"accept",
"accepts"
],
"gitHead": "e74f846e885aa70fceba1af6ce96e3952e6782c1",
"bugs": {
"url": "https://github.com/jshttp/accepts/issues"
},
"homepage": "https://github.com/jshttp/accepts",
"_id": "accepts@1.2.5",
"_shasum": "bb07dc52c141ae562611a836ff433bcec8871ce9",
"_from": "accepts@>=1.2.5 <1.3.0",
"_npmVersion": "1.4.28",
"_npmUser": {
"name": "dougwilson",
"email": "doug@somethingdoug.com"
},
"maintainers": [
{
"name": "jongleberry",
"email": "jonathanrichardong@gmail.com"
},
{
"name": "federomero",
"email": "federomero@gmail.com"
},
{
"name": "dougwilson",
"email": "doug@somethingdoug.com"
},
{
"name": "tjholowaychuk",
"email": "tj@vision-media.ca"
},
{
"name": "shtylman",
"email": "shtylman@gmail.com"
},
{
"name": "mscdex",
"email": "mscdex@mscdex.net"
},
{
"name": "fishrock123",
"email": "fishrock123@rocketmail.com"
}
],
"dist": {
"shasum": "bb07dc52c141ae562611a836ff433bcec8871ce9",
"tarball": "http://registry.npmjs.org/accepts/-/accepts-1.2.5.tgz"
},
"directories": {},
"_resolved": "https://registry.npmjs.org/accepts/-/accepts-1.2.5.tgz",
"readme": "ERROR: No README data found!"
}

accepts

NPM Version NPM Downloads Node.js Version Build Status Test Coverage

Higher level content negotiation based on negotiator. Extracted from koa for general use.

In addition to negotiator, it allows:

  • Allows types as an array or arguments list, ie (['text/html', 'application/json']) as well as ('text/html', 'application/json').
  • Allows type shorthands such as json.
  • Returns false when no types match
  • Treats non-existent headers as *

Installation

npm install accepts

API

var accepts = require('accepts')

accepts(req)

Create a new Accepts object for the given req.

.charset(charsets)

Return the first accepted charset. If nothing in charsets is accepted, then false is returned.

.charsets()

Return the charsets that the request accepts, in the order of the client's preference (most preferred first).

.encoding(encodings)

Return the first accepted encoding. If nothing in encodings is accepted, then false is returned.

.encodings()

Return the encodings that the request accepts, in the order of the client's preference (most preferred first).

.language(languages)

Return the first accepted language. If nothing in languages is accepted, then false is returned.

.languages()

Return the languages that the request accepts, in the order of the client's preference (most preferred first).

.type(types)

Return the first accepted type (and it is returned as the same text as what appears in the types array). If nothing in types is accepted, then false is returned.

The types array can contain full MIME types or file extensions. Any value that is not a full MIME types is passed to require('mime-types').lookup.

.types()

Return the types that the request accepts, in the order of the client's preference (most preferred first).

Examples

Simple type negotiation

This simple example shows how to use accepts to return a different typed respond body based on what the client wants to accept. The server lists it's preferences in order and will get back the best match between the client and server.

var accepts = require('accepts')
var http = require('http')

function app(req, res) {
  var accept = accepts(req)

  // the order of this list is significant; should be server preferred order
  switch(accept.type(['json', 'html'])) {
    case 'json':
      res.setHeader('Content-Type', 'application/json')
      res.write('{"hello":"world!"}')
      break
    case 'html':
      res.setHeader('Content-Type', 'text/html')
      res.write('<b>hello, world!</b>')
      break
    default:
      // the fallback is text/plain, so no need to specify it above
      res.setHeader('Content-Type', 'text/plain')
      res.write('hello, world!')
      break
  }

  res.end()
}

http.createServer(app).listen(3000)

You can test this out with the cURL program:

curl -I -H'Accept: text/html' http://localhost:3000/

License

MIT

0.5.0 / 2014-10-11

  • Add parse function

0.4.0 / 2014-09-21

  • Expand non-Unicode filename to the full ISO-8859-1 charset

0.3.0 / 2014-09-20

  • Add fallback option
  • Add type option

0.2.0 / 2014-09-19

  • Reduce ambiguity of file names with hex escape in buggy browsers

0.1.2 / 2014-09-19

  • Fix periodic invalid Unicode filename header

0.1.1 / 2014-09-19

  • Fix invalid characters appearing in filename* parameter

0.1.0 / 2014-09-18

  • Make the filename argument optional

0.0.0 / 2014-09-18

  • Initial release
/*!
* content-disposition
* Copyright(c) 2014 Douglas Christopher Wilson
* MIT Licensed
*/
/**
* Module exports.
*/
module.exports = contentDisposition
module.exports.parse = parse
/**
* Module dependencies.
*/
var basename = require('path').basename
/**
* RegExp to match non attr-char, *after* encodeURIComponent (i.e. not including "%")
*/
var encodeUriAttrCharRegExp = /[\x00-\x20"'\(\)*,\/:;<=>?@\[\\\]\{\}\x7f]/g
/**
* RegExp to match percent encoding escape.
*/
var hexEscapeRegExp = /%[0-9A-Fa-f]{2}/
var hexEscapeReplaceRegExp = /%([0-9A-Fa-f]{2})/g
/**
* RegExp to match non-latin1 characters.
*/
var nonLatin1RegExp = /[^\x20-\x7e\xa0-\xff]/g
/**
* RegExp to match quoted-pair in RFC 2616
*
* quoted-pair = "\" CHAR
* CHAR = <any US-ASCII character (octets 0 - 127)>
*/
var qescRegExp = /\\([\u0000-\u007f])/g;
/**
* RegExp to match chars that must be quoted-pair in RFC 2616
*/
var quoteRegExp = /([\\"])/g
/**
* RegExp for various RFC 2616 grammar
*
* parameter = token "=" ( token | quoted-string )
* token = 1*<any CHAR except CTLs or separators>
* separators = "(" | ")" | "<" | ">" | "@"
* | "," | ";" | ":" | "\" | <">
* | "/" | "[" | "]" | "?" | "="
* | "{" | "}" | SP | HT
* quoted-string = ( <"> *(qdtext | quoted-pair ) <"> )
* qdtext = <any TEXT except <">>
* quoted-pair = "\" CHAR
* CHAR = <any US-ASCII character (octets 0 - 127)>
* TEXT = <any OCTET except CTLs, but including LWS>
* LWS = [CRLF] 1*( SP | HT )
* CRLF = CR LF
* CR = <US-ASCII CR, carriage return (13)>
* LF = <US-ASCII LF, linefeed (10)>
* SP = <US-ASCII SP, space (32)>
* HT = <US-ASCII HT, horizontal-tab (9)>
* CTL = <any US-ASCII control character (octets 0 - 31) and DEL (127)>
* OCTET = <any 8-bit sequence of data>
*/
var paramRegExp = /; *([!#$%&'\*\+\-\.0-9A-Z\^_`a-z\|~]+) *= *("(?:[ !\x23-\x5b\x5d-\x7e\x80-\xff]|\\[\x20-\x7e])*"|[!#$%&'\*\+\-\.0-9A-Z\^_`a-z\|~]+) */g
var textRegExp = /^[\x20-\x7e\x80-\xff]+$/
var tokenRegExp = /^[!#$%&'\*\+\-\.0-9A-Z\^_`a-z\|~]+$/
/**
* RegExp for various RFC 5987 grammar
*
* ext-value = charset "'" [ language ] "'" value-chars
* charset = "UTF-8" / "ISO-8859-1" / mime-charset
* mime-charset = 1*mime-charsetc
* mime-charsetc = ALPHA / DIGIT
* / "!" / "#" / "$" / "%" / "&"
* / "+" / "-" / "^" / "_" / "`"
* / "{" / "}" / "~"
* language = ( 2*3ALPHA [ extlang ] )
* / 4ALPHA
* / 5*8ALPHA
* extlang = *3( "-" 3ALPHA )
* value-chars = *( pct-encoded / attr-char )
* pct-encoded = "%" HEXDIG HEXDIG
* attr-char = ALPHA / DIGIT
* / "!" / "#" / "$" / "&" / "+" / "-" / "."
* / "^" / "_" / "`" / "|" / "~"
*/
var extValueRegExp = /^([A-Za-z0-9!#$%&+\-^_`{}~]+)'(?:[A-Za-z]{2,3}(?:-[A-Za-z]{3}){0,3}|[A-Za-z]{4,8}|)'((?:%[0-9A-Fa-f]{2}|[A-Za-z0-9!#$&+\-\.^_`|~])+)$/
/**
* RegExp for various RFC 6266 grammar
*
* disposition-type = "inline" | "attachment" | disp-ext-type
* disp-ext-type = token
* disposition-parm = filename-parm | disp-ext-parm
* filename-parm = "filename" "=" value
* | "filename*" "=" ext-value
* disp-ext-parm = token "=" value
* | ext-token "=" ext-value
* ext-token = <the characters in token, followed by "*">
*/
var dispositionTypeRegExp = /^([!#$%&'\*\+\-\.0-9A-Z\^_`a-z\|~]+) *(?:$|;)/
/**
* Create an attachment Content-Disposition header.
*
* @param {string} [filename]
* @param {object} [options]
* @param {string} [options.type=attachment]
* @param {string|boolean} [options.fallback=true]
* @return {string}
* @api public
*/
function contentDisposition(filename, options) {
var opts = options || {}
// get type
var type = opts.type || 'attachment'
// get parameters
var params = createparams(filename, opts.fallback)
// format into string
return format(new ContentDisposition(type, params))
}
/**
* Create parameters object from filename and fallback.
*
* @param {string} [filename]
* @param {string|boolean} [fallback=true]
* @return {object}
* @api private
*/
function createparams(filename, fallback) {
if (filename === undefined) {
return
}
var params = {}
if (typeof filename !== 'string') {
throw new TypeError('filename must be a string')
}
// fallback defaults to true
if (fallback === undefined) {
fallback = true
}
if (typeof fallback !== 'string' && typeof fallback !== 'boolean') {
throw new TypeError('fallback must be a string or boolean')
}
if (typeof fallback === 'string' && nonLatin1RegExp.test(fallback)) {
throw new TypeError('fallback must be ISO-8859-1 string')
}
// restrict to file base name
var name = basename(filename)
// determine if name is suitable for quoted string
var isQuotedString = textRegExp.test(name)
// generate fallback name
var fallbackName = typeof fallback !== 'string'
? fallback && getlatin1(name)
: basename(fallback)
var hasFallback = typeof fallbackName === 'string' && fallbackName !== name
// set extended filename parameter
if (hasFallback || !isQuotedString || hexEscapeRegExp.test(name)) {
params['filename*'] = name
}
// set filename parameter
if (isQuotedString || hasFallback) {
params.filename = hasFallback
? fallbackName
: name
}
return params
}
/**
* Format object to Content-Disposition header.
*
* @param {object} obj
* @param {string} obj.type
* @param {object} [obj.parameters]
* @return {string}
* @api private
*/
function format(obj) {
var parameters = obj.parameters
var type = obj.type
if (!type || typeof type !== 'string' || !tokenRegExp.test(type)) {
throw new TypeError('invalid type')
}
// start with normalized type
var string = String(type).toLowerCase()
// append parameters
if (parameters && typeof parameters === 'object') {
var param
var params = Object.keys(parameters).sort()
for (var i = 0; i < params.length; i++) {
param = params[i]
var val = param.substr(-1) === '*'
? ustring(parameters[param])
: qstring(parameters[param])
string += '; ' + param + '=' + val
}
}
return string
}
/**
* Decode a RFC 6987 field value (gracefully).
*
* @param {string} str
* @return {string}
* @api private
*/
function decodefield(str) {
var match = extValueRegExp.exec(str)
if (!match) {
throw new TypeError('invalid extended field value')
}
var charset = match[1].toLowerCase()
var encoded = match[2]
var value
// to binary string
var binary = encoded.replace(hexEscapeReplaceRegExp, pdecode)
switch (charset) {
case 'iso-8859-1':
value = getlatin1(binary)
break
case 'utf-8':
value = new Buffer(binary, 'binary').toString('utf8')
break
default:
throw new TypeError('unsupported charset in extended field')
}
return value
}
/**
* Get ISO-8859-1 version of string.
*
* @param {string} val
* @return {string}
* @api private
*/
function getlatin1(val) {
// simple Unicode -> ISO-8859-1 transformation
return String(val).replace(nonLatin1RegExp, '?')
}
/**
* Parse Content-Disposition header string.
*
* @param {string} string
* @return {object}
* @api private
*/
function parse(string) {
if (!string || typeof string !== 'string') {
throw new TypeError('argument string is required')
}
var match = dispositionTypeRegExp.exec(string)
if (!match) {
throw new TypeError('invalid type format')
}
// normalize type
var index = match[0].length
var type = match[1].toLowerCase()
var key
var names = []
var params = {}
var value
// calculate index to start at
index = paramRegExp.lastIndex = match[0].substr(-1) === ';'
? index - 1
: index
// match parameters
while (match = paramRegExp.exec(string)) {
if (match.index !== index) {
throw new TypeError('invalid parameter format')
}
index += match[0].length
key = match[1].toLowerCase()
value = match[2]
if (names.indexOf(key) !== -1) {
throw new TypeError('invalid duplicate parameter')
}
names.push(key)
if (key.indexOf('*') + 1 === key.length) {
// decode extended value
key = key.slice(0, -1)
value = decodefield(value)
// overwrite existing value
params[key] = value
continue
}
if (typeof params[key] === 'string') {
continue
}
if (value[0] === '"') {
// remove quotes and escapes
value = value
.substr(1, value.length - 2)
.replace(qescRegExp, '$1')
}
params[key] = value
}
if (index !== -1 && index !== string.length) {
throw new TypeError('invalid parameter format')
}
return new ContentDisposition(type, params)
}
/**
* Percent decode a single character.
*
* @param {string} str
* @param {string} hex
* @return {string}
* @api private
*/
function pdecode(str, hex) {
return String.fromCharCode(parseInt(hex, 16))
}
/**
* Percent encode a single character.
*
* @param {string} char
* @return {string}
* @api private
*/
function pencode(char) {
var hex = String(char)
.charCodeAt(0)
.toString(16)
.toUpperCase()
return hex.length === 1
? '%0' + hex
: '%' + hex
}
/**
* Quote a string for HTTP.
*
* @param {string} val
* @return {string}
* @api private
*/
function qstring(val) {
var str = String(val)
return '"' + str.replace(quoteRegExp, '\\$1') + '"'
}
/**
* Encode a Unicode string for HTTP (RFC 5987).
*
* @param {string} val
* @return {string}
* @api private
*/
function ustring(val) {
var str = String(val)
// percent encode as UTF-8
var encoded = encodeURIComponent(str)
.replace(encodeUriAttrCharRegExp, pencode)
return 'UTF-8\'\'' + encoded
}
/**
* Class for parsed Content-Disposition header for v8 optimization
*/
function ContentDisposition(type, parameters) {
this.type = type
this.parameters = parameters
}
(The MIT License)
Copyright (c) 2014 Douglas Christopher Wilson
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
{
"name": "content-disposition",
"description": "Create and parse Content-Disposition header",
"version": "0.5.0",
"contributors": [
{
"name": "Douglas Christopher Wilson",
"email": "doug@somethingdoug.com"
}
],
"license": "MIT",
"keywords": [
"content-disposition",
"http",
"rfc6266",
"res"
],
"repository": {
"type": "git",
"url": "https://github.com/jshttp/content-disposition"
},
"devDependencies": {
"istanbul": "0.3.2",
"mocha": "~1.21.4"
},
"files": [
"LICENSE",
"HISTORY.md",
"README.md",
"index.js"
],
"engines": {
"node": ">= 0.6"
},
"scripts": {
"test": "mocha --reporter spec --bail --check-leaks test/",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/"
},
"gitHead": "f3c915f0c9d9f5ec79713dba24c8c6181b73305d",
"bugs": {
"url": "https://github.com/jshttp/content-disposition/issues"
},
"homepage": "https://github.com/jshttp/content-disposition",
"_id": "content-disposition@0.5.0",
"_shasum": "4284fe6ae0630874639e44e80a418c2934135e9e",
"_from": "content-disposition@0.5.0",
"_npmVersion": "1.4.21",
"_npmUser": {
"name": "dougwilson",
"email": "doug@somethingdoug.com"
},
"maintainers": [
{
"name": "dougwilson",
"email": "doug@somethingdoug.com"
}
],
"dist": {
"shasum": "4284fe6ae0630874639e44e80a418c2934135e9e",
"tarball": "http://registry.npmjs.org/content-disposition/-/content-disposition-0.5.0.tgz"
},
"directories": {},
"_resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.0.tgz",
"readme": "ERROR: No README data found!"
}

content-disposition

NPM Version NPM Downloads Node.js Version Build Status Test Coverage

Create and parse HTTP Content-Disposition header

Installation

$ npm install content-disposition

API

var contentDisposition = require('content-disposition')

contentDisposition(filename, options)

Create an attachment Content-Disposition header value using the given file name, if supplied. The filename is optional and if no file name is desired, but you want to specify options, set filename to undefined.

res.setHeader('Content-Disposition', contentDisposition('∫ maths.pdf'))

note HTTP headers are of the ISO-8859-1 character set. If you are writing this header through a means different from setHeader in Node.js, you'll want to specify the 'binary' encoding in Node.js.

Options

contentDisposition accepts these properties in the options object.

fallback

If the filename option is outside ISO-8859-1, then the file name is actually stored in a supplemental field for clients that support Unicode file names and a ISO-8859-1 version of the file name is automatically generated.

This specifies the ISO-8859-1 file name to override the automatic generation or disables the generation all together, defaults to true.

  • A string will specify the ISO-8859-1 file name to use in place of automatic generation.
  • false will disable including a ISO-8859-1 file name and only include the Unicode version (unless the file name is already ISO-8859-1).
  • true will enable automatic generation if the file name is outside ISO-8859-1.

If the filename option is ISO-8859-1 and this option is specified and has a different value, then the filename option is encoded in the extended field and this set as the fallback field, even though they are both ISO-8859-1.

type

Specifies the disposition type, defaults to "attachment". This can also be "inline", or any other value (all values except inline are treated like attachment, but can convey additional information if both parties agree to it). The type is normalized to lower-case.

contentDisposition.parse(string)

var disposition = contentDisposition.parse('attachment; filename="EURO rates.txt"; filename*=UTF-8\'\'%e2%82%ac%20rates.txt"');

Parse a Content-Disposition header string. This automatically handles extended ("Unicode") parameters by decoding them and providing them under the standard parameter name. This will return an object with the following properties (examples are shown for the string 'attachment; filename="EURO rates.txt"; filename*=UTF-8\'\'%e2%82%ac%20rates.txt'):

  • type: The disposition type (always lower case). Example: 'attachment'

  • parameters: An object of the parameters in the disposition (name of parameter always lower case and extended versions replace non-extended versions). Example: {filename: "€ rates.txt"}

Examples

Send a file for download

var contentDisposition = require('content-disposition')
var destroy = require('destroy')
var http = require('http')
var onFinished = require('on-finished')

var filePath = '/path/to/public/plans.pdf'

http.createServer(function onRequest(req, res) {
  // set headers
  res.setHeader('Content-Type', 'application/pdf')
  res.setHeader('Content-Disposition', contentDisposition(filePath))

  // send file
  var stream = fs.createReadStream(filePath)
  stream.pipe(res)
  onFinished(res, function (err) {
    destroy(stream)
  })
})

Testing

$ npm test

References

License

MIT

1.0.1 / 2015-02-13

  • Improve missing Content-Type header error message

1.0.0 / 2015-02-01

  • Initial implementation, derived from media-typer@0.3.0
/*!
* content-type
* Copyright(c) 2015 Douglas Christopher Wilson
* MIT Licensed
*/
/**
* RegExp to match *( ";" parameter ) in RFC 7231 sec 3.1.1.1
*
* parameter = token "=" ( token / quoted-string )
* token = 1*tchar
* tchar = "!" / "#" / "$" / "%" / "&" / "'" / "*"
* / "+" / "-" / "." / "^" / "_" / "`" / "|" / "~"
* / DIGIT / ALPHA
* ; any VCHAR, except delimiters
* quoted-string = DQUOTE *( qdtext / quoted-pair ) DQUOTE
* qdtext = HTAB / SP / %x21 / %x23-5B / %x5D-7E / obs-text
* obs-text = %x80-FF
* quoted-pair = "\" ( HTAB / SP / VCHAR / obs-text )
*/
var paramRegExp = /; *([!#$%&'\*\+\-\.\^_`\|~0-9A-Za-z]+) *= *("(?:[\u000b\u0020\u0021\u0023-\u005b\u005d-\u007e\u0080-\u00ff]|\\[\u000b\u0020-\u00ff])*"|[!#$%&'\*\+\-\.\^_`\|~0-9A-Za-z]+) */g
var textRegExp = /^[\u000b\u0020-\u007e\u0080-\u00ff]+$/
var tokenRegExp = /^[!#$%&'\*\+\-\.\^_`\|~0-9A-Za-z]+$/
/**
* RegExp to match quoted-pair in RFC 7230 sec 3.2.6
*
* quoted-pair = "\" ( HTAB / SP / VCHAR / obs-text )
* obs-text = %x80-FF
*/
var qescRegExp = /\\([\u000b\u0020-\u00ff])/g
/**
* RegExp to match chars that must be quoted-pair in RFC 7230 sec 3.2.6
*/
var quoteRegExp = /([\\"])/g
/**
* RegExp to match type in RFC 6838
*
* media-type = type "/" subtype
* type = token
* subtype = token
*/
var typeRegExp = /^[!#$%&'\*\+\-\.\^_`\|~0-9A-Za-z]+\/[!#$%&'\*\+\-\.\^_`\|~0-9A-Za-z]+$/
/**
* Module exports.
* @public
*/
exports.format = format
exports.parse = parse
/**
* Format object to media type.
*
* @param {object} obj
* @return {string}
* @public
*/
function format(obj) {
if (!obj || typeof obj !== 'object') {
throw new TypeError('argument obj is required')
}
var parameters = obj.parameters
var type = obj.type
if (!type || !typeRegExp.test(type)) {
throw new TypeError('invalid type')
}
var string = type
// append parameters
if (parameters && typeof parameters === 'object') {
var param
var params = Object.keys(parameters).sort()
for (var i = 0; i < params.length; i++) {
param = params[i]
if (!tokenRegExp.test(param)) {
throw new TypeError('invalid parameter name')
}
string += '; ' + param + '=' + qstring(parameters[param])
}
}
return string
}
/**
* Parse media type to object.
*
* @param {string|object} string
* @return {Object}
* @public
*/
function parse(string) {
if (!string) {
throw new TypeError('argument string is required')
}
if (typeof string === 'object') {
// support req/res-like objects as argument
string = getcontenttype(string)
if (typeof string !== 'string') {
throw new TypeError('content-type header is missing from object');
}
}
if (typeof string !== 'string') {
throw new TypeError('argument string is required to be a string')
}
var index = string.indexOf(';')
var type = index !== -1
? string.substr(0, index).trim()
: string.trim()
if (!typeRegExp.test(type)) {
throw new TypeError('invalid media type')
}
var key
var match
var obj = new ContentType(type.toLowerCase())
var value
paramRegExp.lastIndex = index
while (match = paramRegExp.exec(string)) {
if (match.index !== index) {
throw new TypeError('invalid parameter format')
}
index += match[0].length
key = match[1].toLowerCase()
value = match[2]
if (value[0] === '"') {
// remove quotes and escapes
value = value
.substr(1, value.length - 2)
.replace(qescRegExp, '$1')
}
obj.parameters[key] = value
}
if (index !== -1 && index !== string.length) {
throw new TypeError('invalid parameter format')
}
return obj
}
/**
* Get content-type from req/res objects.
*
* @param {object}
* @return {Object}
* @private
*/
function getcontenttype(obj) {
if (typeof obj.getHeader === 'function') {
// res-like
return obj.getHeader('content-type')
}
if (typeof obj.headers === 'object') {
// req-like
return obj.headers && obj.headers['content-type']
}
}
/**
* Quote a string if necessary.
*
* @param {string} val
* @return {string}
* @private
*/
function qstring(val) {
var str = String(val)
// no need to quote tokens
if (tokenRegExp.test(str)) {
return str
}
if (str.length > 0 && !textRegExp.test(str)) {
throw new TypeError('invalid parameter value')
}
return '"' + str.replace(quoteRegExp, '\\$1') + '"'
}
/**
* Class to represent a content type.
* @private
*/
function ContentType(type) {
this.parameters = Object.create(null)
this.type = type
}
(The MIT License)
Copyright (c) 2015 Douglas Christopher Wilson
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
{
"name": "content-type",
"description": "Create and parse HTTP Content-Type header",
"version": "1.0.1",
"author": {
"name": "Douglas Christopher Wilson",
"email": "doug@somethingdoug.com"
},
"license": "MIT",
"keywords": [
"content-type",
"http",
"req",
"res",
"rfc7231"
],
"repository": {
"type": "git",
"url": "https://github.com/jshttp/content-type"
},
"devDependencies": {
"istanbul": "0.3.5",
"mocha": "~1.21.5"
},
"files": [
"LICENSE",
"HISTORY.md",
"README.md",
"index.js"
],
"engines": {
"node": ">= 0.6"
},
"scripts": {
"test": "mocha --reporter spec --check-leaks --bail test/",
"test-ci": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/"
},
"gitHead": "3aa58f9c5a358a3634b8601602177888b4a477d8",
"bugs": {
"url": "https://github.com/jshttp/content-type/issues"
},
"homepage": "https://github.com/jshttp/content-type",
"_id": "content-type@1.0.1",
"_shasum": "a19d2247327dc038050ce622b7a154ec59c5e600",
"_from": "content-type@>=1.0.1 <1.1.0",
"_npmVersion": "1.4.28",
"_npmUser": {
"name": "dougwilson",
"email": "doug@somethingdoug.com"
},
"maintainers": [
{
"name": "dougwilson",
"email": "doug@somethingdoug.com"
}
],
"dist": {
"shasum": "a19d2247327dc038050ce622b7a154ec59c5e600",
"tarball": "http://registry.npmjs.org/content-type/-/content-type-1.0.1.tgz"
},
"directories": {},
"_resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.1.tgz",
"readme": "ERROR: No README data found!"
}

content-type

NPM Version NPM Downloads Node.js Version Build Status Test Coverage

Create and parse HTTP Content-Type header according to RFC 7231

Installation

$ npm install content-type

API

var contentType = require('content-type')

contentType.parse(string)

var obj = contentType.parse('image/svg+xml; charset=utf-8')

Parse a content type string. This will return an object with the following properties (examples are shown for the string 'image/svg+xml; charset=utf-8'):

  • type: The media type (the type and subtype, always lower case). Example: 'image/svg+xml'

  • parameters: An object of the parameters in the media type (name of parameter always lower case). Example: {charset: 'utf-8'}

Throws a TypeError if the string is missing or invalid.

contentType.parse(req)

var obj = contentType.parse(req)

Parse the content-type header from the given req. Short-cut for contentType.parse(req.headers['content-type']).

Throws a TypeError if the Content-Type header is missing or invalid.

contentType.parse(res)

var obj = contentType.parse(res)

Parse the content-type header set on the given res. Short-cut for contentType.parse(res.getHeader('content-type')).

Throws a TypeError if the Content-Type header is missing or invalid.

contentType.format(obj)

var str = contentType.format({type: 'image/svg+xml'})

Format an object into a content type string. This will return a string of the content type for the given object with the following properties (examples are shown that produce the string 'image/svg+xml; charset=utf-8'):

  • type: The media type (will be lower-cased). Example: 'image/svg+xml'

  • parameters: An object of the parameters in the media type (name of the parameter will be lower-cased). Example: {charset: 'utf-8'}

Throws a TypeError if the object contains an invalid type or parameter names.

License

MIT

{
"name": "visionmedia-debug",
"main": "dist/debug.js",
"version": "2.1.3",
"homepage": "https://github.com/visionmedia/debug",
"authors": [
"TJ Holowaychuk <tj@vision-media.ca>"
],
"description": "visionmedia-debug",
"moduleType": [
"amd",
"es6",
"globals",
"node"
],
"keywords": [
"visionmedia",
"debug"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
]
}
/**
* This is the web browser implementation of `debug()`.
*
* Expose `debug()` as the module.
*/
exports = module.exports = require('./debug');
exports.log = log;
exports.formatArgs = formatArgs;
exports.save = save;
exports.load = load;
exports.useColors = useColors;
/**
* Use chrome.storage.local if we are in an app
*/
var storage;
if (typeof chrome !== 'undefined' && typeof chrome.storage !== 'undefined')
storage = chrome.storage.local;
else
storage = localstorage();
/**
* Colors.
*/
exports.colors = [
'lightseagreen',
'forestgreen',
'goldenrod',
'dodgerblue',
'darkorchid',
'crimson'
];
/**
* Currently only WebKit-based Web Inspectors, Firefox >= v31,
* and the Firebug extension (any Firefox version) are known
* to support "%c" CSS customizations.
*
* TODO: add a `localStorage` variable to explicitly enable/disable colors
*/
function useColors() {
// is webkit? http://stackoverflow.com/a/16459606/376773
return ('WebkitAppearance' in document.documentElement.style) ||
// is firebug? http://stackoverflow.com/a/398120/376773
(window.console && (console.firebug || (console.exception && console.table))) ||
// is firefox >= v31?
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
(navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31);
}
/**
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
*/
exports.formatters.j = function(v) {
return JSON.stringify(v);
};
/**
* Colorize log arguments if enabled.
*
* @api public
*/
function formatArgs() {
var args = arguments;
var useColors = this.useColors;
args[0] = (useColors ? '%c' : '')
+ this.namespace
+ (useColors ? ' %c' : ' ')
+ args[0]
+ (useColors ? '%c ' : ' ')
+ '+' + exports.humanize(this.diff);
if (!useColors) return args;
var c = 'color: ' + this.color;
args = [args[0], c, 'color: inherit'].concat(Array.prototype.slice.call(args, 1));
// the final "%c" is somewhat tricky, because there could be other
// arguments passed either before or after the %c, so we need to
// figure out the correct index to insert the CSS into
var index = 0;
var lastC = 0;
args[0].replace(/%[a-z%]/g, function(match) {
if ('%%' === match) return;
index++;
if ('%c' === match) {
// we only are interested in the *last* %c
// (the user may have provided their own)
lastC = index;
}
});
args.splice(lastC, 0, c);
return args;
}
/**
* Invokes `console.log()` when available.
* No-op when `console.log` is not a "function".
*
* @api public
*/
function log() {
// this hackery is required for IE8/9, where
// the `console.log` function doesn't have 'apply'
return 'object' === typeof console
&& console.log
&& Function.prototype.apply.call(console.log, console, arguments);
}
/**
* Save `namespaces`.
*
* @param {String} namespaces
* @api private
*/
function save(namespaces) {
try {
if (null == namespaces) {
storage.removeItem('debug');
} else {
storage.debug = namespaces;
}
} catch(e) {}
}
/**
* Load `namespaces`.
*
* @return {String} returns the previously persisted debug modes
* @api private
*/
function load() {
var r;
try {
r = storage.debug;
} catch(e) {}
return r;
}
/**
* Enable namespaces listed in `localStorage.debug` initially.
*/
exports.enable(load());
/**
* Localstorage attempts to return the localstorage.
*
* This is necessary because safari throws
* when a user disables cookies/localstorage
* and you attempt to access it.
*
* @return {LocalStorage}
* @api private
*/
function localstorage(){
try {
return window.localStorage;
} catch (e) {}
}
{
"name": "debug",
"repo": "visionmedia/debug",
"description": "small debugging utility",
"version": "2.1.3",
"keywords": [
"debug",
"log",
"debugger"
],
"main": "browser.js",
"scripts": [
"browser.js",
"debug.js"
],
"dependencies": {
"rauchg/ms.js": "0.7.0"
}
}
/**
* This is the common logic for both the Node.js and web browser
* implementations of `debug()`.
*
* Expose `debug()` as the module.
*/
exports = module.exports = debug;
exports.coerce = coerce;
exports.disable = disable;
exports.enable = enable;
exports.enabled = enabled;
exports.humanize = require('ms');
/**
* The currently active debug mode names, and names to skip.
*/
exports.names = [];
exports.skips = [];
/**
* Map of special "%n" handling functions, for the debug "format" argument.
*
* Valid key names are a single, lowercased letter, i.e. "n".
*/
exports.formatters = {};
/**
* Previously assigned color.
*/
var prevColor = 0;
/**
* Previous log timestamp.
*/
var prevTime;
/**
* Select a color.
*
* @return {Number}
* @api private
*/
function selectColor() {
return exports.colors[prevColor++ % exports.colors.length];
}
/**
* Create a debugger with the given `namespace`.
*
* @param {String} namespace
* @return {Function}
* @api public
*/
function debug(namespace) {
// define the `disabled` version
function disabled() {
}
disabled.enabled = false;
// define the `enabled` version
function enabled() {
var self = enabled;
// set `diff` timestamp
var curr = +new Date();
var ms = curr - (prevTime || curr);
self.diff = ms;
self.prev = prevTime;
self.curr = curr;
prevTime = curr;
// add the `color` if not set
if (null == self.useColors) self.useColors = exports.useColors();
if (null == self.color && self.useColors) self.color = selectColor();
var args = Array.prototype.slice.call(arguments);
args[0] = exports.coerce(args[0]);
if ('string' !== typeof args[0]) {
// anything else let's inspect with %o
args = ['%o'].concat(args);
}
// apply any `formatters` transformations
var index = 0;
args[0] = args[0].replace(/%([a-z%])/g, function(match, format) {
// if we encounter an escaped % then don't increase the array index
if (match === '%%') return match;
index++;
var formatter = exports.formatters[format];
if ('function' === typeof formatter) {
var val = args[index];
match = formatter.call(self, val);
// now we need to remove `args[index]` since it's inlined in the `format`
args.splice(index, 1);
index--;
}
return match;
});
if ('function' === typeof exports.formatArgs) {
args = exports.formatArgs.apply(self, args);
}
var logFn = enabled.log || exports.log || console.log.bind(console);
logFn.apply(self, args);
}
enabled.enabled = true;
var fn = exports.enabled(namespace) ? enabled : disabled;
fn.namespace = namespace;
return fn;
}
/**
* Enables a debug mode by namespaces. This can include modes
* separated by a colon and wildcards.
*
* @param {String} namespaces
* @api public
*/
function enable(namespaces) {
exports.save(namespaces);
var split = (namespaces || '').split(/[\s,]+/);
var len = split.length;
for (var i = 0; i < len; i++) {
if (!split[i]) continue; // ignore empty strings
namespaces = split[i].replace(/\*/g, '.*?');
if (namespaces[0] === '-') {
exports.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
} else {
exports.names.push(new RegExp('^' + namespaces + '$'));
}
}
}
/**
* Disable debug output.
*
* @api public
*/
function disable() {
exports.enable('');
}
/**
* Returns true if the given mode name is enabled, false otherwise.
*
* @param {String} name
* @return {Boolean}
* @api public
*/
function enabled(name) {
var i, len;
for (i = 0, len = exports.skips.length; i < len; i++) {
if (exports.skips[i].test(name)) {
return false;
}
}
for (i = 0, len = exports.names.length; i < len; i++) {
if (exports.names[i].test(name)) {
return true;
}
}
return false;
}
/**
* Coerce `val`.
*
* @param {Mixed} val
* @return {Mixed}
* @api private
*/
function coerce(val) {
if (val instanceof Error) return val.stack || val.message;
return val;
}

2.1.3 / 2015-03-13

  • Updated stdout/stderr example (#186)
  • Updated example/stdout.js to match debug current behaviour
  • Renamed example/stderr.js to stdout.js
  • Update Readme.md (#184)
  • replace high intensity foreground color for bold (#182, #183)

2.1.2 / 2015-03-01

  • dist: recompile
  • update "ms" to v0.7.0
  • package: update "browserify" to v9.0.3
  • component: fix "ms.js" repo location
  • changed bower package name
  • updated documentation about using debug in a browser
  • fix: security error on safari (#167, #168, @yields)

2.1.1 / 2014-12-29

  • browser: use typeof to check for console existence
  • browser: check for console.log truthiness (fix IE 8/9)
  • browser: add support for Chrome apps
  • Readme: added Windows usage remarks
  • Add bower.json to properly support bower install

2.1.0 / 2014-10-15

  • node: implement DEBUG_FD env variable support
  • package: update "browserify" to v6.1.0
  • package: add "license" field to package.json (#135, @panuhorsmalahti)

2.0.0 / 2014-09-01

  • package: update "browserify" to v5.11.0
  • node: use stderr rather than stdout for logging (#29, @stephenmathieson)

1.0.4 / 2014-07-15

  • dist: recompile
  • example: remove console.info() log usage
  • example: add "Content-Type" UTF-8 header to browser example
  • browser: place %c marker after the space character
  • browser: reset the "content" color via color: inherit
  • browser: add colors support for Firefox >= v31
  • debug: prefer an instance log() function over the global one (#119)
  • Readme: update documentation about styled console logs for FF v31 (#116, @wryk)

1.0.3 / 2014-07-09

  • Add support for multiple wildcards in namespaces (#122, @seegno)
  • browser: fix lint

1.0.2 / 2014-06-10

  • browser: update color palette (#113, @gscottolson)
  • common: make console logging function configurable (#108, @timoxley)
  • node: fix %o colors on old node <= 0.8.x
  • Makefile: find node path using shell/which (#109, @timoxley)

1.0.1 / 2014-06-06

  • browser: use removeItem() to clear localStorage
  • browser, node: don't set DEBUG if namespaces is undefined (#107, @leedm777)
  • package: add "contributors" section
  • node: fix comment typo
  • README: list authors

1.0.0 / 2014-06-04

  • make ms diff be global, not be scope
  • debug: ignore empty strings in enable()
  • node: make DEBUG_COLORS able to disable coloring
  • *: export the colors array
  • npmignore: don't publish the dist dir
  • Makefile: refactor to use browserify
  • package: add "browserify" as a dev dependency
  • Readme: add Web Inspector Colors section
  • node: reset terminal color for the debug content
  • node: map "%o" to util.inspect()
  • browser: map "%j" to JSON.stringify()
  • debug: add custom "formatters"
  • debug: use "ms" module for humanizing the diff
  • Readme: add "bash" syntax highlighting
  • browser: add Firebug color support
  • browser: add colors for WebKit browsers
  • node: apply log to console
  • rewrite: abstract common logic for Node & browsers
  • add .jshintrc file

0.8.1 / 2014-04-14

  • package: re-add the "component" section

0.8.0 / 2014-03-30

  • add enable() method for nodejs. Closes #27
  • change from stderr to stdout
  • remove unnecessary index.js file

0.7.4 / 2013-11-13

  • remove "browserify" key from package.json (fixes something in browserify)

0.7.3 / 2013-10-30

  • fix: catch localStorage security error when cookies are blocked (Chrome)
  • add debug(err) support. Closes #46
  • add .browser prop to package.json. Closes #42

0.7.2 / 2013-02-06

  • fix package.json
  • fix: Mobile Safari (private mode) is broken with debug
  • fix: Use unicode to send escape character to shell instead of octal to work with strict mode javascript

0.7.1 / 2013-02-05

  • add repository URL to package.json
  • add DEBUG_COLORED to force colored output
  • add browserify support
  • fix component. Closes #24

0.7.0 / 2012-05-04

  • Added .component to package.json
  • Added debug.component.js build

0.6.0 / 2012-03-16

  • Added support for "-" prefix in DEBUG [Vinay Pulim]
  • Added .enabled flag to the node version [TooTallNate]

0.5.0 / 2012-02-02

  • Added: humanize diffs. Closes #8
  • Added debug.disable() to the CS variant
  • Removed padding. Closes #10
  • Fixed: persist client-side variant again. Closes #9

0.4.0 / 2012-02-01

  • Added browser variant support for older browsers [TooTallNate]
  • Added debug.enable('project:*') to browser variant [TooTallNate]
  • Added padding to diff (moved it to the right)

0.3.0 / 2012-01-26

  • Added millisecond diff when isatty, otherwise UTC string

0.2.0 / 2012-01-22

  • Added wildcard support

0.1.0 / 2011-12-02

  • Added: remove colors unless stderr isatty [TooTallNate]

0.0.1 / 2010-01-03

  • Initial release
# get Makefile directory name: http://stackoverflow.com/a/5982798/376773
THIS_MAKEFILE_PATH:=$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
THIS_DIR:=$(shell cd $(dir $(THIS_MAKEFILE_PATH));pwd)
# BIN directory
BIN := $(THIS_DIR)/node_modules/.bin
# applications
NODE ?= $(shell which node)
NPM ?= $(NODE) $(shell which npm)
BROWSERIFY ?= $(NODE) $(BIN)/browserify
all: dist/debug.js
install: node_modules
clean:
@rm -rf node_modules dist
dist:
@mkdir -p $@
dist/debug.js: node_modules browser.js debug.js dist
@$(BROWSERIFY) \
--standalone debug \
. > $@
node_modules: package.json
@NODE_ENV= $(NPM) install
@touch node_modules
.PHONY: all install clean
/**
* Module dependencies.
*/
var tty = require('tty');
var util = require('util');
/**
* This is the Node.js implementation of `debug()`.
*
* Expose `debug()` as the module.
*/
exports = module.exports = require('./debug');
exports.log = log;
exports.formatArgs = formatArgs;
exports.save = save;
exports.load = load;
exports.useColors = useColors;
/**
* Colors.
*/
exports.colors = [6, 2, 3, 4, 5, 1];
/**
* The file descriptor to write the `debug()` calls to.
* Set the `DEBUG_FD` env variable to override with another value. i.e.:
*
* $ DEBUG_FD=3 node script.js 3>debug.log
*/
var fd = parseInt(process.env.DEBUG_FD, 10) || 2;
var stream = 1 === fd ? process.stdout :
2 === fd ? process.stderr :
createWritableStdioStream(fd);
/**
* Is stdout a TTY? Colored output is enabled when `true`.
*/
function useColors() {
var debugColors = (process.env.DEBUG_COLORS || '').trim().toLowerCase();
if (0 === debugColors.length) {
return tty.isatty(fd);
} else {
return '0' !== debugColors
&& 'no' !== debugColors
&& 'false' !== debugColors
&& 'disabled' !== debugColors;
}
}
/**
* Map %o to `util.inspect()`, since Node doesn't do that out of the box.
*/
var inspect = (4 === util.inspect.length ?
// node <= 0.8.x
function (v, colors) {
return util.inspect(v, void 0, void 0, colors);
} :
// node > 0.8.x
function (v, colors) {
return util.inspect(v, { colors: colors });
}
);
exports.formatters.o = function(v) {
return inspect(v, this.useColors)
.replace(/\s*\n\s*/g, ' ');
};
/**
* Adds ANSI color escape codes if enabled.
*
* @api public
*/
function formatArgs() {
var args = arguments;
var useColors = this.useColors;
var name = this.namespace;
if (useColors) {
var c = this.color;
args[0] = ' \u001b[3' + c + ';1m' + name + ' '
+ '\u001b[0m'
+ args[0] + '\u001b[3' + c + 'm'
+ ' +' + exports.humanize(this.diff) + '\u001b[0m';
} else {
args[0] = new Date().toUTCString()
+ ' ' + name + ' ' + args[0];
}
return args;
}
/**
* Invokes `console.error()` with the specified arguments.
*/
function log() {
return stream.write(util.format.apply(this, arguments) + '\n');
}
/**
* Save `namespaces`.
*
* @param {String} namespaces
* @api private
*/
function save(namespaces) {
if (null == namespaces) {
// If you set a process.env field to null or undefined, it gets cast to the
// string 'null' or 'undefined'. Just delete instead.
delete process.env.DEBUG;
} else {
process.env.DEBUG = namespaces;
}
}
/**
* Load `namespaces`.
*
* @return {String} returns the previously persisted debug modes
* @api private
*/
function load() {
return process.env.DEBUG;
}
/**
* Copied from `node/src/node.js`.
*
* XXX: It's lame that node doesn't expose this API out-of-the-box. It also
* relies on the undocumented `tty_wrap.guessHandleType()` which is also lame.
*/
function createWritableStdioStream (fd) {
var stream;
var tty_wrap = process.binding('tty_wrap');
// Note stream._type is used for test-module-load-list.js
switch (tty_wrap.guessHandleType(fd)) {
case 'TTY':
stream = new tty.WriteStream(fd);
stream._type = 'tty';
// Hack to have stream not keep the event loop alive.
// See https://github.com/joyent/node/issues/1726
if (stream._handle && stream._handle.unref) {
stream._handle.unref();
}
break;
case 'FILE':
var fs = require('fs');
stream = new fs.SyncWriteStream(fd, { autoClose: false });
stream._type = 'fs';
break;
case 'PIPE':
case 'TCP':
var net = require('net');
stream = new net.Socket({
fd: fd,
readable: false,
writable: true
});
// FIXME Should probably have an option in net.Socket to create a
// stream from an existing fd which is writable only. But for now
// we'll just add this hack and set the `readable` member to false.
// Test: ./node test/fixtures/echo.js < /etc/passwd
stream.readable = false;
stream.read = null;
stream._type = 'pipe';
// FIXME Hack to have stream not keep the event loop alive.
// See https://github.com/joyent/node/issues/1726
if (stream._handle && stream._handle.unref) {
stream._handle.unref();
}
break;
default:
// Probably an error on in uv_guess_handle()
throw new Error('Implement me. Unknown stream file type!');
}
// For supporting legacy API we put the FD here.
stream.fd = fd;
stream._isStdio = true;
return stream;
}
/**
* Enable namespaces listed in `process.env.DEBUG` initially.
*/
exports.enable(load());
/**
* Helpers.
*/
var s = 1000;
var m = s * 60;
var h = m * 60;
var d = h * 24;
var y = d * 365.25;
/**
* Parse or format the given `val`.
*
* Options:
*
* - `long` verbose formatting [false]
*
* @param {String|Number} val
* @param {Object} options
* @return {String|Number}
* @api public
*/
module.exports = function(val, options){
options = options || {};
if ('string' == typeof val) return parse(val);
return options.long
? long(val)
: short(val);
};
/**
* Parse the given `str` and return milliseconds.
*
* @param {String} str
* @return {Number}
* @api private
*/
function parse(str) {
var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(str);
if (!match) return;
var n = parseFloat(match[1]);
var type = (match[2] || 'ms').toLowerCase();
switch (type) {
case 'years':
case 'year':
case 'yrs':
case 'yr':
case 'y':
return n * y;
case 'days':
case 'day':
case 'd':
return n * d;
case 'hours':
case 'hour':
case 'hrs':
case 'hr':
case 'h':
return n * h;
case 'minutes':
case 'minute':
case 'mins':
case 'min':
case 'm':
return n * m;
case 'seconds':
case 'second':
case 'secs':
case 'sec':
case 's':
return n * s;
case 'milliseconds':
case 'millisecond':
case 'msecs':
case 'msec':
case 'ms':
return n;
}
}
/**
* Short format for `ms`.
*
* @param {Number} ms
* @return {String}
* @api private
*/
function short(ms) {
if (ms >= d) return Math.round(ms / d) + 'd';
if (ms >= h) return Math.round(ms / h) + 'h';
if (ms >= m) return Math.round(ms / m) + 'm';
if (ms >= s) return Math.round(ms / s) + 's';
return ms + 'ms';
}
/**
* Long format for `ms`.
*
* @param {Number} ms
* @return {String}
* @api private
*/
function long(ms) {
return plural(ms, d, 'day')
|| plural(ms, h, 'hour')
|| plural(ms, m, 'minute')
|| plural(ms, s, 'second')
|| ms + ' ms';
}
/**
* Pluralization helper.
*/
function plural(ms, n, name) {
if (ms < n) return;
if (ms < n * 1.5) return Math.floor(ms / n) + ' ' + name;
return Math.ceil(ms / n) + ' ' + name + 's';
}
(The MIT License)
Copyright (c) 2014 Guillermo Rauch <rauchg@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
{
"name": "ms",
"version": "0.7.0",
"description": "Tiny ms conversion utility",
"repository": {
"type": "git",
"url": "git://github.com/guille/ms.js.git"
},
"main": "./index",
"devDependencies": {
"mocha": "*",
"expect.js": "*",
"serve": "*"
},
"component": {
"scripts": {
"ms/index.js": "index.js"
}
},
"gitHead": "1e9cd9b05ef0dc26f765434d2bfee42394376e52",
"bugs": {
"url": "https://github.com/guille/ms.js/issues"
},
"homepage": "https://github.com/guille/ms.js",
"_id": "ms@0.7.0",
"scripts": {},
"_shasum": "865be94c2e7397ad8a57da6a633a6e2f30798b83",
"_from": "ms@0.7.0",
"_npmVersion": "1.4.21",
"_npmUser": {
"name": "rauchg",
"email": "rauchg@gmail.com"
},
"maintainers": [
{
"name": "rauchg",
"email": "rauchg@gmail.com"
}
],
"dist": {
"shasum": "865be94c2e7397ad8a57da6a633a6e2f30798b83",
"tarball": "http://registry.npmjs.org/ms/-/ms-0.7.0.tgz"
},
"directories": {},
"_resolved": "https://registry.npmjs.org/ms/-/ms-0.7.0.tgz",
"readme": "ERROR: No README data found!"
}

ms.js: miliseconds conversion utility

ms('2 days')  // 172800000
ms('1d')      // 86400000
ms('10h')     // 36000000
ms('2.5 hrs') // 9000000
ms('2h')      // 7200000
ms('1m')      // 60000
ms('5s')      // 5000
ms('100')     // 100
ms(60000)             // "1m"
ms(2 * 60000)         // "2m"
ms(ms('10 hours'))    // "10h"
ms(60000, { long: true })             // "1 minute"
ms(2 * 60000, { long: true })         // "2 minutes"
ms(ms('10 hours'), { long: true })    // "10 hours"
  • Node/Browser compatible. Published as ms in NPM.
  • If a number is supplied to ms, a string with a unit is returned.
  • If a string that contains the number is supplied, it returns it as a number (e.g: it returns 100 for '100').
  • If you pass a string with a number and a valid unit, the number of equivalent ms is returned.

License

MIT

{
"name": "debug",
"version": "2.1.3",
"repository": {
"type": "git",
"url": "git://github.com/visionmedia/debug.git"
},
"description": "small debugging utility",
"keywords": [
"debug",
"log",
"debugger"
],
"author": {
"name": "TJ Holowaychuk",
"email": "tj@vision-media.ca"
},
"contributors": [
{
"name": "Nathan Rajlich",
"email": "nathan@tootallnate.net",
"url": "http://n8.io"
}
],
"license": "MIT",
"dependencies": {
"ms": "0.7.0"
},
"devDependencies": {
"browserify": "9.0.3",
"mocha": "*"
},
"main": "./node.js",
"browser": "./browser.js",
"component": {
"scripts": {
"debug/index.js": "browser.js",
"debug/debug.js": "debug.js"
}
},
"gitHead": "0a8e4b7e0d2d1b55ef4e7422498ca24c677ae63a",
"bugs": {
"url": "https://github.com/visionmedia/debug/issues"
},
"homepage": "https://github.com/visionmedia/debug",
"_id": "debug@2.1.3",
"scripts": {},
"_shasum": "ce8ab1b5ee8fbee2bfa3b633cab93d366b63418e",
"_from": "debug@>=2.1.3 <2.2.0",
"_npmVersion": "2.5.1",
"_nodeVersion": "0.12.0",
"_npmUser": {
"name": "tootallnate",
"email": "nathan@tootallnate.net"
},
"maintainers": [
{
"name": "tjholowaychuk",
"email": "tj@vision-media.ca"
},
{
"name": "tootallnate",
"email": "nathan@tootallnate.net"
}
],
"dist": {
"shasum": "ce8ab1b5ee8fbee2bfa3b633cab93d366b63418e",
"tarball": "http://registry.npmjs.org/debug/-/debug-2.1.3.tgz"
},
"directories": {},
"_resolved": "https://registry.npmjs.org/debug/-/debug-2.1.3.tgz",
"readme": "ERROR: No README data found!"
}

debug

tiny node.js debugging utility modelled after node core's debugging technique.

Installation

$ npm install debug

Usage

With debug you simply invoke the exported function to generate your debug function, passing it a name which will determine if a noop function is returned, or a decorated console.error, so all of the console format string goodies you're used to work fine. A unique color is selected per-function for visibility.

Example app.js:

var debug = require('debug')('http')
  , http = require('http')
  , name = 'My App';

// fake app

debug('booting %s', name);

http.createServer(function(req, res){
  debug(req.method + ' ' + req.url);
  res.end('hello\n');
}).listen(3000, function(){
  debug('listening');
});

// fake worker of some kind

require('./worker');

Example worker.js:

var debug = require('debug')('worker');

setInterval(function(){
  debug('doing some work');
}, 1000);

The DEBUG environment variable is then used to enable these based on space or comma-delimited names. Here are some examples:

debug http and worker

debug worker

Windows note

On Windows the environment variable is set using the set command.

set DEBUG=*,-not_this

Then, run the program to be debugged as usual.

Millisecond diff

When actively developing an application it can be useful to see when the time spent between one debug() call and the next. Suppose for example you invoke debug() before requesting a resource, and after as well, the "+NNNms" will show you how much time was spent between calls.

When stdout is not a TTY, Date#toUTCString() is used, making it more useful for logging the debug information as shown below:

Conventions

If you're using this in one or more of your libraries, you should use the name of your library so that developers may toggle debugging as desired without guessing names. If you have more than one debuggers you should prefix them with your library name and use ":" to separate features. For example "bodyParser" from Connect would then be "connect:bodyParser".

Wildcards

The * character may be used as a wildcard. Suppose for example your library has debuggers named "connect:bodyParser", "connect:compress", "connect:session", instead of listing all three with DEBUG=connect:bodyParser,connect.compress,connect:session, you may simply do DEBUG=connect:*, or to run everything using this module simply use DEBUG=*.

You can also exclude specific debuggers by prefixing them with a "-" character. For example, DEBUG=*,-connect:* would include all debuggers except those starting with "connect:".

Browser support

Debug works in the browser as well, currently persisted by localStorage. Consider the situation shown below where you have worker:a and worker:b, and wish to debug both. Somewhere in the code on your page, include:

window.myDebug = require("debug");

("debug" is a global object in the browser so we give this object a different name.) When your page is open in the browser, type the following in the console:

myDebug.enable("worker:*")

Refresh the page. Debug output will continue to be sent to the console until it is disabled by typing myDebug.disable() in the console.

a = debug('worker:a');
b = debug('worker:b');

setInterval(function(){
  a('doing some work');
}, 1000);

setInterval(function(){
  b('doing some work');
}, 1200);

Web Inspector Colors

Colors are also enabled on "Web Inspectors" that understand the %c formatting option. These are WebKit web inspectors, Firefox (since version 31) and the Firebug plugin for Firefox (any version).

Colored output looks something like:

stderr vs stdout

You can set an alternative logging method per-namespace by overriding the log method on a per-namespace or globally:

Example stdout.js:

var debug = require('debug');
var error = debug('app:error');

// by default stderr is used
error('goes to stderr!');

var log = debug('app:log');
// set this namespace to log via console.log
log.log = console.log.bind(console); // don't forget to bind to console!
log('goes to stdout');
error('still goes to stderr!');

// set all output to go via console.info
// overrides all per-namespace log settings
debug.log = console.info.bind(console);
error('now goes to stdout via console.info');
log('still goes to stdout, but via console.info now');

Authors

  • TJ Holowaychuk
  • Nathan Rajlich

License

(The MIT License)

Copyright (c) 2014 TJ Holowaychuk <tj@vision-media.ca>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

1.0.0 / 2014-09-17

  • No changes

0.4.5 / 2014-09-09

  • Improve call speed to functions using the function wrapper
  • Support Node.js 0.6

0.4.4 / 2014-07-27

  • Work-around v8 generating empty stack traces

0.4.3 / 2014-07-26

  • Fix exception when global Error.stackTraceLimit is too low

0.4.2 / 2014-07-19

  • Correct call site for wrapped functions and properties

0.4.1 / 2014-07-19

  • Improve automatic message generation for function properties

0.4.0 / 2014-07-19

  • Add TRACE_DEPRECATION environment variable
  • Remove non-standard grey color from color output
  • Support --no-deprecation argument
  • Support --trace-deprecation argument
  • Support deprecate.property(fn, prop, message)

0.3.0 / 2014-06-16

  • Add NO_DEPRECATION environment variable

0.2.0 / 2014-06-15

  • Add deprecate.property(obj, prop, message)
  • Remove supports-color dependency for node.js 0.8

0.1.0 / 2014-06-15

  • Add deprecate.function(fn, message)
  • Add process.on('deprecation', fn) emitter
  • Automatically generate message when omitted from deprecate()

0.0.1 / 2014-06-15

  • Fix warning for dynamic calls at singe call site

0.0.0 / 2014-06-15

  • Initial implementation
/*!
* depd
* Copyright(c) 2014 Douglas Christopher Wilson
* MIT Licensed
*/
/**
* Module dependencies.
*/
var callSiteToString = require('./lib/compat').callSiteToString
var EventEmitter = require('events').EventEmitter
var relative = require('path').relative
/**
* Module exports.
*/
module.exports = depd
/**
* Get the path to base files on.
*/
var basePath = process.cwd()
/**
* Get listener count on event emitter.
*/
/*istanbul ignore next*/
var eventListenerCount = EventEmitter.listenerCount
|| function (emitter, type) { return emitter.listeners(type).length }
/**
* Determine if namespace is contained in the string.
*/
function containsNamespace(str, namespace) {
var val = str.split(/[ ,]+/)
namespace = String(namespace).toLowerCase()
for (var i = 0 ; i < val.length; i++) {
if (!(str = val[i])) continue;
// namespace contained
if (str === '*' || str.toLowerCase() === namespace) {
return true
}
}
return false
}
/**
* Convert a data descriptor to accessor descriptor.
*/
function convertDataDescriptorToAccessor(obj, prop, message) {
var descriptor = Object.getOwnPropertyDescriptor(obj, prop)
var value = descriptor.value
descriptor.get = function getter() { return value }
if (descriptor.writable) {
descriptor.set = function setter(val) { return value = val }
}
delete descriptor.value
delete descriptor.writable
Object.defineProperty(obj, prop, descriptor)
return descriptor
}
/**
* Create arguments string to keep arity.
*/
function createArgumentsString(arity) {
var str = ''
for (var i = 0; i < arity; i++) {
str += ', arg' + i
}
return str.substr(2)
}
/**
* Create stack string from stack.
*/
function createStackString(stack) {
var str = this.name + ': ' + this.namespace
if (this.message) {
str += ' deprecated ' + this.message
}
for (var i = 0; i < stack.length; i++) {
str += '\n at ' + callSiteToString(stack[i])
}
return str
}
/**
* Create deprecate for namespace in caller.
*/
function depd(namespace) {
if (!namespace) {
throw new TypeError('argument namespace is required')
}
var stack = getStack()
var site = callSiteLocation(stack[1])
var file = site[0]
function deprecate(message) {
// call to self as log
log.call(deprecate, message)
}
deprecate._file = file
deprecate._ignored = isignored(namespace)
deprecate._namespace = namespace
deprecate._traced = istraced(namespace)
deprecate._warned = Object.create(null)
deprecate.function = wrapfunction
deprecate.property = wrapproperty
return deprecate
}
/**
* Determine if namespace is ignored.
*/
function isignored(namespace) {
/* istanbul ignore next: tested in a child processs */
if (process.noDeprecation) {
// --no-deprecation support
return true
}
var str = process.env.NO_DEPRECATION || ''
// namespace ignored
return containsNamespace(str, namespace)
}
/**
* Determine if namespace is traced.
*/
function istraced(namespace) {
/* istanbul ignore next: tested in a child processs */
if (process.traceDeprecation) {
// --trace-deprecation support
return true
}
var str = process.env.TRACE_DEPRECATION || ''
// namespace traced
return containsNamespace(str, namespace)
}
/**
* Display deprecation message.
*/
function log(message, site) {
var haslisteners = eventListenerCount(process, 'deprecation') !== 0
// abort early if no destination
if (!haslisteners && this._ignored) {
return
}
var caller
var callFile
var callSite
var i = 0
var seen = false
var stack = getStack()
var file = this._file
if (site) {
// provided site
callSite = callSiteLocation(stack[1])
callSite.name = site.name
file = callSite[0]
} else {
// get call site
i = 2
site = callSiteLocation(stack[i])
callSite = site
}
// get caller of deprecated thing in relation to file
for (; i < stack.length; i++) {
caller = callSiteLocation(stack[i])
callFile = caller[0]
if (callFile === file) {
seen = true
} else if (callFile === this._file) {
file = this._file
} else if (seen) {
break
}
}
var key = caller
? site.join(':') + '__' + caller.join(':')
: undefined
if (key !== undefined && key in this._warned) {
// already warned
return
}
this._warned[key] = true
// generate automatic message from call site
if (!message) {
message = callSite === site || !callSite.name
? defaultMessage(site)
: defaultMessage(callSite)
}
// emit deprecation if listeners exist
if (haslisteners) {
var err = DeprecationError(this._namespace, message, stack.slice(i))
process.emit('deprecation', err)
return
}
// format and write message
var format = process.stderr.isTTY
? formatColor
: formatPlain
var msg = format.call(this, message, caller, stack.slice(i))
process.stderr.write(msg + '\n', 'utf8')
return
}
/**
* Get call site location as array.
*/
function callSiteLocation(callSite) {
var file = callSite.getFileName() || '<anonymous>'
var line = callSite.getLineNumber()
var colm = callSite.getColumnNumber()
if (callSite.isEval()) {
file = callSite.getEvalOrigin() + ', ' + file
}
var site = [file, line, colm]
site.callSite = callSite
site.name = callSite.getFunctionName()
return site
}
/**
* Generate a default message from the site.
*/
function defaultMessage(site) {
var callSite = site.callSite
var funcName = site.name
var typeName = callSite.getTypeName()
// make useful anonymous name
if (!funcName) {
funcName = '<anonymous@' + formatLocation(site) + '>'
}
// make useful type name
if (typeName === 'Function') {
typeName = callSite.getThis().name || typeName
}
return callSite.getMethodName()
? typeName + '.' + funcName
: funcName
}
/**
* Format deprecation message without color.
*/
function formatPlain(msg, caller, stack) {
var timestamp = new Date().toUTCString()
var formatted = timestamp
+ ' ' + this._namespace
+ ' deprecated ' + msg
// add stack trace
if (this._traced) {
for (var i = 0; i < stack.length; i++) {
formatted += '\n at ' + callSiteToString(stack[i])
}
return formatted
}
if (caller) {
formatted += ' at ' + formatLocation(caller)
}
return formatted
}
/**
* Format deprecation message with color.
*/
function formatColor(msg, caller, stack) {
var formatted = '\x1b[36;1m' + this._namespace + '\x1b[22;39m' // bold cyan
+ ' \x1b[33;1mdeprecated\x1b[22;39m' // bold yellow
+ ' \x1b[0m' + msg + '\x1b[39m' // reset
// add stack trace
if (this._traced) {
for (var i = 0; i < stack.length; i++) {
formatted += '\n \x1b[36mat ' + callSiteToString(stack[i]) + '\x1b[39m' // cyan
}
return formatted
}
if (caller) {
formatted += ' \x1b[36m' + formatLocation(caller) + '\x1b[39m' // cyan
}
return formatted
}
/**
* Format call site location.
*/
function formatLocation(callSite) {
return relative(basePath, callSite[0])
+ ':' + callSite[1]
+ ':' + callSite[2]
}
/**
* Get the stack as array of call sites.
*/
function getStack() {
var limit = Error.stackTraceLimit
var obj = {}
var prep = Error.prepareStackTrace
Error.prepareStackTrace = prepareObjectStackTrace
Error.stackTraceLimit = Math.max(10, limit)
// capture the stack
Error.captureStackTrace(obj)
// slice this function off the top
var stack = obj.stack.slice(1)
Error.prepareStackTrace = prep
Error.stackTraceLimit = limit
return stack
}
/**
* Capture call site stack from v8.
*/
function prepareObjectStackTrace(obj, stack) {
return stack
}
/**
* Return a wrapped function in a deprecation message.
*/
function wrapfunction(fn, message) {
if (typeof fn !== 'function') {
throw new TypeError('argument fn must be a function')
}
var args = createArgumentsString(fn.length)
var deprecate = this
var stack = getStack()
var site = callSiteLocation(stack[1])
site.name = fn.name
var deprecatedfn = eval('(function (' + args + ') {\n'
+ '"use strict"\n'
+ 'log.call(deprecate, message, site)\n'
+ 'return fn.apply(this, arguments)\n'
+ '})')
return deprecatedfn
}
/**
* Wrap property in a deprecation message.
*/
function wrapproperty(obj, prop, message) {
if (!obj || (typeof obj !== 'object' && typeof obj !== 'function')) {
throw new TypeError('argument obj must be object')
}
var descriptor = Object.getOwnPropertyDescriptor(obj, prop)
if (!descriptor) {
throw new TypeError('must call property on owner object')
}
if (!descriptor.configurable) {
throw new TypeError('property must be configurable')
}
var deprecate = this
var stack = getStack()
var site = callSiteLocation(stack[1])
// set site name
site.name = prop
// convert data descriptor
if ('value' in descriptor) {
descriptor = convertDataDescriptorToAccessor(obj, prop, message)
}
var get = descriptor.get
var set = descriptor.set
// wrap getter
if (typeof get === 'function') {
descriptor.get = function getter() {
log.call(deprecate, message, site)
return get.apply(this, arguments)
}
}
// wrap setter
if (typeof set === 'function') {
descriptor.set = function setter() {
log.call(deprecate, message, site)
return set.apply(this, arguments)
}
}
Object.defineProperty(obj, prop, descriptor)
}
/**
* Create DeprecationError for deprecation
*/
function DeprecationError(namespace, message, stack) {
var error = new Error()
var stackString
Object.defineProperty(error, 'constructor', {
value: DeprecationError
})
Object.defineProperty(error, 'message', {
configurable: true,
enumerable: false,
value: message,
writable: true
})
Object.defineProperty(error, 'name', {
enumerable: false,
configurable: true,
value: 'DeprecationError',
writable: true
})
Object.defineProperty(error, 'namespace', {
configurable: true,
enumerable: false,
value: namespace,
writable: true
})
Object.defineProperty(error, 'stack', {
configurable: true,
enumerable: false,
get: function () {
if (stackString !== undefined) {
return stackString
}
// prepare stack trace
return stackString = createStackString.call(this, stack)
},
set: function setter(val) {
stackString = val
}
})
return error
}
/*!
* depd
* Copyright(c) 2014 Douglas Christopher Wilson
* MIT Licensed
*/
/**
* Module exports.
*/
module.exports = bufferConcat
/**
* Concatenate an array of Buffers.
*/
function bufferConcat(bufs) {
var length = 0
for (var i = 0, len = bufs.length; i < len; i++) {
length += bufs[i].length
}
var buf = new Buffer(length)
var pos = 0
for (var i = 0, len = bufs.length; i < len; i++) {
bufs[i].copy(buf, pos)
pos += bufs[i].length
}
return buf
}
/*!
* depd
* Copyright(c) 2014 Douglas Christopher Wilson
* MIT Licensed
*/
/**
* Module exports.
*/
module.exports = callSiteToString
/**
* Format a CallSite file location to a string.
*/
function callSiteFileLocation(callSite) {
var fileName
var fileLocation = ''
if (callSite.isNative()) {
fileLocation = 'native'
} else if (callSite.isEval()) {
fileName = callSite.getScriptNameOrSourceURL()
if (!fileName) {
fileLocation = callSite.getEvalOrigin()
}
} else {
fileName = callSite.getFileName()
}
if (fileName) {
fileLocation += fileName
var lineNumber = callSite.getLineNumber()
if (lineNumber != null) {
fileLocation += ':' + lineNumber
var columnNumber = callSite.getColumnNumber()
if (columnNumber) {
fileLocation += ':' + columnNumber
}
}
}
return fileLocation || 'unknown source'
}
/**
* Format a CallSite to a string.
*/
function callSiteToString(callSite) {
var addSuffix = true
var fileLocation = callSiteFileLocation(callSite)
var functionName = callSite.getFunctionName()
var isConstructor = callSite.isConstructor()
var isMethodCall = !(callSite.isToplevel() || isConstructor)
var line = ''
if (isMethodCall) {
var methodName = callSite.getMethodName()
var typeName = getConstructorName(callSite)
if (functionName) {
if (typeName && functionName.indexOf(typeName) !== 0) {
line += typeName + '.'
}
line += functionName
if (methodName && functionName.lastIndexOf('.' + methodName) !== functionName.length - methodName.length - 1) {
line += ' [as ' + methodName + ']'
}
} else {
line += typeName + '.' + (methodName || '<anonymous>')
}
} else if (isConstructor) {
line += 'new ' + (functionName || '<anonymous>')
} else if (functionName) {
line += functionName
} else {
addSuffix = false
line += fileLocation
}
if (addSuffix) {
line += ' (' + fileLocation + ')'
}
return line
}
/**
* Get constructor name of reviver.
*/
function getConstructorName(obj) {
var receiver = obj.receiver
return (receiver.constructor && receiver.constructor.name) || null
}
/*!
* depd
* Copyright(c) 2014 Douglas Christopher Wilson
* MIT Licensed
*/
/**
* Module exports.
*/
lazyProperty(module.exports, 'bufferConcat', function bufferConcat() {
return Buffer.concat || require('./buffer-concat')
})
lazyProperty(module.exports, 'callSiteToString', function callSiteToString() {
var limit = Error.stackTraceLimit
var obj = {}
var prep = Error.prepareStackTrace
function prepareObjectStackTrace(obj, stack) {
return stack
}
Error.prepareStackTrace = prepareObjectStackTrace
Error.stackTraceLimit = 2
// capture the stack
Error.captureStackTrace(obj)
// slice the stack
var stack = obj.stack.slice()
Error.prepareStackTrace = prep
Error.stackTraceLimit = limit
return stack[0].toString ? toString : require('./callsite-tostring')
})
/**
* Define a lazy property.
*/
function lazyProperty(obj, prop, getter) {
function get() {
var val = getter()
Object.defineProperty(obj, prop, {
configurable: true,
enumerable: true,
value: val
})
return val
}
Object.defineProperty(obj, prop, {
configurable: true,
enumerable: true,
get: get
})
}
/**
* Call toString() on the obj
*/
function toString(obj) {
return obj.toString()
}
(The MIT License)
Copyright (c) 2014 Douglas Christopher Wilson
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
{
"name": "depd",
"description": "Deprecate all the things",
"version": "1.0.0",
"author": {
"name": "Douglas Christopher Wilson",
"email": "doug@somethingdoug.com"
},
"license": "MIT",
"keywords": [
"deprecate",
"deprecated"
],
"repository": {
"type": "git",
"url": "https://github.com/dougwilson/nodejs-depd"
},
"devDependencies": {
"benchmark": "1.0.0",
"beautify-benchmark": "0.2.4",
"istanbul": "0.3.2",
"mocha": "~1.21.4",
"should": "~4.0.4"
},
"files": [
"lib/",
"History.md",
"LICENSE",
"index.js",
"Readme.md"
],
"engines": {
"node": ">= 0.6"
},
"scripts": {
"bench": "node benchmark/index.js",
"test": "mocha --reporter spec --bail --require should test/",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --require should test/",
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --require should test/"
},
"readme": "# depd\n\n[![NPM Version][npm-version-image]][npm-url]\n[![NPM Downloads][npm-downloads-image]][npm-url]\n[![Node.js Version][node-image]][node-url]\n[![Build Status][travis-image]][travis-url]\n[![Coverage Status][coveralls-image]][coveralls-url]\n[![Gratipay][gratipay-image]][gratipay-url]\n\nDeprecate all the things\n\n> With great modules comes great responsibility; mark things deprecated!\n\n## Install\n\n```sh\n$ npm install depd\n```\n\n## API\n\n```js\nvar deprecate = require('depd')('my-module')\n```\n\nThis library allows you to display deprecation messages to your users.\nThis library goes above and beyond with deprecation warnings by\nintrospection of the call stack (but only the bits that it is interested\nin).\n\nInstead of just warning on the first invocation of a deprecated\nfunction and never again, this module will warn on the first invocation\nof a deprecated function per unique call site, making it ideal to alert\nusers of all deprecated uses across the code base, rather than just\nwhatever happens to execute first.\n\nThe deprecation warnings from this module also include the file and line\ninformation for the call into the module that the deprecated function was\nin.\n\n**NOTE** this library has a similar interface to the `debug` module, and\nthis module uses the calling file to get the boundary for the call stacks,\nso you should always create a new `deprecate` object in each file and not\nwithin some central file.\n\n### depd(namespace)\n\nCreate a new deprecate function that uses the given namespace name in the\nmessages and will display the call site prior to the stack entering the\nfile this function was called from. It is highly suggested you use the\nname of your module as the namespace.\n\n### deprecate(message)\n\nCall this function from deprecated code to display a deprecation message.\nThis message will appear once per unique caller site. Caller site is the\nfirst call site in the stack in a different file from the caller of this\nfunction.\n\nIf the message is omitted, a message is generated for you based on the site\nof the `deprecate()` call and will display the name of the function called,\nsimilar to the name displayed in a stack trace.\n\n### deprecate.function(fn, message)\n\nCall this function to wrap a given function in a deprecation message on any\ncall to the function. An optional message can be supplied to provide a custom\nmessage.\n\n### deprecate.property(obj, prop, message)\n\nCall this function to wrap a given property on object in a deprecation message\non any accessing or setting of the property. An optional message can be supplied\nto provide a custom message.\n\nThe method must be called on the object where the property belongs (not\ninherited from the prototype).\n\nIf the property is a data descriptor, it will be converted to an accessor\ndescriptor in order to display the deprecation message.\n\n### process.on('deprecation', fn)\n\nThis module will allow easy capturing of deprecation errors by emitting the\nerrors as the type \"deprecation\" on the global `process`. If there are no\nlisteners for this type, the errors are written to STDERR as normal, but if\nthere are any listeners, nothing will be written to STDERR and instead only\nemitted. From there, you can write the errors in a different format or to a\nlogging source.\n\nThe error represents the deprecation and is emitted only once with the same\nrules as writing to STDERR. The error has the following properties:\n\n - `message` - This is the message given by the library\n - `name` - This is always `'DeprecationError'`\n - `namespace` - This is the namespace the deprecation came from\n - `stack` - This is the stack of the call to the deprecated thing\n\nExample `error.stack` output:\n\n```\nDeprecationError: my-cool-module deprecated oldfunction\n at Object.<anonymous> ([eval]-wrapper:6:22)\n at Module._compile (module.js:456:26)\n at evalScript (node.js:532:25)\n at startup (node.js:80:7)\n at node.js:902:3\n```\n\n### process.env.NO_DEPRECATION\n\nAs a user of modules that are deprecated, the environment variable `NO_DEPRECATION`\nis provided as a quick solution to silencing deprecation warnings from being\noutput. The format of this is similar to that of `DEBUG`:\n\n```sh\n$ NO_DEPRECATION=my-module,othermod node app.js\n```\n\nThis will suppress deprecations from being output for \"my-module\" and \"othermod\".\nThe value is a list of comma-separated namespaces. To suppress every warning\nacross all namespaces, use the value `*` for a namespace.\n\nProviding the argument `--no-deprecation` to the `node` executable will suppress\nall deprecations (only available in Node.js 0.8 or higher).\n\n**NOTE** This will not suppress the deperecations given to any \"deprecation\"\nevent listeners, just the output to STDERR.\n\n### process.env.TRACE_DEPRECATION\n\nAs a user of modules that are deprecated, the environment variable `TRACE_DEPRECATION`\nis provided as a solution to getting more detailed location information in deprecation\nwarnings by including the entire stack trace. The format of this is the same as\n`NO_DEPRECATION`:\n\n```sh\n$ TRACE_DEPRECATION=my-module,othermod node app.js\n```\n\nThis will include stack traces for deprecations being output for \"my-module\" and\n\"othermod\". The value is a list of comma-separated namespaces. To trace every\nwarning across all namespaces, use the value `*` for a namespace.\n\nProviding the argument `--trace-deprecation` to the `node` executable will trace\nall deprecations (only available in Node.js 0.8 or higher).\n\n**NOTE** This will not trace the deperecations silenced by `NO_DEPRECATION`.\n\n## Display\n\n![message](files/message.png)\n\nWhen a user calls a function in your library that you mark deprecated, they\nwill see the following written to STDERR (in the given colors, similar colors\nand layout to the `debug` module):\n\n```\nbright cyan bright yellow\n| | reset cyan\n| | | |\n▼ ▼ ▼ ▼\nmy-cool-module deprecated oldfunction [eval]-wrapper:6:22\n▲ ▲ ▲ ▲\n| | | |\nnamespace | | location of mycoolmod.oldfunction() call\n | deprecation message\n the word \"deprecated\"\n```\n\nIf the user redirects their STDERR to a file or somewhere that does not support\ncolors, they see (similar layout to the `debug` module):\n\n```\nSun, 15 Jun 2014 05:21:37 GMT my-cool-module deprecated oldfunction at [eval]-wrapper:6:22\n▲ ▲ ▲ ▲ ▲\n| | | | |\ntimestamp of message namespace | | location of mycoolmod.oldfunction() call\n | deprecation message\n the word \"deprecated\"\n```\n\n## Examples\n\n### Deprecating all calls to a function\n\nThis will display a deprecated message about \"oldfunction\" being deprecated\nfrom \"my-module\" on STDERR.\n\n```js\nvar deprecate = require('depd')('my-cool-module')\n\n// message automatically derived from function name\n// Object.oldfunction\nexports.oldfunction = deprecate.function(function oldfunction() {\n // all calls to function are deprecated\n})\n\n// specific message\nexports.oldfunction = deprecate.function(function () {\n // all calls to function are deprecated\n}, 'oldfunction')\n```\n\n### Conditionally deprecating a function call\n\nThis will display a deprecated message about \"weirdfunction\" being deprecated\nfrom \"my-module\" on STDERR when called with less than 2 arguments.\n\n```js\nvar deprecate = require('depd')('my-cool-module')\n\nexports.weirdfunction = function () {\n if (arguments.length < 2) {\n // calls with 0 or 1 args are deprecated\n deprecate('weirdfunction args < 2')\n }\n}\n```\n\nWhen calling `deprecate` as a function, the warning is counted per call site\nwithin your own module, so you can display different deprecations depending\non different situations and the users will still get all the warnings:\n\n```js\nvar deprecate = require('depd')('my-cool-module')\n\nexports.weirdfunction = function () {\n if (arguments.length < 2) {\n // calls with 0 or 1 args are deprecated\n deprecate('weirdfunction args < 2')\n } else if (typeof arguments[0] !== 'string') {\n // calls with non-string first argument are deprecated\n deprecate('weirdfunction non-string first arg')\n }\n}\n```\n\n### Deprecating property access\n\nThis will display a deprecated message about \"oldprop\" being deprecated\nfrom \"my-module\" on STDERR when accessed. A deprecation will be displayed\nwhen setting the value and when getting the value.\n\n```js\nvar deprecate = require('depd')('my-cool-module')\n\nexports.oldprop = 'something'\n\n// message automatically derives from property name\ndeprecate.property(exports, 'oldprop')\n\n// explicit message\ndeprecate.property(exports, 'oldprop', 'oldprop >= 0.10')\n```\n\n## License\n\n[MIT](LICENSE)\n\n[npm-version-image]: https://img.shields.io/npm/v/depd.svg?style=flat\n[npm-downloads-image]: https://img.shields.io/npm/dm/depd.svg?style=flat\n[npm-url]: https://npmjs.org/package/depd\n[travis-image]: https://img.shields.io/travis/dougwilson/nodejs-depd.svg?style=flat\n[travis-url]: https://travis-ci.org/dougwilson/nodejs-depd\n[coveralls-image]: https://img.shields.io/coveralls/dougwilson/nodejs-depd.svg?style=flat\n[coveralls-url]: https://coveralls.io/r/dougwilson/nodejs-depd?branch=master\n[node-image]: https://img.shields.io/node/v/depd.svg?style=flat\n[node-url]: http://nodejs.org/download/\n[gratipay-image]: https://img.shields.io/gratipay/dougwilson.svg?style=flat\n[gratipay-url]: https://www.gratipay.com/dougwilson/\n",
"readmeFilename": "Readme.md",
"bugs": {
"url": "https://github.com/dougwilson/nodejs-depd/issues"
},
"homepage": "https://github.com/dougwilson/nodejs-depd",
"_id": "depd@1.0.0",
"_shasum": "2fda0d00e98aae2845d4991ab1bf1f2a199073d5",
"_resolved": "https://registry.npmjs.org/depd/-/depd-1.0.0.tgz",
"_from": "depd@>=1.0.0 <1.1.0"
}

depd

NPM Version NPM Downloads Node.js Version Build Status Coverage Status Gratipay

Deprecate all the things

With great modules comes great responsibility; mark things deprecated!

Install

$ npm install depd

API

var deprecate = require('depd')('my-module')

This library allows you to display deprecation messages to your users. This library goes above and beyond with deprecation warnings by introspection of the call stack (but only the bits that it is interested in).

Instead of just warning on the first invocation of a deprecated function and never again, this module will warn on the first invocation of a deprecated function per unique call site, making it ideal to alert users of all deprecated uses across the code base, rather than just whatever happens to execute first.

The deprecation warnings from this module also include the file and line information for the call into the module that the deprecated function was in.

NOTE this library has a similar interface to the debug module, and this module uses the calling file to get the boundary for the call stacks, so you should always create a new deprecate object in each file and not within some central file.

depd(namespace)

Create a new deprecate function that uses the given namespace name in the messages and will display the call site prior to the stack entering the file this function was called from. It is highly suggested you use the name of your module as the namespace.

deprecate(message)

Call this function from deprecated code to display a deprecation message. This message will appear once per unique caller site. Caller site is the first call site in the stack in a different file from the caller of this function.

If the message is omitted, a message is generated for you based on the site of the deprecate() call and will display the name of the function called, similar to the name displayed in a stack trace.

deprecate.function(fn, message)

Call this function to wrap a given function in a deprecation message on any call to the function. An optional message can be supplied to provide a custom message.

deprecate.property(obj, prop, message)

Call this function to wrap a given property on object in a deprecation message on any accessing or setting of the property. An optional message can be supplied to provide a custom message.

The method must be called on the object where the property belongs (not inherited from the prototype).

If the property is a data descriptor, it will be converted to an accessor descriptor in order to display the deprecation message.

process.on('deprecation', fn)

This module will allow easy capturing of deprecation errors by emitting the errors as the type "deprecation" on the global process. If there are no listeners for this type, the errors are written to STDERR as normal, but if there are any listeners, nothing will be written to STDERR and instead only emitted. From there, you can write the errors in a different format or to a logging source.

The error represents the deprecation and is emitted only once with the same rules as writing to STDERR. The error has the following properties:

  • message - This is the message given by the library
  • name - This is always 'DeprecationError'
  • namespace - This is the namespace the deprecation came from
  • stack - This is the stack of the call to the deprecated thing

Example error.stack output:

DeprecationError: my-cool-module deprecated oldfunction
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (module.js:456:26)
    at evalScript (node.js:532:25)
    at startup (node.js:80:7)
    at node.js:902:3

process.env.NO_DEPRECATION

As a user of modules that are deprecated, the environment variable NO_DEPRECATION is provided as a quick solution to silencing deprecation warnings from being output. The format of this is similar to that of DEBUG:

$ NO_DEPRECATION=my-module,othermod node app.js

This will suppress deprecations from being output for "my-module" and "othermod". The value is a list of comma-separated namespaces. To suppress every warning across all namespaces, use the value * for a namespace.

Providing the argument --no-deprecation to the node executable will suppress all deprecations (only available in Node.js 0.8 or higher).

NOTE This will not suppress the deperecations given to any "deprecation" event listeners, just the output to STDERR.

process.env.TRACE_DEPRECATION

As a user of modules that are deprecated, the environment variable TRACE_DEPRECATION is provided as a solution to getting more detailed location information in deprecation warnings by including the entire stack trace. The format of this is the same as NO_DEPRECATION:

$ TRACE_DEPRECATION=my-module,othermod node app.js

This will include stack traces for deprecations being output for "my-module" and "othermod". The value is a list of comma-separated namespaces. To trace every warning across all namespaces, use the value * for a namespace.

Providing the argument --trace-deprecation to the node executable will trace all deprecations (only available in Node.js 0.8 or higher).

NOTE This will not trace the deperecations silenced by NO_DEPRECATION.

Display

message

When a user calls a function in your library that you mark deprecated, they will see the following written to STDERR (in the given colors, similar colors and layout to the debug module):

bright cyan    bright yellow
|              |          reset       cyan
|              |          |           |
▼              ▼          ▼           ▼
my-cool-module deprecated oldfunction [eval]-wrapper:6:22
▲              ▲          ▲           ▲
|              |          |           |
namespace      |          |           location of mycoolmod.oldfunction() call
               |          deprecation message
               the word "deprecated"

If the user redirects their STDERR to a file or somewhere that does not support colors, they see (similar layout to the debug module):

Sun, 15 Jun 2014 05:21:37 GMT my-cool-module deprecated oldfunction at [eval]-wrapper:6:22
▲                             ▲              ▲          ▲              ▲
|                             |              |          |              |
timestamp of message          namespace      |          |             location of mycoolmod.oldfunction() call
                                             |          deprecation message
                                             the word "deprecated"

Examples

Deprecating all calls to a function

This will display a deprecated message about "oldfunction" being deprecated from "my-module" on STDERR.

var deprecate = require('depd')('my-cool-module')

// message automatically derived from function name
// Object.oldfunction
exports.oldfunction = deprecate.function(function oldfunction() {
  // all calls to function are deprecated
})

// specific message
exports.oldfunction = deprecate.function(function () {
  // all calls to function are deprecated
}, 'oldfunction')

Conditionally deprecating a function call

This will display a deprecated message about "weirdfunction" being deprecated from "my-module" on STDERR when called with less than 2 arguments.

var deprecate = require('depd')('my-cool-module')

exports.weirdfunction = function () {
  if (arguments.length < 2) {
    // calls with 0 or 1 args are deprecated
    deprecate('weirdfunction args < 2')
  }
}

When calling deprecate as a function, the warning is counted per call site within your own module, so you can display different deprecations depending on different situations and the users will still get all the warnings:

var deprecate = require('depd')('my-cool-module')

exports.weirdfunction = function () {
  if (arguments.length < 2) {
    // calls with 0 or 1 args are deprecated
    deprecate('weirdfunction args < 2')
  } else if (typeof arguments[0] !== 'string') {
    // calls with non-string first argument are deprecated
    deprecate('weirdfunction non-string first arg')
  }
}

Deprecating property access

This will display a deprecated message about "oldprop" being deprecated from "my-module" on STDERR when accessed. A deprecation will be displayed when setting the value and when getting the value.

var deprecate = require('depd')('my-cool-module')

exports.oldprop = 'something'

// message automatically derives from property name
deprecate.property(exports, 'oldprop')

// explicit message
deprecate.property(exports, 'oldprop', 'oldprop >= 0.10')

License

MIT

{
"name": "escape-html",
"description": "Escape HTML entities",
"version": "1.0.1",
"keywords": ["escape", "html", "utility"],
"dependencies": {},
"scripts": [
"index.js"
]
}
/**
* Escape special characters in the given string of html.
*
* @param {String} html
* @return {String}
* @api private
*/
module.exports = function(html) {
return String(html)
.replace(/&/g, '&amp;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#39;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
}
build: components index.js
@component build
components:
@Component install
clean:
rm -fr build components template.js
.PHONY: clean
{
"name": "escape-html",
"description": "Escape HTML entities",
"version": "1.0.1",
"keywords": [
"escape",
"html",
"utility"
],
"dependencies": {},
"main": "index.js",
"component": {
"scripts": {
"escape-html/index.js": "index.js"
}
},
"repository": {
"type": "git",
"url": "https://github.com/component/escape-html.git"
},
"bugs": {
"url": "https://github.com/component/escape-html/issues"
},
"homepage": "https://github.com/component/escape-html",
"_id": "escape-html@1.0.1",
"dist": {
"shasum": "181a286ead397a39a92857cfb1d43052e356bff0",
"tarball": "http://registry.npmjs.org/escape-html/-/escape-html-1.0.1.tgz"
},
"_from": "escape-html@1.0.1",
"_npmVersion": "1.3.15",
"_npmUser": {
"name": "tjholowaychuk",
"email": "tj@vision-media.ca"
},
"maintainers": [
{
"name": "tjholowaychuk",
"email": "tj@vision-media.ca"
}
],
"directories": {},
"_shasum": "181a286ead397a39a92857cfb1d43052e356bff0",
"_resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.1.tgz",
"readme": "ERROR: No README data found!",
"scripts": {}
}

escape-html

Escape HTML entities

Example

var escape = require('escape-html');
escape(str);

License

MIT

1.5.1 / 2014-11-19

  • deps: crc@3.2.1
    • Minor fixes

1.5.0 / 2014-10-14

  • Improve string performance
  • Slightly improve speed for weak ETags over 1KB

1.4.0 / 2014-09-21

  • Support "fake" stats objects
  • Support Node.js 0.6

1.3.1 / 2014-09-14

  • Use the (new and improved) crc for crc32

1.3.0 / 2014-08-29

  • Default strings to strong ETags
  • Improve speed for weak ETags over 1KB

1.2.1 / 2014-08-29

  • Use the (much faster) buffer-crc32 for crc32

1.2.0 / 2014-08-24

  • Add support for file stat objects

1.1.0 / 2014-08-24

  • Add fast-path for empty entity
  • Add weak ETag generation
  • Shrink size of generated ETags

1.0.1 / 2014-08-24

  • Fix behavior of string containing Unicode

1.0.0 / 2014-05-18

  • Initial release
/*!
* etag
* Copyright(c) 2014 Douglas Christopher Wilson
* MIT Licensed
*/
/**
* Module exports.
*/
module.exports = etag
/**
* Module dependencies.
*/
var crc = require('crc').crc32
var crypto = require('crypto')
var Stats = require('fs').Stats
/**
* Module variables.
*/
var crc32threshold = 1000 // 1KB
var NULL = new Buffer([0])
var toString = Object.prototype.toString
/**
* Create a simple ETag.
*
* @param {string|Buffer|Stats} entity
* @param {object} [options]
* @param {boolean} [options.weak]
* @return {String}
* @api public
*/
function etag(entity, options) {
if (entity == null) {
throw new TypeError('argument entity is required')
}
var isStats = isstats(entity)
var weak = options && typeof options.weak === 'boolean'
? options.weak
: isStats
// support fs.Stats object
if (isStats) {
return stattag(entity, weak)
}
if (typeof entity !== 'string' && !Buffer.isBuffer(entity)) {
throw new TypeError('argument entity must be string, Buffer, or fs.Stats')
}
var hash = weak
? weakhash(entity)
: stronghash(entity)
return weak
? 'W/"' + hash + '"'
: '"' + hash + '"'
}
/**
* Determine if object is a Stats object.
*
* @param {object} obj
* @return {boolean}
* @api private
*/
function isstats(obj) {
// not even an object
if (obj === null || typeof obj !== 'object') {
return false
}
// genuine fs.Stats
if (obj instanceof Stats) {
return true
}
// quack quack
return 'atime' in obj && toString.call(obj.atime) === '[object Date]'
&& 'ctime' in obj && toString.call(obj.ctime) === '[object Date]'
&& 'mtime' in obj && toString.call(obj.mtime) === '[object Date]'
&& 'ino' in obj && typeof obj.ino === 'number'
&& 'size' in obj && typeof obj.size === 'number'
}
/**
* Generate a tag for a stat.
*
* @param {Buffer} entity
* @return {String}
* @api private
*/
function stattag(stat, weak) {
var mtime = stat.mtime.toISOString()
var size = stat.size.toString(16)
if (weak) {
return 'W/"' + size + '-' + crc(mtime) + '"'
}
var hash = crypto
.createHash('md5')
.update('file', 'utf8')
.update(NULL)
.update(size, 'utf8')
.update(NULL)
.update(mtime, 'utf8')
.digest('base64')
return '"' + hash + '"'
}
/**
* Generate a strong hash.
*
* @param {Buffer} entity
* @return {String}
* @api private
*/
function stronghash(entity) {
if (entity.length === 0) {
// fast-path empty
return '1B2M2Y8AsgTpgAmY7PhCfg=='
}
return crypto
.createHash('md5')
.update(entity, 'utf8')
.digest('base64')
}
/**
* Generate a weak hash.
*
* @param {Buffer} entity
* @return {String}
* @api private
*/
function weakhash(entity) {
if (entity.length === 0) {
// fast-path empty
return '0-0'
}
var len = typeof entity === 'string'
? Buffer.byteLength(entity, 'utf8')
: entity.length
if (len <= crc32threshold) {
// crc32 plus length when it's fast
// crc(str) only accepts utf-8 encoding
return len.toString(16) + '-' + crc(entity).toString(16)
}
// use md4 for long strings
return crypto
.createHash('md4')
.update(entity, 'utf8')
.digest('base64')
}
(The MIT License)
Copyright (c) 2014 Douglas Christopher Wilson
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// Generated by CoffeeScript 1.7.1
var CRC, hex;
hex = require('./hex');
module.exports = CRC = (function() {
CRC.prototype.INIT_CRC = 0x00;
CRC.prototype.XOR_MASK = 0x00;
CRC.prototype.WIDTH = 0;
CRC.prototype.pack = function(crc) {
return '';
};
CRC.prototype.each_byte = function(buf, cb) {
var i, _i, _ref, _results;
if (!Buffer.isBuffer(buf)) {
buf = Buffer(buf);
}
_results = [];
for (i = _i = 0, _ref = buf.length - 1; 0 <= _ref ? _i <= _ref : _i >= _ref; i = 0 <= _ref ? ++_i : --_i) {
_results.push(cb(buf[i]));
}
return _results;
};
function CRC() {
this.crc = this.INIT_CRC;
}
CRC.prototype.digest_length = function() {
return Math.ceil(this.WIDTH / 8.0);
};
CRC.prototype.update = function(data) {};
CRC.prototype.reset = function() {
return this.crc = this.INIT_CRC;
};
CRC.prototype.checksum = function(signed) {
var sum;
if (signed == null) {
signed = true;
}
sum = this.crc ^ this.XOR_MASK;
if (signed) {
sum = sum >>> 0;
}
return sum;
};
CRC.prototype.finish = function() {
return this.pack(this.checksum());
};
CRC.prototype.hexdigest = function(value) {
var result;
if (value != null) {
this.update(value);
}
result = this.finish();
this.reset();
return result;
};
return CRC;
})();
// Generated by CoffeeScript 1.7.1
var Buffer, create;
Buffer = require('buffer').Buffer;
create = require('./create');
module.exports = create('crc1', function(buf, previous) {
var accum, byte, crc, _i, _len;
if (!Buffer.isBuffer(buf)) {
buf = Buffer(buf);
}
crc = ~~previous;
accum = 0;
for (_i = 0, _len = buf.length; _i < _len; _i++) {
byte = buf[_i];
accum += byte;
}
crc += accum % 256;
return crc % 256;
});
// Generated by CoffeeScript 1.7.1
var Buffer, TABLE, create;
Buffer = require('buffer').Buffer;
create = require('./create');
TABLE = [0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0, 0x0280, 0xc241, 0xc601, 0x06c0, 0x0780, 0xc741, 0x0500, 0xc5c1, 0xc481, 0x0440, 0xcc01, 0x0cc0, 0x0d80, 0xcd41, 0x0f00, 0xcfc1, 0xce81, 0x0e40, 0x0a00, 0xcac1, 0xcb81, 0x0b40, 0xc901, 0x09c0, 0x0880, 0xc841, 0xd801, 0x18c0, 0x1980, 0xd941, 0x1b00, 0xdbc1, 0xda81, 0x1a40, 0x1e00, 0xdec1, 0xdf81, 0x1f40, 0xdd01, 0x1dc0, 0x1c80, 0xdc41, 0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, 0x1680, 0xd641, 0xd201, 0x12c0, 0x1380, 0xd341, 0x1100, 0xd1c1, 0xd081, 0x1040, 0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, 0xf281, 0x3240, 0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441, 0x3c00, 0xfcc1, 0xfd81, 0x3d40, 0xff01, 0x3fc0, 0x3e80, 0xfe41, 0xfa01, 0x3ac0, 0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840, 0x2800, 0xe8c1, 0xe981, 0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41, 0xee01, 0x2ec0, 0x2f80, 0xef41, 0x2d00, 0xedc1, 0xec81, 0x2c40, 0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, 0xe7c1, 0xe681, 0x2640, 0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, 0x2080, 0xe041, 0xa001, 0x60c0, 0x6180, 0xa141, 0x6300, 0xa3c1, 0xa281, 0x6240, 0x6600, 0xa6c1, 0xa781, 0x6740, 0xa501, 0x65c0, 0x6480, 0xa441, 0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41, 0xaa01, 0x6ac0, 0x6b80, 0xab41, 0x6900, 0xa9c1, 0xa881, 0x6840, 0x7800, 0xb8c1, 0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41, 0xbe01, 0x7ec0, 0x7f80, 0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40, 0xb401, 0x74c0, 0x7580, 0xb541, 0x7700, 0xb7c1, 0xb681, 0x7640, 0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101, 0x71c0, 0x7080, 0xb041, 0x5000, 0x90c1, 0x9181, 0x5140, 0x9301, 0x53c0, 0x5280, 0x9241, 0x9601, 0x56c0, 0x5780, 0x9741, 0x5500, 0x95c1, 0x9481, 0x5440, 0x9c01, 0x5cc0, 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40, 0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841, 0x8801, 0x48c0, 0x4980, 0x8941, 0x4b00, 0x8bc1, 0x8a81, 0x4a40, 0x4e00, 0x8ec1, 0x8f81, 0x4f40, 0x8d01, 0x4dc0, 0x4c80, 0x8c41, 0x4400, 0x84c1, 0x8581, 0x4540, 0x8701, 0x47c0, 0x4680, 0x8641, 0x8201, 0x42c0, 0x4380, 0x8341, 0x4100, 0x81c1, 0x8081, 0x4040];
if (typeof Int32Array !== 'undefined') {
TABLE = new Int32Array(TABLE);
}
module.exports = create('crc-16', function(buf, previous) {
var byte, crc, _i, _len;
if (!Buffer.isBuffer(buf)) {
buf = Buffer(buf);
}
crc = ~~previous;
for (_i = 0, _len = buf.length; _i < _len; _i++) {
byte = buf[_i];
crc = (TABLE[(crc ^ byte) & 0xff] ^ (crc >> 8)) & 0xffff;
}
return crc;
});
// Generated by CoffeeScript 1.7.1
var Buffer, TABLE, create;
Buffer = require('buffer').Buffer;
create = require('./create');
TABLE = [0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7, 0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef, 0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6, 0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de, 0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485, 0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d, 0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4, 0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc, 0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823, 0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b, 0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12, 0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a, 0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41, 0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49, 0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70, 0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78, 0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f, 0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067, 0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e, 0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256, 0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d, 0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, 0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c, 0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634, 0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab, 0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3, 0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a, 0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92, 0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9, 0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1, 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0];
if (typeof Int32Array !== 'undefined') {
TABLE = new Int32Array(TABLE);
}
module.exports = create('ccitt', function(buf, previous) {
var byte, crc, _i, _len;
if (!Buffer.isBuffer(buf)) {
buf = Buffer(buf);
}
crc = previous != null ? ~~previous : 0xffff;
for (_i = 0, _len = buf.length; _i < _len; _i++) {
byte = buf[_i];
crc = (TABLE[((crc >> 8) ^ byte) & 0xff] ^ (crc << 8)) & 0xffff;
}
return crc;
});
// Generated by CoffeeScript 1.7.1
var Buffer, TABLE, create;
Buffer = require('buffer').Buffer;
create = require('./create');
TABLE = [0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0, 0x0280, 0xc241, 0xc601, 0x06c0, 0x0780, 0xc741, 0x0500, 0xc5c1, 0xc481, 0x0440, 0xcc01, 0x0cc0, 0x0d80, 0xcd41, 0x0f00, 0xcfc1, 0xce81, 0x0e40, 0x0a00, 0xcac1, 0xcb81, 0x0b40, 0xc901, 0x09c0, 0x0880, 0xc841, 0xd801, 0x18c0, 0x1980, 0xd941, 0x1b00, 0xdbc1, 0xda81, 0x1a40, 0x1e00, 0xdec1, 0xdf81, 0x1f40, 0xdd01, 0x1dc0, 0x1c80, 0xdc41, 0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, 0x1680, 0xd641, 0xd201, 0x12c0, 0x1380, 0xd341, 0x1100, 0xd1c1, 0xd081, 0x1040, 0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, 0xf281, 0x3240, 0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441, 0x3c00, 0xfcc1, 0xfd81, 0x3d40, 0xff01, 0x3fc0, 0x3e80, 0xfe41, 0xfa01, 0x3ac0, 0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840, 0x2800, 0xe8c1, 0xe981, 0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41, 0xee01, 0x2ec0, 0x2f80, 0xef41, 0x2d00, 0xedc1, 0xec81, 0x2c40, 0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, 0xe7c1, 0xe681, 0x2640, 0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, 0x2080, 0xe041, 0xa001, 0x60c0, 0x6180, 0xa141, 0x6300, 0xa3c1, 0xa281, 0x6240, 0x6600, 0xa6c1, 0xa781, 0x6740, 0xa501, 0x65c0, 0x6480, 0xa441, 0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41, 0xaa01, 0x6ac0, 0x6b80, 0xab41, 0x6900, 0xa9c1, 0xa881, 0x6840, 0x7800, 0xb8c1, 0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41, 0xbe01, 0x7ec0, 0x7f80, 0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40, 0xb401, 0x74c0, 0x7580, 0xb541, 0x7700, 0xb7c1, 0xb681, 0x7640, 0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101, 0x71c0, 0x7080, 0xb041, 0x5000, 0x90c1, 0x9181, 0x5140, 0x9301, 0x53c0, 0x5280, 0x9241, 0x9601, 0x56c0, 0x5780, 0x9741, 0x5500, 0x95c1, 0x9481, 0x5440, 0x9c01, 0x5cc0, 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40, 0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841, 0x8801, 0x48c0, 0x4980, 0x8941, 0x4b00, 0x8bc1, 0x8a81, 0x4a40, 0x4e00, 0x8ec1, 0x8f81, 0x4f40, 0x8d01, 0x4dc0, 0x4c80, 0x8c41, 0x4400, 0x84c1, 0x8581, 0x4540, 0x8701, 0x47c0, 0x4680, 0x8641, 0x8201, 0x42c0, 0x4380, 0x8341, 0x4100, 0x81c1, 0x8081, 0x4040];
if (typeof Int32Array !== 'undefined') {
TABLE = new Int32Array(TABLE);
}
module.exports = create('crc-16-modbus', function(buf, previous) {
var byte, crc, _i, _len;
if (!Buffer.isBuffer(buf)) {
buf = Buffer(buf);
}
crc = previous != null ? ~~previous : 0xffff;
for (_i = 0, _len = buf.length; _i < _len; _i++) {
byte = buf[_i];
crc = (TABLE[(crc ^ byte) & 0xff] ^ (crc >> 8)) & 0xffff;
}
return crc;
});
// Generated by CoffeeScript 1.7.1
var Buffer, TABLE, create;
Buffer = require('buffer').Buffer;
create = require('./create');
TABLE = [0x000000, 0x864cfb, 0x8ad50d, 0x0c99f6, 0x93e6e1, 0x15aa1a, 0x1933ec, 0x9f7f17, 0xa18139, 0x27cdc2, 0x2b5434, 0xad18cf, 0x3267d8, 0xb42b23, 0xb8b2d5, 0x3efe2e, 0xc54e89, 0x430272, 0x4f9b84, 0xc9d77f, 0x56a868, 0xd0e493, 0xdc7d65, 0x5a319e, 0x64cfb0, 0xe2834b, 0xee1abd, 0x685646, 0xf72951, 0x7165aa, 0x7dfc5c, 0xfbb0a7, 0x0cd1e9, 0x8a9d12, 0x8604e4, 0x00481f, 0x9f3708, 0x197bf3, 0x15e205, 0x93aefe, 0xad50d0, 0x2b1c2b, 0x2785dd, 0xa1c926, 0x3eb631, 0xb8faca, 0xb4633c, 0x322fc7, 0xc99f60, 0x4fd39b, 0x434a6d, 0xc50696, 0x5a7981, 0xdc357a, 0xd0ac8c, 0x56e077, 0x681e59, 0xee52a2, 0xe2cb54, 0x6487af, 0xfbf8b8, 0x7db443, 0x712db5, 0xf7614e, 0x19a3d2, 0x9fef29, 0x9376df, 0x153a24, 0x8a4533, 0x0c09c8, 0x00903e, 0x86dcc5, 0xb822eb, 0x3e6e10, 0x32f7e6, 0xb4bb1d, 0x2bc40a, 0xad88f1, 0xa11107, 0x275dfc, 0xdced5b, 0x5aa1a0, 0x563856, 0xd074ad, 0x4f0bba, 0xc94741, 0xc5deb7, 0x43924c, 0x7d6c62, 0xfb2099, 0xf7b96f, 0x71f594, 0xee8a83, 0x68c678, 0x645f8e, 0xe21375, 0x15723b, 0x933ec0, 0x9fa736, 0x19ebcd, 0x8694da, 0x00d821, 0x0c41d7, 0x8a0d2c, 0xb4f302, 0x32bff9, 0x3e260f, 0xb86af4, 0x2715e3, 0xa15918, 0xadc0ee, 0x2b8c15, 0xd03cb2, 0x567049, 0x5ae9bf, 0xdca544, 0x43da53, 0xc596a8, 0xc90f5e, 0x4f43a5, 0x71bd8b, 0xf7f170, 0xfb6886, 0x7d247d, 0xe25b6a, 0x641791, 0x688e67, 0xeec29c, 0x3347a4, 0xb50b5f, 0xb992a9, 0x3fde52, 0xa0a145, 0x26edbe, 0x2a7448, 0xac38b3, 0x92c69d, 0x148a66, 0x181390, 0x9e5f6b, 0x01207c, 0x876c87, 0x8bf571, 0x0db98a, 0xf6092d, 0x7045d6, 0x7cdc20, 0xfa90db, 0x65efcc, 0xe3a337, 0xef3ac1, 0x69763a, 0x578814, 0xd1c4ef, 0xdd5d19, 0x5b11e2, 0xc46ef5, 0x42220e, 0x4ebbf8, 0xc8f703, 0x3f964d, 0xb9dab6, 0xb54340, 0x330fbb, 0xac70ac, 0x2a3c57, 0x26a5a1, 0xa0e95a, 0x9e1774, 0x185b8f, 0x14c279, 0x928e82, 0x0df195, 0x8bbd6e, 0x872498, 0x016863, 0xfad8c4, 0x7c943f, 0x700dc9, 0xf64132, 0x693e25, 0xef72de, 0xe3eb28, 0x65a7d3, 0x5b59fd, 0xdd1506, 0xd18cf0, 0x57c00b, 0xc8bf1c, 0x4ef3e7, 0x426a11, 0xc426ea, 0x2ae476, 0xaca88d, 0xa0317b, 0x267d80, 0xb90297, 0x3f4e6c, 0x33d79a, 0xb59b61, 0x8b654f, 0x0d29b4, 0x01b042, 0x87fcb9, 0x1883ae, 0x9ecf55, 0x9256a3, 0x141a58, 0xefaaff, 0x69e604, 0x657ff2, 0xe33309, 0x7c4c1e, 0xfa00e5, 0xf69913, 0x70d5e8, 0x4e2bc6, 0xc8673d, 0xc4fecb, 0x42b230, 0xddcd27, 0x5b81dc, 0x57182a, 0xd154d1, 0x26359f, 0xa07964, 0xace092, 0x2aac69, 0xb5d37e, 0x339f85, 0x3f0673, 0xb94a88, 0x87b4a6, 0x01f85d, 0x0d61ab, 0x8b2d50, 0x145247, 0x921ebc, 0x9e874a, 0x18cbb1, 0xe37b16, 0x6537ed, 0x69ae1b, 0xefe2e0, 0x709df7, 0xf6d10c, 0xfa48fa, 0x7c0401, 0x42fa2f, 0xc4b6d4, 0xc82f22, 0x4e63d9, 0xd11cce, 0x575035, 0x5bc9c3, 0xdd8538];
if (typeof Int32Array !== 'undefined') {
TABLE = new Int32Array(TABLE);
}
module.exports = create('crc-24', function(buf, previous) {
var byte, crc, _i, _len;
if (!Buffer.isBuffer(buf)) {
buf = Buffer(buf);
}
crc = previous != null ? ~~previous : 0xb704ce;
for (_i = 0, _len = buf.length; _i < _len; _i++) {
byte = buf[_i];
crc = (TABLE[((crc >> 16) ^ byte) & 0xff] ^ (crc << 8)) & 0xffffff;
}
return crc;
});
// Generated by CoffeeScript 1.7.1
var Buffer, TABLE, create;
Buffer = require('buffer').Buffer;
create = require('./create');
TABLE = [0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d];
if (typeof Int32Array !== 'undefined') {
TABLE = new Int32Array(TABLE);
}
module.exports = create('crc-32', function(buf, previous) {
var byte, crc, _i, _len;
if (!Buffer.isBuffer(buf)) {
buf = Buffer(buf);
}
crc = previous === 0 ? 0 : ~~previous ^ -1;
for (_i = 0, _len = buf.length; _i < _len; _i++) {
byte = buf[_i];
crc = TABLE[(crc ^ byte) & 0xff] ^ (crc >>> 8);
}
return crc ^ -1;
});
// Generated by CoffeeScript 1.7.1
var Buffer, TABLE, create;
Buffer = require('buffer').Buffer;
create = require('./create');
TABLE = [0x00, 0x07, 0x0e, 0x09, 0x1c, 0x1b, 0x12, 0x15, 0x38, 0x3f, 0x36, 0x31, 0x24, 0x23, 0x2a, 0x2d, 0x70, 0x77, 0x7e, 0x79, 0x6c, 0x6b, 0x62, 0x65, 0x48, 0x4f, 0x46, 0x41, 0x54, 0x53, 0x5a, 0x5d, 0xe0, 0xe7, 0xee, 0xe9, 0xfc, 0xfb, 0xf2, 0xf5, 0xd8, 0xdf, 0xd6, 0xd1, 0xc4, 0xc3, 0xca, 0xcd, 0x90, 0x97, 0x9e, 0x99, 0x8c, 0x8b, 0x82, 0x85, 0xa8, 0xaf, 0xa6, 0xa1, 0xb4, 0xb3, 0xba, 0xbd, 0xc7, 0xc0, 0xc9, 0xce, 0xdb, 0xdc, 0xd5, 0xd2, 0xff, 0xf8, 0xf1, 0xf6, 0xe3, 0xe4, 0xed, 0xea, 0xb7, 0xb0, 0xb9, 0xbe, 0xab, 0xac, 0xa5, 0xa2, 0x8f, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9d, 0x9a, 0x27, 0x20, 0x29, 0x2e, 0x3b, 0x3c, 0x35, 0x32, 0x1f, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0d, 0x0a, 0x57, 0x50, 0x59, 0x5e, 0x4b, 0x4c, 0x45, 0x42, 0x6f, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7d, 0x7a, 0x89, 0x8e, 0x87, 0x80, 0x95, 0x92, 0x9b, 0x9c, 0xb1, 0xb6, 0xbf, 0xb8, 0xad, 0xaa, 0xa3, 0xa4, 0xf9, 0xfe, 0xf7, 0xf0, 0xe5, 0xe2, 0xeb, 0xec, 0xc1, 0xc6, 0xcf, 0xc8, 0xdd, 0xda, 0xd3, 0xd4, 0x69, 0x6e, 0x67, 0x60, 0x75, 0x72, 0x7b, 0x7c, 0x51, 0x56, 0x5f, 0x58, 0x4d, 0x4a, 0x43, 0x44, 0x19, 0x1e, 0x17, 0x10, 0x05, 0x02, 0x0b, 0x0c, 0x21, 0x26, 0x2f, 0x28, 0x3d, 0x3a, 0x33, 0x34, 0x4e, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5c, 0x5b, 0x76, 0x71, 0x78, 0x7f, 0x6a, 0x6d, 0x64, 0x63, 0x3e, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2c, 0x2b, 0x06, 0x01, 0x08, 0x0f, 0x1a, 0x1d, 0x14, 0x13, 0xae, 0xa9, 0xa0, 0xa7, 0xb2, 0xb5, 0xbc, 0xbb, 0x96, 0x91, 0x98, 0x9f, 0x8a, 0x8d, 0x84, 0x83, 0xde, 0xd9, 0xd0, 0xd7, 0xc2, 0xc5, 0xcc, 0xcb, 0xe6, 0xe1, 0xe8, 0xef, 0xfa, 0xfd, 0xf4, 0xf3];
if (typeof Int32Array !== 'undefined') {
TABLE = new Int32Array(TABLE);
}
module.exports = create('crc-8', function(buf, previous) {
var byte, crc, _i, _len;
if (!Buffer.isBuffer(buf)) {
buf = Buffer(buf);
}
crc = ~~previous;
for (_i = 0, _len = buf.length; _i < _len; _i++) {
byte = buf[_i];
crc = TABLE[(crc ^ byte) & 0xff] & 0xff;
}
return crc;
});
// Generated by CoffeeScript 1.7.1
var Buffer, TABLE, create;
Buffer = require('buffer').Buffer;
create = require('./create');
TABLE = [0x00, 0x5e, 0xbc, 0xe2, 0x61, 0x3f, 0xdd, 0x83, 0xc2, 0x9c, 0x7e, 0x20, 0xa3, 0xfd, 0x1f, 0x41, 0x9d, 0xc3, 0x21, 0x7f, 0xfc, 0xa2, 0x40, 0x1e, 0x5f, 0x01, 0xe3, 0xbd, 0x3e, 0x60, 0x82, 0xdc, 0x23, 0x7d, 0x9f, 0xc1, 0x42, 0x1c, 0xfe, 0xa0, 0xe1, 0xbf, 0x5d, 0x03, 0x80, 0xde, 0x3c, 0x62, 0xbe, 0xe0, 0x02, 0x5c, 0xdf, 0x81, 0x63, 0x3d, 0x7c, 0x22, 0xc0, 0x9e, 0x1d, 0x43, 0xa1, 0xff, 0x46, 0x18, 0xfa, 0xa4, 0x27, 0x79, 0x9b, 0xc5, 0x84, 0xda, 0x38, 0x66, 0xe5, 0xbb, 0x59, 0x07, 0xdb, 0x85, 0x67, 0x39, 0xba, 0xe4, 0x06, 0x58, 0x19, 0x47, 0xa5, 0xfb, 0x78, 0x26, 0xc4, 0x9a, 0x65, 0x3b, 0xd9, 0x87, 0x04, 0x5a, 0xb8, 0xe6, 0xa7, 0xf9, 0x1b, 0x45, 0xc6, 0x98, 0x7a, 0x24, 0xf8, 0xa6, 0x44, 0x1a, 0x99, 0xc7, 0x25, 0x7b, 0x3a, 0x64, 0x86, 0xd8, 0x5b, 0x05, 0xe7, 0xb9, 0x8c, 0xd2, 0x30, 0x6e, 0xed, 0xb3, 0x51, 0x0f, 0x4e, 0x10, 0xf2, 0xac, 0x2f, 0x71, 0x93, 0xcd, 0x11, 0x4f, 0xad, 0xf3, 0x70, 0x2e, 0xcc, 0x92, 0xd3, 0x8d, 0x6f, 0x31, 0xb2, 0xec, 0x0e, 0x50, 0xaf, 0xf1, 0x13, 0x4d, 0xce, 0x90, 0x72, 0x2c, 0x6d, 0x33, 0xd1, 0x8f, 0x0c, 0x52, 0xb0, 0xee, 0x32, 0x6c, 0x8e, 0xd0, 0x53, 0x0d, 0xef, 0xb1, 0xf0, 0xae, 0x4c, 0x12, 0x91, 0xcf, 0x2d, 0x73, 0xca, 0x94, 0x76, 0x28, 0xab, 0xf5, 0x17, 0x49, 0x08, 0x56, 0xb4, 0xea, 0x69, 0x37, 0xd5, 0x8b, 0x57, 0x09, 0xeb, 0xb5, 0x36, 0x68, 0x8a, 0xd4, 0x95, 0xcb, 0x29, 0x77, 0xf4, 0xaa, 0x48, 0x16, 0xe9, 0xb7, 0x55, 0x0b, 0x88, 0xd6, 0x34, 0x6a, 0x2b, 0x75, 0x97, 0xc9, 0x4a, 0x14, 0xf6, 0xa8, 0x74, 0x2a, 0xc8, 0x96, 0x15, 0x4b, 0xa9, 0xf7, 0xb6, 0xe8, 0x0a, 0x54, 0xd7, 0x89, 0x6b, 0x35];
if (typeof Int32Array !== 'undefined') {
TABLE = new Int32Array(TABLE);
}
module.exports = create('dallas-1-wire', function(buf, previous) {
var byte, crc, _i, _len;
if (!Buffer.isBuffer(buf)) {
buf = Buffer(buf);
}
crc = ~~previous;
for (_i = 0, _len = buf.length; _i < _len; _i++) {
byte = buf[_i];
crc = TABLE[(crc ^ byte) & 0xff] & 0xff;
}
return crc;
});
// Generated by CoffeeScript 1.7.1
module.exports = function(model, calc) {
var fn;
fn = function(buf, previous) {
return calc(buf, previous) >>> 0;
};
fn.signed = calc;
fn.unsigned = fn;
fn.model = model;
return fn;
};
// Generated by CoffeeScript 1.7.1
module.exports = function(number) {
var result;
result = number.toString(16);
while (result.length % 2) {
result = "0" + result;
}
return result;
};
// Generated by CoffeeScript 1.7.1
module.exports = {
crc1: require('./crc1'),
crc8: require('./crc8'),
crc81wire: require('./crc8_1wire'),
crc16: require('./crc16'),
crc16ccitt: require('./crc16_ccitt'),
crc16modbus: require('./crc16_modbus'),
crc24: require('./crc24'),
crc32: require('./crc32')
};
The MIT License (MIT)
Copyright 2014 Alex Gorbatchev
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
{
"name": "crc",
"version": "3.2.1",
"description": "Various CRC JavaScript implementations",
"keywords": [
"crc"
],
"main": "./lib/index.js",
"scripts": {
"test": "mocha test/*.spec.coffee",
"pretest": "coffee --bare --output ./lib --compile ./src/*.coffee"
},
"author": {
"name": "Alex Gorbatchev",
"url": "https://github.com/alexgorbatchev"
},
"devDependencies": {
"beautify-benchmark": "^0.2.4",
"benchmark": "^1.0.0",
"buffer-crc32": "^0.2.3",
"chai": "~1.9.1",
"coffee-errors": "~0.8.6",
"coffee-script": "~1.7.1",
"mocha": "*",
"seedrandom": "^2.3.6"
},
"homepage": "https://github.com/alexgorbatchev/node-crc",
"bugs": {
"url": "https://github.com/alexgorbatchev/node-crc/issues"
},
"repository": {
"type": "git",
"url": "git://github.com/alexgorbatchev/node-crc.git"
},
"license": "MIT",
"readme": "# crc\n\n[![GitTip](http://img.shields.io/gittip/alexgorbatchev.svg?style=flat)](https://www.gittip.com/alexgorbatchev/)\n[![Dependency status](http://img.shields.io/david/alexgorbatchev/node-crc.svg?style=flat)](https://david-dm.org/alexgorbatchev/node-crc)\n[![devDependency Status](http://img.shields.io/david/dev/alexgorbatchev/node-crc.svg?style=flat)](https://david-dm.org/alexgorbatchev/node-crc#info=devDependencies)\n[![Build Status](http://img.shields.io/travis/alexgorbatchev/node-crc.svg?style=flat&branch=master)](https://travis-ci.org/alexgorbatchev/node-crc)\n\n[![NPM](https://nodei.co/npm/crc.svg?style=flat)](https://npmjs.org/package/node-crc)\n\nModule for calculating Cyclic Redundancy Check (CRC).\n\n## Features\n\n* Full test suite comparing values against reference `pycrc` implementation.\n* Version 3.x is 3x to 4x faster than version 2.x.\n* Pure JavaScript implementation, no dependencies.\n* Provides CRC Tables for optimized calculations.\n* Provides support for the following CRC algorithms:\n * CRC1 `crc.crc1(…)`\n * CRC8 `crc.crc8(…)`\n * CRC8 1-Wire `crc.crc81wire(…)`\n * CRC16 `crc.crc16(…)`\n * CRC16 CCITT `crc.crc16ccitt(…)`\n * CRC16 Modbus `crc.crc16modbus(…)`\n * CRC24 `crc.crc24(…)`\n * CRC32 `crc.crc32(…)`\n\n## IMPORTANT\n\nIf you've used `crc` module prior to version 2.x, you might have some inconsistentcies with the current implementation because it relied on very old code and wasn't checked against reference implementation. If you upgrading from 1.x, please take special care.\n\n## Support\n\n<a href=\"https://blockchain.info/address/1CZyBREeHTmy8C5zVGHZHPwqBuWFmEuUCQ\"><img src=\"bitcoin.png\" width=\"150\" align=\"right\"/></a> Please support me on [GitTip](https://www.gittip.com/alexgorbatchev/). I've spend days developing and grooming this module and hope to spend more time. If you have bitcoin, please use the QR code or this wallet address [`1CZyBREeHTmy8C5zVGHZHPwqBuWFmEuUCQ`](https://blockchain.info/address/1CZyBREeHTmy8C5zVGHZHPwqBuWFmEuUCQ):\n\n## Installation\n\n npm install crc\n\n## Running tests\n\n $ npm install\n $ npm test\n\n## Usage Example\n\nCalculate a CRC32:\n\n var crc = require('crc');\n\n crc.crc32('hello').toString(16);\n # => \"3610a686\"\n\nCalculate a CRC32 of a file:\n\n crc.crc32(fs.readFileSync('README.md', 'utf8')).toString(16);\n # => \"127ad531\"\n\nOr using a `Buffer`:\n\n crc.crc32(fs.readFileSync('README.md')).toString(16);\n # => \"127ad531\"\n\nIncrementally calculate a CRC32:\n\n value = crc32('one');\n value = crc32('two', value);\n value = crc32('three', value);\n value.toString(16);\n # => \"09e1c092\"\n\n## Thanks!\n\n[pycrc](http://www.tty1.net/pycrc/) library is which the source of all of the CRC tables.\n\n# License\n\nThe MIT License (MIT)\n\nCopyright (c) 2014 Alex Gorbatchev\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n",
"readmeFilename": "README.md",
"_id": "crc@3.2.1",
"_shasum": "5d9c8fb77a245cd5eca291e5d2d005334bab0082",
"_resolved": "https://registry.npmjs.org/crc/-/crc-3.2.1.tgz",
"_from": "crc@3.2.1"
}

crc

GitTip Dependency status devDependency Status Build Status

NPM

Module for calculating Cyclic Redundancy Check (CRC).

Features

  • Full test suite comparing values against reference pycrc implementation.
  • Version 3.x is 3x to 4x faster than version 2.x.
  • Pure JavaScript implementation, no dependencies.
  • Provides CRC Tables for optimized calculations.
  • Provides support for the following CRC algorithms:
    • CRC1 crc.crc1(…)
    • CRC8 crc.crc8(…)
    • CRC8 1-Wire crc.crc81wire(…)
    • CRC16 crc.crc16(…)
    • CRC16 CCITT crc.crc16ccitt(…)
    • CRC16 Modbus crc.crc16modbus(…)
    • CRC24 crc.crc24(…)
    • CRC32 crc.crc32(…)

IMPORTANT

If you've used crc module prior to version 2.x, you might have some inconsistentcies with the current implementation because it relied on very old code and wasn't checked against reference implementation. If you upgrading from 1.x, please take special care.

Support

Please support me on GitTip. I've spend days developing and grooming this module and hope to spend more time. If you have bitcoin, please use the QR code or this wallet address 1CZyBREeHTmy8C5zVGHZHPwqBuWFmEuUCQ:

Installation

npm install crc

Running tests

$ npm install
$ npm test

Usage Example

Calculate a CRC32:

var crc = require('crc');

crc.crc32('hello').toString(16);
# => "3610a686"

Calculate a CRC32 of a file:

crc.crc32(fs.readFileSync('README.md', 'utf8')).toString(16);
# => "127ad531"

Or using a Buffer:

crc.crc32(fs.readFileSync('README.md')).toString(16);
# => "127ad531"

Incrementally calculate a CRC32:

value = crc32('one');
value = crc32('two', value);
value = crc32('three', value);
value.toString(16);
# => "09e1c092"

Thanks!

pycrc library is which the source of all of the CRC tables.

License

The MIT License (MIT)

Copyright (c) 2014 Alex Gorbatchev

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

{
"name": "etag",
"description": "Create simple ETags",
"version": "1.5.1",
"contributors": [
{
"name": "Douglas Christopher Wilson",
"email": "doug@somethingdoug.com"
},
{
"name": "David Björklund",
"email": "david.bjorklund@gmail.com"
}
],
"license": "MIT",
"keywords": [
"etag",
"http",
"res"
],
"repository": {
"type": "git",
"url": "https://github.com/jshttp/etag"
},
"dependencies": {
"crc": "3.2.1"
},
"devDependencies": {
"benchmark": "1.0.0",
"beautify-benchmark": "0.2.4",
"istanbul": "0.3.2",
"mocha": "~1.21.4",
"seedrandom": "~2.3.6"
},
"files": [
"LICENSE",
"HISTORY.md",
"index.js"
],
"engines": {
"node": ">= 0.6"
},
"scripts": {
"bench": "node benchmark/index.js",
"test": "mocha --reporter spec --bail --check-leaks test/",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/"
},
"readme": "# etag\n\n[![NPM Version][npm-image]][npm-url]\n[![NPM Downloads][downloads-image]][downloads-url]\n[![Node.js Version][node-version-image]][node-version-url]\n[![Build Status][travis-image]][travis-url]\n[![Test Coverage][coveralls-image]][coveralls-url]\n\nCreate simple ETags\n\n## Installation\n\n```sh\n$ npm install etag\n```\n\n## API\n\n```js\nvar etag = require('etag')\n```\n\n### etag(entity, [options])\n\nGenerate a strong ETag for the given entity. This should be the complete\nbody of the entity. Strings, `Buffer`s, and `fs.Stats` are accepted. By\ndefault, a strong ETag is generated except for `fs.Stats`, which will\ngenerate a weak ETag (this can be overwritten by `options.weak`).\n\n```js\nres.setHeader('ETag', etag(body))\n```\n\n#### Options\n\n`etag` accepts these properties in the options object.\n\n##### weak\n\nSpecifies if a \"strong\" or a \"weak\" ETag will be generated. The ETag can only\nreally be a strong as the given input.\n\n## Testing\n\n```sh\n$ npm test\n```\n\n## Benchmark\n\n```bash\n$ npm run-script bench\n\n> etag@1.5.1 bench nodejs-etag\n> node benchmark/index.js\n\n> node benchmark/body0-100b.js\n\n 100B body\n\n 1 test completed.\n 2 tests completed.\n 3 tests completed.\n 4 tests completed.\n\n buffer - strong x 425,007 ops/sec ±1.47% (184 runs sampled)\n* buffer - weak x 1,009,859 ops/sec ±0.18% (197 runs sampled)\n string - strong x 442,096 ops/sec ±1.20% (181 runs sampled)\n string - weak x 325,063 ops/sec ±0.31% (192 runs sampled)\n\n> node benchmark/body1-1kb.js\n\n 1KB body\n\n 1 test completed.\n 2 tests completed.\n 3 tests completed.\n 4 tests completed.\n\n buffer - strong x 263,069 ops/sec ±1.60% (190 runs sampled)\n* buffer - weak x 295,732 ops/sec ±0.43% (199 runs sampled)\n string - strong x 274,822 ops/sec ±1.15% (191 runs sampled)\n string - weak x 169,473 ops/sec ±1.59% (194 runs sampled)\n\n> node benchmark/body2-5kb.js\n\n 5KB body\n\n 1 test completed.\n 2 tests completed.\n 3 tests completed.\n 4 tests completed.\n\n buffer - strong x 104,299 ops/sec ±0.60% (193 runs sampled)\n* buffer - weak x 108,126 ops/sec ±0.65% (196 runs sampled)\n string - strong x 101,736 ops/sec ±0.78% (194 runs sampled)\n string - weak x 101,266 ops/sec ±0.85% (192 runs sampled)\n\n> node benchmark/body3-10kb.js\n\n 10KB body\n\n 1 test completed.\n 2 tests completed.\n 3 tests completed.\n 4 tests completed.\n\n buffer - strong x 59,007 ops/sec ±0.29% (198 runs sampled)\n* buffer - weak x 60,968 ops/sec ±0.48% (197 runs sampled)\n string - strong x 51,873 ops/sec ±1.78% (178 runs sampled)\n string - weak x 52,307 ops/sec ±2.63% (193 runs sampled)\n\n> node benchmark/body4-100kb.js\n\n 100KB body\n\n 1 test completed.\n 2 tests completed.\n 3 tests completed.\n 4 tests completed.\n\n buffer - strong x 6,712 ops/sec ±0.11% (198 runs sampled)\n* buffer - weak x 6,716 ops/sec ±0.50% (196 runs sampled)\n string - strong x 6,397 ops/sec ±0.36% (196 runs sampled)\n string - weak x 6,635 ops/sec ±0.15% (198 runs sampled)\n```\n\n## License\n\n[MIT](LICENSE)\n\n[npm-image]: https://img.shields.io/npm/v/etag.svg?style=flat\n[npm-url]: https://npmjs.org/package/etag\n[node-version-image]: https://img.shields.io/node/v/etag.svg?style=flat\n[node-version-url]: http://nodejs.org/download/\n[travis-image]: https://img.shields.io/travis/jshttp/etag.svg?style=flat\n[travis-url]: https://travis-ci.org/jshttp/etag\n[coveralls-image]: https://img.shields.io/coveralls/jshttp/etag.svg?style=flat\n[coveralls-url]: https://coveralls.io/r/jshttp/etag?branch=master\n[downloads-image]: https://img.shields.io/npm/dm/etag.svg?style=flat\n[downloads-url]: https://npmjs.org/package/etag\n",
"readmeFilename": "README.md",
"bugs": {
"url": "https://github.com/jshttp/etag/issues"
},
"homepage": "https://github.com/jshttp/etag",
"_id": "etag@1.5.1",
"_shasum": "54c50de04ee42695562925ac566588291be7e9ea",
"_resolved": "https://registry.npmjs.org/etag/-/etag-1.5.1.tgz",
"_from": "etag@>=1.5.1 <1.6.0"
}

etag

NPM Version NPM Downloads Node.js Version Build Status Test Coverage

Create simple ETags

Installation

$ npm install etag

API

var etag = require('etag')

etag(entity, [options])

Generate a strong ETag for the given entity. This should be the complete body of the entity. Strings, Buffers, and fs.Stats are accepted. By default, a strong ETag is generated except for fs.Stats, which will generate a weak ETag (this can be overwritten by options.weak).

res.setHeader('ETag', etag(body))

Options

etag accepts these properties in the options object.

weak

Specifies if a "strong" or a "weak" ETag will be generated. The ETag can only really be a strong as the given input.

Testing

$ npm test

Benchmark

$ npm run-script bench

> etag@1.5.1 bench nodejs-etag
> node benchmark/index.js

> node benchmark/body0-100b.js

  100B body

  1 test completed.
  2 tests completed.
  3 tests completed.
  4 tests completed.

  buffer - strong x   425,007 ops/sec ±1.47% (184 runs sampled)
* buffer - weak   x 1,009,859 ops/sec ±0.18% (197 runs sampled)
  string - strong x   442,096 ops/sec ±1.20% (181 runs sampled)
  string - weak   x   325,063 ops/sec ±0.31% (192 runs sampled)

> node benchmark/body1-1kb.js

  1KB body

  1 test completed.
  2 tests completed.
  3 tests completed.
  4 tests completed.

  buffer - strong x 263,069 ops/sec ±1.60% (190 runs sampled)
* buffer - weak   x 295,732 ops/sec ±0.43% (199 runs sampled)
  string - strong x 274,822 ops/sec ±1.15% (191 runs sampled)
  string - weak   x 169,473 ops/sec ±1.59% (194 runs sampled)

> node benchmark/body2-5kb.js

  5KB body

  1 test completed.
  2 tests completed.
  3 tests completed.
  4 tests completed.

  buffer - strong x 104,299 ops/sec ±0.60% (193 runs sampled)
* buffer - weak   x 108,126 ops/sec ±0.65% (196 runs sampled)
  string - strong x 101,736 ops/sec ±0.78% (194 runs sampled)
  string - weak   x 101,266 ops/sec ±0.85% (192 runs sampled)

> node benchmark/body3-10kb.js

  10KB body

  1 test completed.
  2 tests completed.
  3 tests completed.
  4 tests completed.

  buffer - strong x 59,007 ops/sec ±0.29% (198 runs sampled)
* buffer - weak   x 60,968 ops/sec ±0.48% (197 runs sampled)
  string - strong x 51,873 ops/sec ±1.78% (178 runs sampled)
  string - weak   x 52,307 ops/sec ±2.63% (193 runs sampled)

> node benchmark/body4-100kb.js

  100KB body

  1 test completed.
  2 tests completed.
  3 tests completed.
  4 tests completed.

  buffer - strong x 6,712 ops/sec ±0.11% (198 runs sampled)
* buffer - weak   x 6,716 ops/sec ±0.50% (196 runs sampled)
  string - strong x 6,397 ops/sec ±0.36% (196 runs sampled)
  string - weak   x 6,635 ops/sec ±0.15% (198 runs sampled)

License

MIT

0.3.4 / 2015-03-15

  • deps: debug@~2.1.3
    • Fix high intensity foreground color for bold
    • deps: ms@0.7.0

0.3.3 / 2015-01-01

  • deps: debug@~2.1.1
  • deps: on-finished@~2.2.0

0.3.2 / 2014-10-22

  • deps: on-finished@~2.1.1
    • Fix handling of pipelined requests

0.3.1 / 2014-10-16

  • deps: debug@~2.1.0
    • Implement DEBUG_FD env variable support

0.3.0 / 2014-09-17

  • Terminate in progress response only on error
  • Use on-finished to determine request status

0.2.0 / 2014-09-03

  • Set X-Content-Type-Options: nosniff header
  • deps: debug@~2.0.0

0.1.0 / 2014-07-16

  • Respond after request fully read
    • prevents hung responses and socket hang ups
  • deps: debug@1.0.4

0.0.3 / 2014-07-11

  • deps: debug@1.0.3
    • Add support for multiple wildcards in namespaces

0.0.2 / 2014-06-19

  • Handle invalid status codes

0.0.1 / 2014-06-05

  • deps: debug@1.0.2

0.0.0 / 2014-06-05

  • Extracted from connect/express
/*!
* finalhandler
* Copyright(c) 2014 Douglas Christopher Wilson
* MIT Licensed
*/
/**
* Module dependencies.
*/
var debug = require('debug')('finalhandler')
var escapeHtml = require('escape-html')
var http = require('http')
var onFinished = require('on-finished')
/**
* Variables.
*/
/* istanbul ignore next */
var defer = typeof setImmediate === 'function'
? setImmediate
: function(fn){ process.nextTick(fn.bind.apply(fn, arguments)) }
var isFinished = onFinished.isFinished
/**
* Module exports.
*/
module.exports = finalhandler
/**
* Final handler:
*
* @param {Request} req
* @param {Response} res
* @param {Object} [options]
* @return {Function}
* @api public
*/
function finalhandler(req, res, options) {
options = options || {}
// get environment
var env = options.env || process.env.NODE_ENV || 'development'
// get error callback
var onerror = options.onerror
return function (err) {
var msg
// ignore 404 on in-flight response
if (!err && res._header) {
debug('cannot 404 after headers sent')
return
}
// unhandled error
if (err) {
// default status code to 500
if (!res.statusCode || res.statusCode < 400) {
res.statusCode = 500
}
// respect err.status
if (err.status) {
res.statusCode = err.status
}
// production gets a basic error message
var msg = env === 'production'
? http.STATUS_CODES[res.statusCode]
: err.stack || err.toString()
msg = escapeHtml(msg)
.replace(/\n/g, '<br>')
.replace(/ /g, ' &nbsp;') + '\n'
} else {
res.statusCode = 404
msg = 'Cannot ' + escapeHtml(req.method) + ' ' + escapeHtml(req.originalUrl || req.url) + '\n'
}
debug('default %s', res.statusCode)
// schedule onerror callback
if (err && onerror) {
defer(onerror, err, req, res)
}
// cannot actually respond
if (res._header) {
return req.socket.destroy()
}
send(req, res, res.statusCode, msg)
}
}
/**
* Send response.
*
* @param {IncomingMessage} req
* @param {OutgoingMessage} res
* @param {number} status
* @param {string} body
* @api private
*/
function send(req, res, status, body) {
function write() {
res.statusCode = status
// security header for content sniffing
res.setHeader('X-Content-Type-Options', 'nosniff')
// standard headers
res.setHeader('Content-Type', 'text/html; charset=utf-8')
res.setHeader('Content-Length', Buffer.byteLength(body, 'utf8'))
if (req.method === 'HEAD') {
res.end()
return
}
res.end(body, 'utf8')
}
if (isFinished(req)) {
write()
return
}
// unpipe everything from the request
unpipe(req)
// flush the request
onFinished(req, write)
req.resume()
}
/**
* Unpipe everything from a stream.
*
* @param {Object} stream
* @api private
*/
/* istanbul ignore next: implementation differs between versions */
function unpipe(stream) {
if (typeof stream.unpipe === 'function') {
// new-style
stream.unpipe()
return
}
// Node.js 0.8 hack
var listener
var listeners = stream.listeners('close')
for (var i = 0; i < listeners.length; i++) {
listener = listeners[i]
if (listener.name !== 'cleanup' && listener.name !== 'onclose') {
continue
}
// invoke the listener
listener.call(stream)
}
}
(The MIT License)
Copyright (c) 2014 Douglas Christopher Wilson <doug@somethingdoug.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
{
"name": "finalhandler",
"description": "Node.js final http responder",
"version": "0.3.4",
"author": {
"name": "Douglas Christopher Wilson",
"email": "doug@somethingdoug.com"
},
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/pillarjs/finalhandler"
},
"dependencies": {
"debug": "~2.1.3",
"escape-html": "1.0.1",
"on-finished": "~2.2.0"
},
"devDependencies": {
"istanbul": "0.3.8",
"mocha": "~2.2.1",
"readable-stream": "~1.0.33",
"supertest": "~0.15.0"
},
"files": [
"LICENSE",
"HISTORY.md",
"index.js"
],
"engines": {
"node": ">= 0.8"
},
"scripts": {
"test": "mocha --reporter spec --bail --check-leaks test/",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/"
},
"gitHead": "63e18603c11effcacc06676f6fefbf270795459a",
"bugs": {
"url": "https://github.com/pillarjs/finalhandler/issues"
},
"homepage": "https://github.com/pillarjs/finalhandler",
"_id": "finalhandler@0.3.4",
"_shasum": "4787d3573d079ae8b07536f26b0b911ebaf2a2ac",
"_from": "finalhandler@0.3.4",
"_npmVersion": "1.4.28",
"_npmUser": {
"name": "dougwilson",
"email": "doug@somethingdoug.com"
},
"maintainers": [
{
"name": "dougwilson",
"email": "doug@somethingdoug.com"
},
{
"name": "jongleberry",
"email": "jonathanrichardong@gmail.com"
},
{
"name": "shtylman",
"email": "shtylman@gmail.com"
},
{
"name": "tjholowaychuk",
"email": "tj@vision-media.ca"
},
{
"name": "fishrock123",
"email": "fishrock123@rocketmail.com"
}
],
"dist": {
"shasum": "4787d3573d079ae8b07536f26b0b911ebaf2a2ac",
"tarball": "http://registry.npmjs.org/finalhandler/-/finalhandler-0.3.4.tgz"
},
"directories": {},
"_resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-0.3.4.tgz",
"readme": "ERROR: No README data found!"
}

finalhandler

NPM Version NPM Downloads Node.js Version Build Status Test Coverage

Node.js function to invoke as the final step to respond to HTTP request.

Installation

$ npm install finalhandler

API

var finalhandler = require('finalhandler')

finalhandler(req, res, [options])

Returns function to be invoked as the final step for the given req and res. This function is to be invoked as fn(err). If err is falsy, the handler will write out a 404 response to the res. If it is truthy, an error response will be written out to the res, and res.statusCode is set from err.status.

The final handler will also unpipe anything from req when it is invoked.

options.env

By default, the environment is determined by NODE_ENV variable, but it can be overridden by this option.

options.onerror

Provide a function to be called with the err when it exists. Can be used for writing errors to a central location without excessive function generation. Called as onerror(err, req, res).

Examples

always 404

var finalhandler = require('finalhandler')
var http = require('http')

var server = http.createServer(function (req, res) {
  var done = finalhandler(req, res)
  done()
})

server.listen(3000)

perform simple action

var finalhandler = require('finalhandler')
var fs = require('fs')
var http = require('http')

var server = http.createServer(function (req, res) {
  var done = finalhandler(req, res)

  fs.readFile('index.html', function (err, buf) {
    if (err) return done(err)
    res.setHeader('Content-Type', 'text/html')
    res.end(buf)
  })
})

server.listen(3000)

use with middleware-style functions

var finalhandler = require('finalhandler')
var http = require('http')
var serveStatic = require('serve-static')

var serve = serveStatic('public')

var server = http.createServer(function (req, res) {
  var done = finalhandler(req, res)
  serve(req, res, done)
})

server.listen(3000)

keep log of all errors

var finalhandler = require('finalhandler')
var fs = require('fs')
var http = require('http')

var server = http.createServer(function (req, res) {
  var done = finalhandler(req, res, {onerror: logerror})

  fs.readFile('index.html', function (err, buf) {
    if (err) return done(err)
    res.setHeader('Content-Type', 'text/html')
    res.end(buf)
  })
})

server.listen(3000)

function logerror(err) {
  console.error(err.stack || err.toString())
}

License

MIT

0.2.4 / 2014-09-07

  • Support Node.js 0.6

0.2.3 / 2014-09-07

  • Move repository to jshttp

0.2.2 / 2014-02-19

  • Revert "Fix for blank page on Safari reload"

0.2.1 / 2014-01-29

  • fix: support max-age=0 for end-to-end revalidation

0.2.0 / 2013-08-11

  • fix: return false for no-cache
/**
* Expose `fresh()`.
*/
module.exports = fresh;
/**
* Check freshness of `req` and `res` headers.
*
* When the cache is "fresh" __true__ is returned,
* otherwise __false__ is returned to indicate that
* the cache is now stale.
*
* @param {Object} req
* @param {Object} res
* @return {Boolean}
* @api public
*/
function fresh(req, res) {
// defaults
var etagMatches = true;
var notModified = true;
// fields
var modifiedSince = req['if-modified-since'];
var noneMatch = req['if-none-match'];
var lastModified = res['last-modified'];
var etag = res['etag'];
var cc = req['cache-control'];
// unconditional request
if (!modifiedSince && !noneMatch) return false;
// check for no-cache cache request directive
if (cc && cc.indexOf('no-cache') !== -1) return false;
// parse if-none-match
if (noneMatch) noneMatch = noneMatch.split(/ *, */);
// if-none-match
if (noneMatch) etagMatches = ~noneMatch.indexOf(etag) || '*' == noneMatch[0];
// if-modified-since
if (modifiedSince) {
modifiedSince = new Date(modifiedSince);
lastModified = new Date(lastModified);
notModified = lastModified <= modifiedSince;
}
return !! (etagMatches && notModified);
}
(The MIT License)
Copyright (c) 2012 TJ Holowaychuk <tj@vision-media.ca>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
{
"name": "fresh",
"description": "HTTP response freshness testing",
"version": "0.2.4",
"author": {
"name": "TJ Holowaychuk",
"email": "tj@vision-media.ca",
"url": "http://tjholowaychuk.com"
},
"license": "MIT",
"keywords": [
"fresh",
"http",
"conditional",
"cache"
],
"repository": {
"type": "git",
"url": "https://github.com/jshttp/fresh"
},
"devDependencies": {
"istanbul": "0",
"mocha": "1",
"should": "3"
},
"files": [
"HISTORY.md",
"LICENSE",
"index.js"
],
"engines": {
"node": ">= 0.6"
},
"scripts": {
"test": "mocha --reporter spec --require should",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --require should",
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter dot --require should"
},
"readme": "# fresh\n\n[![NPM Version][npm-image]][npm-url]\n[![NPM Downloads][downloads-image]][downloads-url]\n[![Node.js Version][node-version-image]][node-version-url]\n[![Build Status][travis-image]][travis-url]\n[![Test Coverage][coveralls-image]][coveralls-url]\n\nHTTP response freshness testing\n\n## Installation\n\n```\n$ npm install fresh\n```\n\n## API\n\n```js\nvar fresh = require('fresh')\n```\n\n### fresh(req, res)\n\n Check freshness of `req` and `res` headers.\n\n When the cache is \"fresh\" __true__ is returned,\n otherwise __false__ is returned to indicate that\n the cache is now stale.\n\n## Example\n\n```js\nvar req = { 'if-none-match': 'tobi' };\nvar res = { 'etag': 'luna' };\nfresh(req, res);\n// => false\n\nvar req = { 'if-none-match': 'tobi' };\nvar res = { 'etag': 'tobi' };\nfresh(req, res);\n// => true\n```\n\n## License\n\n[MIT](LICENSE)\n\n[npm-image]: https://img.shields.io/npm/v/fresh.svg?style=flat\n[npm-url]: https://npmjs.org/package/fresh\n[node-version-image]: https://img.shields.io/badge/node.js-%3E%3D_0.6-brightgreen.svg?style=flat\n[node-version-url]: http://nodejs.org/download/\n[travis-image]: https://img.shields.io/travis/jshttp/fresh.svg?style=flat\n[travis-url]: https://travis-ci.org/jshttp/fresh\n[coveralls-image]: https://img.shields.io/coveralls/jshttp/fresh.svg?style=flat\n[coveralls-url]: https://coveralls.io/r/jshttp/fresh?branch=master\n[downloads-image]: https://img.shields.io/npm/dm/fresh.svg?style=flat\n[downloads-url]: https://npmjs.org/package/fresh\n",
"readmeFilename": "README.md",
"bugs": {
"url": "https://github.com/jshttp/fresh/issues"
},
"homepage": "https://github.com/jshttp/fresh",
"_id": "fresh@0.2.4",
"_shasum": "3582499206c9723714190edd74b4604feb4a614c",
"_resolved": "https://registry.npmjs.org/fresh/-/fresh-0.2.4.tgz",
"_from": "fresh@0.2.4"
}

fresh

NPM Version NPM Downloads Node.js Version Build Status Test Coverage

HTTP response freshness testing

Installation

$ npm install fresh

API

var fresh = require('fresh')

fresh(req, res)

Check freshness of req and res headers.

When the cache is "fresh" true is returned, otherwise false is returned to indicate that the cache is now stale.

Example

var req = { 'if-none-match': 'tobi' };
var res = { 'etag': 'luna' };
fresh(req, res);
// => false

var req = { 'if-none-match': 'tobi' };
var res = { 'etag': 'tobi' };
fresh(req, res);
// => true

License

MIT

/*!
* merge-descriptors
* Copyright(c) 2014 Jonathan Ong
* MIT Licensed
*/
/**
* Module exports.
* @public
*/
module.exports = merge
/**
* Module variables.
* @private
*/
var hasOwnProperty = Object.prototype.hasOwnProperty
/**
* Merge the property descriptors of `src` into `dest`
*
* @param {object} dest Object to add descriptors to
* @param {object} src Object to clone descriptors from
* @param {boolean} [redefine=true] Redefine `dest` properties with `src` properties
* @returns {object} Reference to dest
* @public
*/
function merge(dest, src, redefine) {
if (!dest) {
throw new TypeError('argument dest is required')
}
if (!src) {
throw new TypeError('argument src is required')
}
if (redefine === undefined) {
// Default to true
redefine = true
}
Object.getOwnPropertyNames(src).forEach(function forEachOwnPropertyName(name) {
if (!redefine && hasOwnProperty.call(dest, name)) {
// Skip desriptor
return
}
// Copy descriptor
var descriptor = Object.getOwnPropertyDescriptor(src, name)
Object.defineProperty(dest, name, descriptor)
})
return dest
}
(The MIT License)
Copyright (c) 2013 Jonathan Ong <me@jongleberry.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
{
"name": "merge-descriptors",
"description": "Merge objects using descriptors",
"version": "1.0.0",
"author": {
"name": "Jonathan Ong",
"email": "me@jongleberry.com",
"url": "http://jongleberry.com"
},
"contributors": [
{
"name": "Douglas Christopher Wilson",
"email": "doug@somethingdoug.com"
}
],
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/component/merge-descriptors.git"
},
"bugs": {
"url": "https://github.com/component/merge-descriptors/issues"
},
"files": [
"LICENSE",
"README.md",
"index.js"
],
"gitHead": "81d7a3c14099884c391bd237d7d8edf23c6d6f18",
"homepage": "https://github.com/component/merge-descriptors",
"_id": "merge-descriptors@1.0.0",
"scripts": {},
"_shasum": "2169cf7538e1b0cc87fb88e1502d8474bbf79864",
"_from": "merge-descriptors@1.0.0",
"_npmVersion": "1.4.28",
"_npmUser": {
"name": "dougwilson",
"email": "doug@somethingdoug.com"
},
"maintainers": [
{
"name": "jongleberry",
"email": "jonathanrichardong@gmail.com"
},
{
"name": "tootallnate",
"email": "nathan@tootallnate.net"
},
{
"name": "juliangruber",
"email": "julian@juliangruber.com"
},
{
"name": "yields",
"email": "yields@icloud.com"
},
{
"name": "ianstormtaylor",
"email": "ian@ianstormtaylor.com"
},
{
"name": "tjholowaychuk",
"email": "tj@vision-media.ca"
},
{
"name": "timoxley",
"email": "secoif@gmail.com"
},
{
"name": "mattmueller",
"email": "mattmuelle@gmail.com"
},
{
"name": "jonathanong",
"email": "jonathanrichardong@gmail.com"
},
{
"name": "queckezz",
"email": "fabian.eichenberger@gmail.com"
},
{
"name": "anthonyshort",
"email": "antshort@gmail.com"
},
{
"name": "dominicbarnes",
"email": "dominic@dbarnes.info"
},
{
"name": "clintwood",
"email": "clint@anotherway.co.za"
},
{
"name": "thehydroimpulse",
"email": "dnfagnan@gmail.com"
},
{
"name": "stephenmathieson",
"email": "me@stephenmathieson.com"
},
{
"name": "trevorgerhardt",
"email": "trevorgerhardt@gmail.com"
},
{
"name": "timaschew",
"email": "timaschew@gmail.com"
},
{
"name": "hughsk",
"email": "hughskennedy@gmail.com"
},
{
"name": "dougwilson",
"email": "doug@somethingdoug.com"
}
],
"dist": {
"shasum": "2169cf7538e1b0cc87fb88e1502d8474bbf79864",
"tarball": "http://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.0.tgz"
},
"directories": {},
"_resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.0.tgz",
"readme": "ERROR: No README data found!"
}

Merge Descriptors

Merge objects using descriptors.

var thing = {
  get name() {
    return 'jon'
  }
}

var animal = {

}

merge(animal, thing)

animal.name === 'jon'

API

merge(destination, source)

Redefines destination's descriptors with source's.

merge(destination, source, false)

Defines source's descriptors on destination if destination does not have a descriptor by the same name.

License

MIT

1.1.1 / 2014-12-30

  • Improve browserify support

1.1.0 / 2014-07-05

  • Add CONNECT method

1.0.1 / 2014-06-02

  • Fix module to work with harmony transform

1.0.0 / 2014-05-08

  • Add PURGE method

0.1.0 / 2013-10-28

  • Add http.METHODS support
var http = require('http');
/* istanbul ignore next: implementation differs on version */
if (http.METHODS) {
module.exports = http.METHODS.map(function(method){
return method.toLowerCase();
});
} else {
module.exports = [
'get',
'post',
'put',
'head',
'delete',
'options',
'trace',
'copy',
'lock',
'mkcol',
'move',
'purge',
'propfind',
'proppatch',
'unlock',
'report',
'mkactivity',
'checkout',
'merge',
'm-search',
'notify',
'subscribe',
'unsubscribe',
'patch',
'search',
'connect'
];
}
(The MIT License)
Copyright (c) 2013-2014 TJ Holowaychuk <tj@vision-media.ca>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
{
"name": "methods",
"description": "HTTP methods that node supports",
"version": "1.1.1",
"contributors": [
{
"name": "Douglas Christopher Wilson",
"email": "doug@somethingdoug.com"
},
{
"name": "Jonathan Ong",
"email": "me@jongleberry.com",
"url": "http://jongleberry.com"
},
{
"name": "TJ Holowaychuk",
"email": "tj@vision-media.ca",
"url": "http://tjholowaychuk.com"
}
],
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/jshttp/methods"
},
"devDependencies": {
"istanbul": "0.3",
"mocha": "1"
},
"files": [
"index.js",
"HISTORY.md",
"LICENSE"
],
"engines": {
"node": ">= 0.6"
},
"scripts": {
"test": "mocha --reporter spec",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot",
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter dot"
},
"browser": {
"http": false
},
"keywords": [
"http",
"methods"
],
"gitHead": "6293c6b27c5fb963acf67a347af80ad2ebd7247f",
"bugs": {
"url": "https://github.com/jshttp/methods/issues"
},
"homepage": "https://github.com/jshttp/methods",
"_id": "methods@1.1.1",
"_shasum": "17ea6366066d00c58e375b8ec7dfd0453c89822a",
"_from": "methods@>=1.1.1 <1.2.0",
"_npmVersion": "1.4.28",
"_npmUser": {
"name": "dougwilson",
"email": "doug@somethingdoug.com"
},
"maintainers": [
{
"name": "tjholowaychuk",
"email": "tj@vision-media.ca"
},
{
"name": "jonathanong",
"email": "jonathanrichardong@gmail.com"
},
{
"name": "jongleberry",
"email": "jonathanrichardong@gmail.com"
},
{
"name": "dougwilson",
"email": "doug@somethingdoug.com"
}
],
"dist": {
"shasum": "17ea6366066d00c58e375b8ec7dfd0453c89822a",
"tarball": "http://registry.npmjs.org/methods/-/methods-1.1.1.tgz"
},
"directories": {},
"_resolved": "https://registry.npmjs.org/methods/-/methods-1.1.1.tgz",
"readme": "ERROR: No README data found!"
}

Methods

NPM Version NPM Downloads Node.js Version Build Status Test Coverage

HTTP verbs that node core's parser supports.

Install

$ npm install methods

API

var methods = require('methods')

methods

This is an array of lower-case method names that Node.js supports.

License

MIT

2.2.0 / 2014-12-22

  • Add message object to callback arguments

2.1.1 / 2014-10-22

  • Fix handling of pipelined requests

2.1.0 / 2014-08-16

  • Check if socket is detached
  • Return undefined for isFinished if state unknown

2.0.0 / 2014-08-16

  • Add isFinished function
  • Move to jshttp organization
  • Remove support for plain socket argument
  • Rename to on-finished
  • Support both req and res as arguments
  • deps: ee-first@1.0.5

1.2.2 / 2014-06-10

  • Reduce listeners added to emitters
    • avoids "event emitter leak" warnings when used multiple times on same request

1.2.1 / 2014-06-08

  • Fix returned value when already finished

1.2.0 / 2014-06-05

  • Call callback when called on already-finished socket

1.1.4 / 2014-05-27

  • Support node.js 0.8

1.1.3 / 2014-04-30

  • Make sure errors passed as instanceof Error

1.1.2 / 2014-04-18

  • Default the socket to passed-in object

1.1.1 / 2014-01-16

  • Rename module to finished

1.1.0 / 2013-12-25

  • Call callback when called on already-errored socket

1.0.1 / 2013-12-20

  • Actually pass the error to the callback

1.0.0 / 2013-12-20

  • Initial release
/*!
* on-finished
* Copyright(c) 2013 Jonathan Ong
* Copyright(c) 2014 Douglas Christopher Wilson
* MIT Licensed
*/
/**
* Module exports.
*/
module.exports = onFinished;
module.exports.isFinished = isFinished;
/**
* Module dependencies.
*/
var first = require('ee-first')
/**
* Variables.
*/
/* istanbul ignore next */
var defer = typeof setImmediate === 'function'
? setImmediate
: function(fn){ process.nextTick(fn.bind.apply(fn, arguments)) }
/**
* Invoke callback when the response has finished, useful for
* cleaning up resources afterwards.
*
* @param {object} msg
* @param {function} listener
* @return {object}
* @api public
*/
function onFinished(msg, listener) {
if (isFinished(msg) !== false) {
defer(listener, null, msg)
return msg
}
// attach the listener to the message
attachListener(msg, listener)
return msg
}
/**
* Determine if message is already finished.
*
* @param {object} msg
* @return {boolean}
* @api public
*/
function isFinished(msg) {
var socket = msg.socket
if (typeof msg.finished === 'boolean') {
// OutgoingMessage
return Boolean(msg.finished || (socket && !socket.writable))
}
if (typeof msg.complete === 'boolean') {
// IncomingMessage
return Boolean(!socket || msg.complete || !socket.readable)
}
// don't know
return undefined
}
/**
* Attach a finished listener to the message.
*
* @param {object} msg
* @param {function} callback
* @private
*/
function attachFinishedListener(msg, callback) {
var eeMsg
var eeSocket
var finished = false
function onFinish(error) {
eeMsg.cancel()
eeSocket.cancel()
finished = true
callback(error)
}
// finished on first message event
eeMsg = eeSocket = first([[msg, 'end', 'finish']], onFinish)
function onSocket(socket) {
// remove listener
msg.removeListener('socket', onSocket)
if (finished) return
if (eeMsg !== eeSocket) return
// finished on first socket event
eeSocket = first([[socket, 'error', 'close']], onFinish)
}
if (msg.socket) {
// socket already assigned
onSocket(msg.socket)
return
}
// wait for socket to be assigned
msg.on('socket', onSocket)
if (msg.socket === undefined) {
// node.js 0.8 patch
patchAssignSocket(msg, onSocket)
}
}
/**
* Attach the listener to the message.
*
* @param {object} msg
* @return {function}
* @api private
*/
function attachListener(msg, listener) {
var attached = msg.__onFinished
// create a private single listener with queue
if (!attached || !attached.queue) {
attached = msg.__onFinished = createListener(msg)
attachFinishedListener(msg, attached)
}
attached.queue.push(listener)
}
/**
* Create listener on message.
*
* @param {object} msg
* @return {function}
* @api private
*/
function createListener(msg) {
function listener(err) {
if (msg.__onFinished === listener) msg.__onFinished = null
if (!listener.queue) return
var queue = listener.queue
listener.queue = null
for (var i = 0; i < queue.length; i++) {
queue[i](err, msg)
}
}
listener.queue = []
return listener
}
/**
* Patch ServerResponse.prototype.assignSocket for node.js 0.8.
*
* @param {ServerResponse} res
* @param {function} callback
* @private
*/
function patchAssignSocket(res, callback) {
var assignSocket = res.assignSocket
if (typeof assignSocket !== 'function') return
// res.on('socket', callback) is broken in 0.8
res.assignSocket = function _assignSocket(socket) {
assignSocket.call(this, socket)
callback(socket)
}
}
(The MIT License)
Copyright (c) 2013 Jonathan Ong <me@jongleberry.com>
Copyright (c) 2014 Douglas Christopher Wilson <doug@somethingdoug.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
module.exports = function first(stuff, done) {
if (!Array.isArray(stuff))
throw new TypeError('arg must be an array of [ee, events...] arrays')
var cleanups = []
for (var i = 0; i < stuff.length; i++) {
var arr = stuff[i]
if (!Array.isArray(arr) || arr.length < 2)
throw new TypeError('each array member must be [ee, events...]')
var ee = arr[0]
for (var j = 1; j < arr.length; j++) {
var event = arr[j]
var fn = listener(event, callback)
// listen to the event
ee.on(event, fn)
// push this listener to the list of cleanups
cleanups.push({
ee: ee,
event: event,
fn: fn,
})
}
}
function callback() {
cleanup()
done.apply(null, arguments)
}
function cleanup() {
var x
for (var i = 0; i < cleanups.length; i++) {
x = cleanups[i]
x.ee.removeListener(x.event, x.fn)
}
}
function thunk(fn) {
done = fn
}
thunk.cancel = cleanup
return thunk
}
function listener(event, done) {
return function onevent(arg1) {
var args = new Array(arguments.length)
var ee = this
var err = event === 'error'
? arg1
: null
// copy args to prevent arguments escaping scope
for (var i = 0; i < args.length; i++) {
args[i] = arguments[i]
}
done(err, ee, event, args)
}
}
The MIT License (MIT)
Copyright (c) 2014 Jonathan Ong me@jongleberry.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
{
"name": "ee-first",
"description": "return the first event in a set of ee/event pairs",
"version": "1.1.0",
"author": {
"name": "Jonathan Ong",
"email": "me@jongleberry.com",
"url": "http://jongleberry.com"
},
"contributors": [
{
"name": "Douglas Christopher Wilson",
"email": "doug@somethingdoug.com"
}
],
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/jonathanong/ee-first"
},
"devDependencies": {
"istanbul": "0.3.2",
"mocha": "1"
},
"files": [
"index.js",
"LICENSE"
],
"scripts": {
"test": "mocha --reporter spec --bail --check-leaks test/",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/"
},
"gitHead": "a6412004da4745941af2fc98ec30c8da570da7ea",
"bugs": {
"url": "https://github.com/jonathanong/ee-first/issues"
},
"homepage": "https://github.com/jonathanong/ee-first",
"_id": "ee-first@1.1.0",
"_shasum": "6a0d7c6221e490feefd92ec3f441c9ce8cd097f4",
"_from": "ee-first@1.1.0",
"_npmVersion": "1.4.21",
"_npmUser": {
"name": "dougwilson",
"email": "doug@somethingdoug.com"
},
"maintainers": [
{
"name": "jongleberry",
"email": "jonathanrichardong@gmail.com"
},
{
"name": "dougwilson",
"email": "doug@somethingdoug.com"
}
],
"dist": {
"shasum": "6a0d7c6221e490feefd92ec3f441c9ce8cd097f4",
"tarball": "http://registry.npmjs.org/ee-first/-/ee-first-1.1.0.tgz"
},
"directories": {},
"_resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.0.tgz",
"readme": "ERROR: No README data found!"
}

EE First

NPM version Build status Test coverage License Downloads Gittip

Get the first event in a set of event emitters and event pairs, then clean up after itself.

Install

$ npm install ee-first

API

var first = require('ee-first')

first(arr, listener)

Invoke listener on the first event from the list specified in arr. arr is an array of arrays, with each array in the format [ee, ...event]. listener will be called only once, the first time any of the given events are emitted. If error is one of the listened events, then if that fires first, the listener will be given the err argument.

The listener is invoked as listener(err, ee, event, args), where err is the first argument emitted from an error event, if applicable; ee is the event emitter that fired; event is the string event name that fired; and args is an array of the arguments that were emitted on the event.

var ee1 = new EventEmitter()
var ee2 = new EventEmitter()

first([
  [ee1, 'close', 'end', 'error'],
  [ee2, 'error']
], function (err, ee, event, args) {
  // listener invoked
})

.cancel()

The group of listeners can be cancelled before being invoked and have all the event listeners removed from the underlying event emitters.

var thunk = first([
  [ee1, 'close', 'end', 'error'],
  [ee2, 'error']
], function (err, ee, event, args) {
  // listener invoked
})

// cancel and clean up
thunk.cancel()
{
"name": "on-finished",
"description": "Execute a callback when a request closes, finishes, or errors",
"version": "2.2.0",
"contributors": [
{
"name": "Douglas Christopher Wilson",
"email": "doug@somethingdoug.com"
},
{
"name": "Jonathan Ong",
"email": "me@jongleberry.com",
"url": "http://jongleberry.com"
}
],
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/jshttp/on-finished"
},
"dependencies": {
"ee-first": "1.1.0"
},
"devDependencies": {
"istanbul": "0.3.5",
"mocha": "~2.0.1"
},
"engines": {
"node": ">= 0.8"
},
"files": [
"HISTORY.md",
"LICENSE",
"index.js"
],
"scripts": {
"test": "mocha --reporter spec --bail --check-leaks test/",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/"
},
"gitHead": "fcd56f5674721cac92a16eff93547929716f5192",
"bugs": {
"url": "https://github.com/jshttp/on-finished/issues"
},
"homepage": "https://github.com/jshttp/on-finished",
"_id": "on-finished@2.2.0",
"_shasum": "e6ba6a09a3482d6b7969bc3da92c86f0a967605e",
"_from": "on-finished@>=2.2.0 <2.3.0",
"_npmVersion": "1.4.28",
"_npmUser": {
"name": "dougwilson",
"email": "doug@somethingdoug.com"
},
"maintainers": [
{
"name": "dougwilson",
"email": "doug@somethingdoug.com"
},
{
"name": "jongleberry",
"email": "jonathanrichardong@gmail.com"
}
],
"dist": {
"shasum": "e6ba6a09a3482d6b7969bc3da92c86f0a967605e",
"tarball": "http://registry.npmjs.org/on-finished/-/on-finished-2.2.0.tgz"
},
"directories": {},
"_resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.2.0.tgz",
"readme": "ERROR: No README data found!"
}

on-finished

NPM Version NPM Downloads Node.js Version Build Status Test Coverage

Execute a callback when a request closes, finishes, or errors.

Install

$ npm install on-finished

API

var onFinished = require('on-finished')

onFinished(res, listener)

Attach a listener to listen for the response to finish. The listener will be invoked only once when the response finished. If the response finished to to an error, the first argument will contain the error. If the response has already finished, the listener will be invoked.

Listening to the end of a response would be used to close things associated with the response, like open files.

Listener is invoked as listener(err, res).

onFinished(res, function (err, res) {
  // clean up open fds, etc.
  // err contains the error is request error'd
})

onFinished(req, listener)

Attach a listener to listen for the request to finish. The listener will be invoked only once when the request finished. If the request finished to to an error, the first argument will contain the error. If the request has already finished, the listener will be invoked.

Listening to the end of a request would be used to know when to continue after reading the data.

Listener is invoked as listener(err, req).

var data = ''

req.setEncoding('utf8')
res.on('data', function (str) {
  data += str
})

onFinished(req, function (err, req) {
  // data is read unless there is err
})

onFinished.isFinished(res)

Determine if res is already finished. This would be useful to check and not even start certain operations if the response has already finished.

onFinished.isFinished(req)

Determine if req is already finished. This would be useful to check and not even start certain operations if the request has already finished.

Example

The following code ensures that file descriptors are always closed once the response finishes.

var destroy = require('destroy')
var http = require('http')
var onFinished = require('on-finished')

http.createServer(function onRequest(req, res) {
  var stream = fs.createReadStream('package.json')
  stream.pipe(res)
  onFinished(res, function (err) {
    destroy(stream)
  })
})

License

MIT

1.3.0 / 2014-08-09

  • Add parseurl.original for parsing req.originalUrl with fallback
  • Return undefined if req.url is undefined

1.2.0 / 2014-07-21

  • Cache URLs based on original value
  • Remove no-longer-needed URL mis-parse work-around
  • Simplify the "fast-path" RegExp

1.1.3 / 2014-07-08

  • Fix typo

1.1.2 / 2014-07-08

  • Seriously fix Node.js 0.8 compatibility

1.1.1 / 2014-07-08

  • Fix Node.js 0.8 compatibility

1.1.0 / 2014-07-08

  • Incorporate URL href-only parse fast-path

1.0.1 / 2014-03-08

  • Add missing require

1.0.0 / 2014-03-08

  • Genesis from connect
/*!
* parseurl
* Copyright(c) 2014 Jonathan Ong
* Copyright(c) 2014 Douglas Christopher Wilson
* MIT Licensed
*/
/**
* Module dependencies.
*/
var url = require('url')
var parse = url.parse
var Url = url.Url
/**
* Pattern for a simple path case.
* See: https://github.com/joyent/node/pull/7878
*/
var simplePathRegExp = /^(\/\/?(?!\/)[^\?#\s]*)(\?[^#\s]*)?$/
/**
* Exports.
*/
module.exports = parseurl
module.exports.original = originalurl
/**
* Parse the `req` url with memoization.
*
* @param {ServerRequest} req
* @return {Object}
* @api public
*/
function parseurl(req) {
var url = req.url
if (url === undefined) {
// URL is undefined
return undefined
}
var parsed = req._parsedUrl
if (fresh(url, parsed)) {
// Return cached URL parse
return parsed
}
// Parse the URL
parsed = fastparse(url)
parsed._raw = url
return req._parsedUrl = parsed
};
/**
* Parse the `req` original url with fallback and memoization.
*
* @param {ServerRequest} req
* @return {Object}
* @api public
*/
function originalurl(req) {
var url = req.originalUrl
if (typeof url !== 'string') {
// Fallback
return parseurl(req)
}
var parsed = req._parsedOriginalUrl
if (fresh(url, parsed)) {
// Return cached URL parse
return parsed
}
// Parse the URL
parsed = fastparse(url)
parsed._raw = url
return req._parsedOriginalUrl = parsed
};
/**
* Parse the `str` url with fast-path short-cut.
*
* @param {string} str
* @return {Object}
* @api private
*/
function fastparse(str) {
// Try fast path regexp
// See: https://github.com/joyent/node/pull/7878
var simplePath = typeof str === 'string' && simplePathRegExp.exec(str)
// Construct simple URL
if (simplePath) {
var pathname = simplePath[1]
var search = simplePath[2] || null
var url = Url !== undefined
? new Url()
: {}
url.path = str
url.href = str
url.pathname = pathname
url.search = search
url.query = search && search.substr(1)
return url
}
return parse(str)
}
/**
* Determine if parsed is still fresh for url.
*
* @param {string} url
* @param {object} parsedUrl
* @return {boolean}
* @api private
*/
function fresh(url, parsedUrl) {
return typeof parsedUrl === 'object'
&& parsedUrl !== null
&& (Url === undefined || parsedUrl instanceof Url)
&& parsedUrl._raw === url
}
(The MIT License)
Copyright (c) 2014 Jonathan Ong <me@jongleberry.com>
Copyright (c) 2014 Douglas Christopher Wilson <doug@somethingdoug.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
{
"name": "parseurl",
"description": "parse a url with memoization",
"version": "1.3.0",
"author": {
"name": "Jonathan Ong",
"email": "me@jongleberry.com",
"url": "http://jongleberry.com"
},
"contributors": [
{
"name": "Douglas Christopher Wilson",
"email": "doug@somethingdoug.com"
}
],
"repository": {
"type": "git",
"url": "https://github.com/expressjs/parseurl"
},
"license": "MIT",
"devDependencies": {
"benchmark": "1.0.0",
"beautify-benchmark": "0.2.4",
"fast-url-parser": "~1.0.0",
"istanbul": "0.3.0",
"mocha": "~1.21.4"
},
"scripts": {
"bench": "node benchmark/index.js",
"test": "mocha --check-leaks --bail --reporter spec test/",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --check-leaks --reporter dot test/",
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --check-leaks --reporter spec test/"
},
"readme": "# parseurl\n\n[![NPM version](https://badge.fury.io/js/parseurl.svg)](http://badge.fury.io/js/parseurl)\n[![Build Status](https://travis-ci.org/expressjs/parseurl.svg?branch=master)](https://travis-ci.org/expressjs/parseurl)\n[![Coverage Status](https://img.shields.io/coveralls/expressjs/parseurl.svg?branch=master)](https://coveralls.io/r/expressjs/parseurl)\n\nParse a URL with memoization.\n\n## Install\n\n```bash\n$ npm install parseurl\n```\n\n## API\n\n```js\nvar parseurl = require('parseurl')\n```\n\n### parseurl(req)\n\nParse the URL of the given request object (looks at the `req.url` property)\nand return the result. The result is the same as `url.parse` in Node.js core.\nCalling this function multiple times on the same `req` where `req.url` does\nnot change will return a cached parsed object, rather than parsing again.\n\n### parseurl.original(req)\n\nParse the original URL of the given request object and return the result.\nThis works by trying to parse `req.originalUrl` if it is a string, otherwise\nparses `req.url`. The result is the same as `url.parse` in Node.js core.\nCalling this function multiple times on the same `req` where `req.originalUrl`\ndoes not change will return a cached parsed object, rather than parsing again.\n\n## Benchmark\n\n```bash\n$ npm run-script bench\n\n> parseurl@1.3.0 bench nodejs-parseurl\n> node benchmark/index.js\n\n> node benchmark/fullurl.js\n\n Parsing URL \"http://localhost:8888/foo/bar?user=tj&pet=fluffy\"\n\n 1 test completed.\n 2 tests completed.\n 3 tests completed.\n\n fasturl x 1,290,780 ops/sec ±0.46% (195 runs sampled)\n nativeurl x 56,401 ops/sec ±0.22% (196 runs sampled)\n parseurl x 55,231 ops/sec ±0.22% (194 runs sampled)\n\n> node benchmark/pathquery.js\n\n Parsing URL \"/foo/bar?user=tj&pet=fluffy\"\n\n 1 test completed.\n 2 tests completed.\n 3 tests completed.\n\n fasturl x 1,986,668 ops/sec ±0.27% (190 runs sampled)\n nativeurl x 98,740 ops/sec ±0.21% (195 runs sampled)\n parseurl x 2,628,171 ops/sec ±0.36% (195 runs sampled)\n\n> node benchmark/samerequest.js\n\n Parsing URL \"/foo/bar?user=tj&pet=fluffy\" on same request object\n\n 1 test completed.\n 2 tests completed.\n 3 tests completed.\n\n fasturl x 2,184,468 ops/sec ±0.40% (194 runs sampled)\n nativeurl x 99,437 ops/sec ±0.71% (194 runs sampled)\n parseurl x 10,498,005 ops/sec ±0.61% (186 runs sampled)\n\n> node benchmark/simplepath.js\n\n Parsing URL \"/foo/bar\"\n\n 1 test completed.\n 2 tests completed.\n 3 tests completed.\n\n fasturl x 4,535,825 ops/sec ±0.27% (191 runs sampled)\n nativeurl x 98,769 ops/sec ±0.54% (191 runs sampled)\n parseurl x 4,164,865 ops/sec ±0.34% (192 runs sampled)\n\n> node benchmark/slash.js\n\n Parsing URL \"/\"\n\n 1 test completed.\n 2 tests completed.\n 3 tests completed.\n\n fasturl x 4,908,405 ops/sec ±0.42% (191 runs sampled)\n nativeurl x 100,945 ops/sec ±0.59% (188 runs sampled)\n parseurl x 4,333,208 ops/sec ±0.27% (194 runs sampled)\n```\n\n## License\n\n [MIT](LICENSE)\n",
"readmeFilename": "README.md",
"bugs": {
"url": "https://github.com/expressjs/parseurl/issues"
},
"homepage": "https://github.com/expressjs/parseurl",
"_id": "parseurl@1.3.0",
"_shasum": "b58046db4223e145afa76009e61bac87cc2281b3",
"_resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.0.tgz",
"_from": "parseurl@>=1.3.0 <1.4.0"
}

parseurl

NPM version Build Status Coverage Status

Parse a URL with memoization.

Install

$ npm install parseurl

API

var parseurl = require('parseurl')

parseurl(req)

Parse the URL of the given request object (looks at the req.url property) and return the result. The result is the same as url.parse in Node.js core. Calling this function multiple times on the same req where req.url does not change will return a cached parsed object, rather than parsing again.

parseurl.original(req)

Parse the original URL of the given request object and return the result. This works by trying to parse req.originalUrl if it is a string, otherwise parses req.url. The result is the same as url.parse in Node.js core. Calling this function multiple times on the same req where req.originalUrl does not change will return a cached parsed object, rather than parsing again.

Benchmark

$ npm run-script bench

> parseurl@1.3.0 bench nodejs-parseurl
> node benchmark/index.js

> node benchmark/fullurl.js

  Parsing URL "http://localhost:8888/foo/bar?user=tj&pet=fluffy"

  1 test completed.
  2 tests completed.
  3 tests completed.

  fasturl   x 1,290,780 ops/sec ±0.46% (195 runs sampled)
  nativeurl x    56,401 ops/sec ±0.22% (196 runs sampled)
  parseurl  x    55,231 ops/sec ±0.22% (194 runs sampled)

> node benchmark/pathquery.js

  Parsing URL "/foo/bar?user=tj&pet=fluffy"

  1 test completed.
  2 tests completed.
  3 tests completed.

  fasturl   x 1,986,668 ops/sec ±0.27% (190 runs sampled)
  nativeurl x    98,740 ops/sec ±0.21% (195 runs sampled)
  parseurl  x 2,628,171 ops/sec ±0.36% (195 runs sampled)

> node benchmark/samerequest.js

  Parsing URL "/foo/bar?user=tj&pet=fluffy" on same request object

  1 test completed.
  2 tests completed.
  3 tests completed.

  fasturl   x  2,184,468 ops/sec ±0.40% (194 runs sampled)
  nativeurl x     99,437 ops/sec ±0.71% (194 runs sampled)
  parseurl  x 10,498,005 ops/sec ±0.61% (186 runs sampled)

> node benchmark/simplepath.js

  Parsing URL "/foo/bar"

  1 test completed.
  2 tests completed.
  3 tests completed.

  fasturl   x 4,535,825 ops/sec ±0.27% (191 runs sampled)
  nativeurl x    98,769 ops/sec ±0.54% (191 runs sampled)
  parseurl  x 4,164,865 ops/sec ±0.34% (192 runs sampled)

> node benchmark/slash.js

  Parsing URL "/"

  1 test completed.
  2 tests completed.
  3 tests completed.

  fasturl   x 4,908,405 ops/sec ±0.42% (191 runs sampled)
  nativeurl x   100,945 ops/sec ±0.59% (188 runs sampled)
  parseurl  x 4,333,208 ops/sec ±0.27% (194 runs sampled)

License

MIT

{
"name": "path-to-regexp",
"description": "Express style path to RegExp utility",
"version": "0.1.3",
"keywords": [
"express",
"regexp",
"route",
"routing"
],
"scripts": [
"index.js"
],
"license": "MIT"
}

0.1.3 / 2014-07-06

  • Better array support
  • Improved support for trailing slash in non-ending mode

0.1.0 / 2014-03-06

  • add options.end

0.0.2 / 2013-02-10

  • Update to match current express
  • add .license property to component.json
/**
* Expose `pathtoRegexp`.
*/
module.exports = pathtoRegexp;
/**
* Normalize the given path string,
* returning a regular expression.
*
* An empty array should be passed,
* which will contain the placeholder
* key names. For example "/user/:id" will
* then contain ["id"].
*
* @param {String|RegExp|Array} path
* @param {Array} keys
* @param {Object} options
* @return {RegExp}
* @api private
*/
function pathtoRegexp(path, keys, options) {
options = options || {};
var strict = options.strict;
var end = options.end !== false;
var flags = options.sensitive ? '' : 'i';
keys = keys || [];
if (path instanceof RegExp) {
return path;
}
if (Array.isArray(path)) {
// Map array parts into regexps and return their source. We also pass
// the same keys and options instance into every generation to get
// consistent matching groups before we join the sources together.
path = path.map(function (value) {
return pathtoRegexp(value, keys, options).source;
});
return new RegExp('(?:' + path.join('|') + ')', flags);
}
path = ('^' + path + (strict ? '' : path[path.length - 1] === '/' ? '?' : '/?'))
.replace(/\/\(/g, '/(?:')
.replace(/([\/\.])/g, '\\$1')
.replace(/(\\\/)?(\\\.)?:(\w+)(\(.*?\))?(\*)?(\?)?/g, function (match, slash, format, key, capture, star, optional) {
slash = slash || '';
format = format || '';
capture = capture || '([^\\/' + format + ']+?)';
optional = optional || '';
keys.push({ name: key, optional: !!optional });
return ''
+ (optional ? '' : slash)
+ '(?:'
+ format + (optional ? slash : '') + capture
+ (star ? '((?:[\\/' + format + '].+?)?)' : '')
+ ')'
+ optional;
})
.replace(/\*/g, '(.*)');
// If the path is non-ending, match until the end or a slash.
path += (end ? '$' : (path[path.length - 1] === '/' ? '' : '(?=\\/|$)'));
return new RegExp(path, flags);
};
{
"name": "path-to-regexp",
"description": "Express style path to RegExp utility",
"version": "0.1.3",
"scripts": {
"test": "istanbul cover _mocha -- -R spec"
},
"keywords": [
"express",
"regexp"
],
"component": {
"scripts": {
"path-to-regexp": "index.js"
}
},
"repository": {
"type": "git",
"url": "https://github.com/component/path-to-regexp.git"
},
"devDependencies": {
"mocha": "^1.17.1",
"istanbul": "^0.2.6"
},
"bugs": {
"url": "https://github.com/component/path-to-regexp/issues"
},
"homepage": "https://github.com/component/path-to-regexp",
"_id": "path-to-regexp@0.1.3",
"_shasum": "21b9ab82274279de25b156ea08fd12ca51b8aecb",
"_from": "path-to-regexp@0.1.3",
"_npmVersion": "1.4.9",
"_npmUser": {
"name": "blakeembrey",
"email": "hello@blakeembrey.com"
},
"maintainers": [
{
"name": "tjholowaychuk",
"email": "tj@vision-media.ca"
},
{
"name": "jongleberry",
"email": "jonathanrichardong@gmail.com"
},
{
"name": "dominicbarnes",
"email": "dominic@dbarnes.info"
},
{
"name": "tootallnate",
"email": "nathan@tootallnate.net"
},
{
"name": "rauchg",
"email": "rauchg@gmail.com"
},
{
"name": "retrofox",
"email": "rdsuarez@gmail.com"
},
{
"name": "coreh",
"email": "thecoreh@gmail.com"
},
{
"name": "forbeslindesay",
"email": "forbes@lindesay.co.uk"
},
{
"name": "kelonye",
"email": "kelonyemitchel@gmail.com"
},
{
"name": "mattmueller",
"email": "mattmuelle@gmail.com"
},
{
"name": "yields",
"email": "yields@icloud.com"
},
{
"name": "anthonyshort",
"email": "antshort@gmail.com"
},
{
"name": "ianstormtaylor",
"email": "ian@ianstormtaylor.com"
},
{
"name": "cristiandouce",
"email": "cristian@gravityonmars.com"
},
{
"name": "swatinem",
"email": "arpad.borsos@googlemail.com"
},
{
"name": "stagas",
"email": "gstagas@gmail.com"
},
{
"name": "amasad",
"email": "amjad.masad@gmail.com"
},
{
"name": "juliangruber",
"email": "julian@juliangruber.com"
},
{
"name": "shtylman",
"email": "shtylman@gmail.com"
},
{
"name": "calvinfo",
"email": "calvin@calv.info"
},
{
"name": "blakeembrey",
"email": "hello@blakeembrey.com"
},
{
"name": "timoxley",
"email": "secoif@gmail.com"
},
{
"name": "jonathanong",
"email": "jonathanrichardong@gmail.com"
},
{
"name": "queckezz",
"email": "fabian.eichenberger@gmail.com"
},
{
"name": "nami-doc",
"email": "vendethiel@hotmail.fr"
},
{
"name": "clintwood",
"email": "clint@anotherway.co.za"
},
{
"name": "thehydroimpulse",
"email": "dnfagnan@gmail.com"
},
{
"name": "stephenmathieson",
"email": "me@stephenmathieson.com"
},
{
"name": "trevorgerhardt",
"email": "trevorgerhardt@gmail.com"
}
],
"dist": {
"shasum": "21b9ab82274279de25b156ea08fd12ca51b8aecb",
"tarball": "http://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.3.tgz"
},
"directories": {},
"_resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.3.tgz",
"readme": "ERROR: No README data found!"
}

Path-to-RegExp

Turn an Express-style path string such as /user/:name into a regular expression.

Usage

var pathToRegexp = require('path-to-regexp');

pathToRegexp(path, keys, options)

  • path A string in the express format, an array of such strings, or a regular expression
  • keys An array to be populated with the keys present in the url. Once the function completes, this will be an array of strings.
  • options
    • options.sensitive Defaults to false, set this to true to make routes case sensitive
    • options.strict Defaults to false, set this to true to make the trailing slash matter.
    • options.end Defaults to true, set this to false to only match the prefix of the URL.
var keys = [];
var exp = pathToRegexp('/foo/:bar', keys);
//keys = ['bar']
//exp = /^\/foo\/(?:([^\/]+?))\/?$/i

Live Demo

You can see a live demo of this library in use at express-route-tester.

License

MIT

var pathToRegExp = require('./');
var assert = require('assert');
describe('path-to-regexp', function () {
describe('strings', function () {
it('should match simple paths', function () {
var params = [];
var m = pathToRegExp('/test', params).exec('/test');
assert.equal(params.length, 0);
assert.equal(m.length, 1);
assert.equal(m[0], '/test');
});
it('should match express format params', function () {
var params = [];
var m = pathToRegExp('/:test', params).exec('/pathname');
assert.equal(params.length, 1);
assert.equal(params[0].name, 'test');
assert.equal(params[0].optional, false);
assert.equal(m.length, 2);
assert.equal(m[0], '/pathname');
assert.equal(m[1], 'pathname');
});
it('should do strict matches', function () {
var params = [];
var re = pathToRegExp('/:test', params, { strict: true });
var m;
assert.equal(params.length, 1);
assert.equal(params[0].name, 'test');
assert.equal(params[0].optional, false);
m = re.exec('/route');
assert.equal(m.length, 2);
assert.equal(m[0], '/route');
assert.equal(m[1], 'route');
m = re.exec('/route/');
assert.ok(!m);
});
it('should do strict matches with trailing slashes', function () {
var params = [];
var re = pathToRegExp('/:test/', params, { strict: true });
var m;
assert.equal(params.length, 1);
assert.equal(params[0].name, 'test');
assert.equal(params[0].optional, false);
m = re.exec('/route');
assert.ok(!m);
m = re.exec('/route/');
assert.equal(m.length, 2);
assert.equal(m[0], '/route/');
assert.equal(m[1], 'route');
m = re.exec('/route//');
assert.ok(!m);
});
it('should allow optional express format params', function () {
var params = [];
var re = pathToRegExp('/:test?', params);
var m;
assert.equal(params.length, 1);
assert.equal(params[0].name, 'test');
assert.equal(params[0].optional, true);
m = re.exec('/route');
assert.equal(m.length, 2);
assert.equal(m[0], '/route');
assert.equal(m[1], 'route');
m = re.exec('/');
assert.equal(m.length, 2);
assert.equal(m[0], '/');
assert.equal(m[1], undefined);
});
it('should allow express format param regexps', function () {
var params = [];
var m = pathToRegExp('/:page(\\d+)', params).exec('/56');
assert.equal(params.length, 1);
assert.equal(params[0].name, 'page');
assert.equal(params[0].optional, false);
assert.equal(m.length, 2);
assert.equal(m[0], '/56');
assert.equal(m[1], '56');
});
it('should match without a prefixed slash', function () {
var params = [];
var m = pathToRegExp(':test', params).exec('string');
assert.equal(params.length, 1);
assert.equal(params[0].name, 'test');
assert.equal(params[0].optional, false);
assert.equal(m.length, 2);
assert.equal(m[0], 'string');
assert.equal(m[1], 'string');
});
it('should not match format parts', function () {
var params = [];
var m = pathToRegExp('/:test.json', params).exec('/route.json');
assert.equal(params.length, 1);
assert.equal(params[0].name, 'test');
assert.equal(params[0].optional, false);
assert.equal(m.length, 2);
assert.equal(m[0], '/route.json');
assert.equal(m[1], 'route');
});
it('should match format parts', function () {
var params = [];
var re = pathToRegExp('/:test.:format', params);
var m;
assert.equal(params.length, 2);
assert.equal(params[0].name, 'test');
assert.equal(params[0].optional, false);
assert.equal(params[1].name, 'format');
assert.equal(params[1].optional, false);
m = re.exec('/route.json');
assert.equal(m.length, 3);
assert.equal(m[0], '/route.json');
assert.equal(m[1], 'route');
assert.equal(m[2], 'json');
m = re.exec('/route');
assert.ok(!m);
});
it('should match route parts with a trailing format', function () {
var params = [];
var m = pathToRegExp('/:test.json', params).exec('/route.json');
assert.equal(params.length, 1);
assert.equal(params[0].name, 'test');
assert.equal(params[0].optional, false);
assert.equal(m.length, 2);
assert.equal(m[0], '/route.json');
assert.equal(m[1], 'route');
});
it('should match optional trailing routes', function () {
var params = [];
var m = pathToRegExp('/test*', params).exec('/test/route');
assert.equal(params.length, 0);
assert.equal(m.length, 2);
assert.equal(m[0], '/test/route');
assert.equal(m[1], '/route');
});
it('should match optional trailing routes after a param', function () {
var params = [];
var re = pathToRegExp('/:test*', params);
var m;
assert.equal(params.length, 1);
assert.equal(params[0].name, 'test');
assert.equal(params[0].optional, false);
m = re.exec('/test/route');
assert.equal(m.length, 3);
assert.equal(m[0], '/test/route');
assert.equal(m[1], 'test');
assert.equal(m[2], '/route');
m = re.exec('/testing');
assert.equal(m.length, 3);
assert.equal(m[0], '/testing');
assert.equal(m[1], 'testing');
assert.equal(m[2], '');
});
it('should match optional trailing routes before a format', function () {
var params = [];
var re = pathToRegExp('/test*.json', params);
var m;
assert.equal(params.length, 0);
m = re.exec('/test.json');
assert.equal(m.length, 2);
assert.equal(m[0], '/test.json');
assert.equal(m[1], '');
m = re.exec('/testing.json');
assert.equal(m.length, 2);
assert.equal(m[0], '/testing.json');
assert.equal(m[1], 'ing');
m = re.exec('/test/route.json');
assert.equal(m.length, 2);
assert.equal(m[0], '/test/route.json');
assert.equal(m[1], '/route');
});
it('should match optional trailing routes after a param and before a format', function () {
var params = [];
var re = pathToRegExp('/:test*.json', params);
var m;
assert.equal(params.length, 1);
assert.equal(params[0].name, 'test');
assert.equal(params[0].optional, false);
m = re.exec('/testing.json');
assert.equal(m.length, 3);
assert.equal(m[0], '/testing.json');
assert.equal(m[1], 'testing');
assert.equal(m[2], '');
m = re.exec('/test/route.json');
assert.equal(m.length, 3);
assert.equal(m[0], '/test/route.json');
assert.equal(m[1], 'test');
assert.equal(m[2], '/route');
m = re.exec('.json');
assert.ok(!m);
});
it('should match optional trailing routes between a normal param and a format param', function () {
var params = [];
var re = pathToRegExp('/:test*.:format', params);
var m;
assert.equal(params.length, 2);
assert.equal(params[0].name, 'test');
assert.equal(params[0].optional, false);
assert.equal(params[1].name, 'format');
assert.equal(params[1].optional, false);
m = re.exec('/testing.json');
assert.equal(m.length, 4);
assert.equal(m[0], '/testing.json');
assert.equal(m[1], 'testing');
assert.equal(m[2], '');
assert.equal(m[3], 'json');
m = re.exec('/test/route.json');
assert.equal(m.length, 4);
assert.equal(m[0], '/test/route.json');
assert.equal(m[1], 'test');
assert.equal(m[2], '/route');
assert.equal(m[3], 'json');
m = re.exec('/test');
assert.ok(!m);
m = re.exec('.json');
assert.ok(!m);
});
it('should match optional trailing routes after a param and before an optional format param', function () {
var params = [];
var re = pathToRegExp('/:test*.:format?', params);
var m;
assert.equal(params.length, 2);
assert.equal(params[0].name, 'test');
assert.equal(params[0].optional, false);
assert.equal(params[1].name, 'format');
assert.equal(params[1].optional, true);
m = re.exec('/testing.json');
assert.equal(m.length, 4);
assert.equal(m[0], '/testing.json');
assert.equal(m[1], 'testing');
assert.equal(m[2], '');
assert.equal(m[3], 'json');
m = re.exec('/test/route.json');
assert.equal(m.length, 4);
assert.equal(m[0], '/test/route.json');
assert.equal(m[1], 'test');
assert.equal(m[2], '/route');
assert.equal(m[3], 'json');
m = re.exec('/test');
assert.equal(m.length, 4);
assert.equal(m[0], '/test');
assert.equal(m[1], 'test');
assert.equal(m[2], '');
assert.equal(m[3], undefined);
m = re.exec('.json');
assert.ok(!m);
});
it('should match optional trailing routes inside optional express param', function () {
var params = [];
var re = pathToRegExp('/:test*?', params);
var m;
assert.equal(params.length, 1);
assert.equal(params[0].name, 'test');
assert.equal(params[0].optional, true);
m = re.exec('/test/route');
assert.equal(m.length, 3);
assert.equal(m[0], '/test/route');
assert.equal(m[1], 'test');
assert.equal(m[2], '/route');
m = re.exec('/test');
assert.equal(m.length, 3);
assert.equal(m[0], '/test');
assert.equal(m[1], 'test');
assert.equal(m[2], '');
m = re.exec('/');
assert.equal(m.length, 3);
assert.equal(m[0], '/');
assert.equal(m[1], undefined);
assert.equal(m[2], undefined);
});
it('should do case insensitive matches', function () {
var m = pathToRegExp('/test').exec('/TEST');
assert.equal(m[0], '/TEST');
});
it('should do case sensitive matches', function () {
var re = pathToRegExp('/test', null, { sensitive: true });
var m;
m = re.exec('/test');
assert.equal(m.length, 1);
assert.equal(m[0], '/test');
m = re.exec('/TEST');
assert.ok(!m);
});
it('should do non-ending matches', function () {
var params = [];
var m = pathToRegExp('/:test', params, { end: false }).exec('/test/route');
assert.equal(params.length, 1);
assert.equal(params[0].name, 'test');
assert.equal(params[0].optional, false);
assert.equal(m.length, 2);
assert.equal(m[0], '/test');
assert.equal(m[1], 'test');
});
it('should match trailing slashes in non-ending non-strict mode', function () {
var params = [];
var re = pathToRegExp('/:test', params, { end: false });
var m;
assert.equal(params.length, 1);
assert.equal(params[0].name, 'test');
assert.equal(params[0].optional, false);
m = re.exec('/test/');
assert.equal(m.length, 2);
assert.equal(m[0], '/test/');
assert.equal(m[1], 'test');
});
it('should match trailing slashes in non-ending non-strict mode', function () {
var params = [];
var re = pathToRegExp('/route/', params, { end: false });
var m;
assert.equal(params.length, 0);
m = re.exec('/route/');
assert.equal(m.length, 1);
assert.equal(m[0], '/route/');
m = re.exec('/route/test');
assert.equal(m.length, 1);
assert.equal(m[0], '/route');
m = re.exec('/route');
assert.equal(m.length, 1);
assert.equal(m[0], '/route');
m = re.exec('/route//');
assert.equal(m.length, 1);
assert.equal(m[0], '/route/');
});
it('should match trailing slashing in non-ending strict mode', function () {
var params = [];
var re = pathToRegExp('/route/', params, { end: false, strict: true });
assert.equal(params.length, 0);
m = re.exec('/route/');
assert.equal(m.length, 1);
assert.equal(m[0], '/route/');
m = re.exec('/route/test');
assert.equal(m.length, 1);
assert.equal(m[0], '/route/');
m = re.exec('/route');
assert.ok(!m);
m = re.exec('/route//');
assert.equal(m.length, 1);
assert.equal(m[0], '/route/');
});
it('should not match trailing slashes in non-ending strict mode', function () {
var params = [];
var re = pathToRegExp('/route', params, { end: false, strict: true });
assert.equal(params.length, 0);
m = re.exec('/route');
assert.equal(m.length, 1);
assert.equal(m[0], '/route');
m = re.exec('/route/');
assert.ok(m.length, 1);
assert.equal(m[0], '/route');
});
it('should match text after an express param', function () {
var params = [];
var re = pathToRegExp('/(:test)route', params);
assert.equal(params.length, 1);
assert.equal(params[0].name, 'test');
assert.equal(params[0].optional, false);
m = re.exec('/route');
assert.ok(!m);
m = re.exec('/testroute');
assert.equal(m.length, 2);
assert.equal(m[0], '/testroute');
assert.equal(m[1], 'test');
m = re.exec('testroute');
assert.ok(!m);
});
it('should match text after an optional express param', function () {
var params = [];
var re = pathToRegExp('/(:test?)route', params);
var m;
assert.equal(params.length, 1);
assert.equal(params[0].name, 'test');
assert.equal(params[0].optional, true);
m = re.exec('/route');
assert.equal(m.length, 2);
assert.equal(m[0], '/route');
assert.equal(m[1], undefined);
m = re.exec('/testroute');
assert.equal(m.length, 2);
assert.equal(m[0], '/testroute');
assert.equal(m[1], 'test');
m = re.exec('route');
assert.ok(!m);
});
it('should match optional formats', function () {
var params = [];
var re = pathToRegExp('/:test.:format?', params);
var m;
assert.equal(params.length, 2);
assert.equal(params[0].name, 'test');
assert.equal(params[0].optional, false);
assert.equal(params[1].name, 'format');
assert.equal(params[1].optional, true);
m = re.exec('/route');
assert.equal(m.length, 3);
assert.equal(m[0], '/route');
assert.equal(m[1], 'route');
assert.equal(m[2], undefined);
m = re.exec('/route.json');
assert.equal(m.length, 3);
assert.equal(m[0], '/route.json');
assert.equal(m[1], 'route');
assert.equal(m[2], 'json');
});
it('should match full paths with format by default', function () {
var params = [];
var m = pathToRegExp('/:test', params).exec('/test.json');
assert.equal(params.length, 1);
assert.equal(params[0].name, 'test');
assert.equal(params[0].optional, false);
assert.equal(m.length, 2);
assert.equal(m[0], '/test.json');
assert.equal(m[1], 'test.json');
});
});
describe('regexps', function () {
it('should return the regexp', function () {
assert.deepEqual(pathToRegExp(/.*/), /.*/);
});
});
describe('arrays', function () {
it('should join arrays parts', function () {
var re = pathToRegExp(['/test', '/route']);
assert.ok(re.test('/test'));
assert.ok(re.test('/route'));
assert.ok(!re.test('/else'));
});
it('should match parts properly', function () {
var params = [];
var re = pathToRegExp(['/:test', '/test/:route'], params);
var m;
assert.equal(params.length, 2);
assert.equal(params[0].name, 'test');
assert.equal(params[0].optional, false);
assert.equal(params[1].name, 'route');
assert.equal(params[1].optional, false);
m = re.exec('/route');
assert.equal(m.length, 3);
assert.equal(m[0], '/route');
assert.equal(m[1], 'route');
assert.equal(m[2], undefined);
m = re.exec('/test/path');
assert.equal(m.length, 3);
assert.equal(m[0], '/test/path');
assert.equal(m[1], undefined);
assert.equal(m[2], 'path');
});
});
});

1.0.7 / 2015-03-16

  • deps: ipaddr.js@0.1.9
    • Fix OOM on certain inputs to isValid

1.0.6 / 2015-02-01

  • deps: ipaddr.js@0.1.8

1.0.5 / 2015-01-08

  • deps: ipaddr.js@0.1.6

1.0.4 / 2014-11-23

  • deps: ipaddr.js@0.1.5
    • Fix edge cases with isValid

1.0.3 / 2014-09-21

  • Use forwarded npm module

1.0.2 / 2014-09-18

  • Fix a global leak when multiple subnets are trusted
  • Support Node.js 0.6
  • deps: ipaddr.js@0.1.3

1.0.1 / 2014-06-03

  • Fix links in npm package

1.0.0 / 2014-05-08

  • Add trust argument to determine proxy trust on
    • Accepts custom function
    • Accepts IPv4/IPv6 address(es)
    • Accepts subnets
    • Accepts pre-defined names
  • Add optional trust argument to proxyaddr.all to stop at first untrusted
  • Add proxyaddr.compile to pre-compile trust function to make subsequent calls faster

0.0.1 / 2014-05-04

  • Fix bad npm publish

0.0.0 / 2014-05-04

  • Initial release
/*!
* proxy-addr
* Copyright(c) 2014 Douglas Christopher Wilson
* MIT Licensed
*/
/**
* Module exports.
*/
module.exports = proxyaddr;
module.exports.all = alladdrs;
module.exports.compile = compile;
/**
* Module dependencies.
*/
var forwarded = require('forwarded');
var ipaddr = require('ipaddr.js');
/**
* Variables.
*/
var digitre = /^[0-9]+$/;
var isip = ipaddr.isValid;
var parseip = ipaddr.parse;
/**
* Pre-defined IP ranges.
*/
var ipranges = {
linklocal: ['169.254.0.0/16', 'fe80::/10'],
loopback: ['127.0.0.1/8', '::1/128'],
uniquelocal: ['10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16', 'fc00::/7']
};
/**
* Get all addresses in the request, optionally stopping
* at the first untrusted.
*
* @param {Object} request
* @param {Function|Array|String} [trust]
* @api public
*/
function alladdrs(req, trust) {
// get addresses
var addrs = forwarded(req);
if (!trust) {
// Return all addresses
return addrs;
}
if (typeof trust !== 'function') {
trust = compile(trust);
}
for (var i = 0; i < addrs.length - 1; i++) {
if (trust(addrs[i], i)) continue;
addrs.length = i + 1;
}
return addrs;
}
/**
* Compile argument into trust function.
*
* @param {Array|String} val
* @api private
*/
function compile(val) {
if (!val) {
throw new TypeError('argument is required');
}
var trust = typeof val === 'string'
? [val]
: val;
if (!Array.isArray(trust)) {
throw new TypeError('unsupported trust argument');
}
for (var i = 0; i < trust.length; i++) {
val = trust[i];
if (!ipranges.hasOwnProperty(val)) {
continue;
}
// Splice in pre-defined range
val = ipranges[val];
trust.splice.apply(trust, [i, 1].concat(val));
i += val.length - 1;
}
return compileTrust(compileRangeSubnets(trust));
}
/**
* Compile `arr` elements into range subnets.
*
* @param {Array} arr
* @api private
*/
function compileRangeSubnets(arr) {
var rangeSubnets = new Array(arr.length);
for (var i = 0; i < arr.length; i++) {
rangeSubnets[i] = parseipNotation(arr[i]);
}
return rangeSubnets;
}
/**
* Compile range subnet array into trust function.
*
* @param {Array} rangeSubnets
* @api private
*/
function compileTrust(rangeSubnets) {
// Return optimized function based on length
var len = rangeSubnets.length;
return len === 0
? trustNone
: len === 1
? trustSingle(rangeSubnets[0])
: trustMulti(rangeSubnets);
}
/**
* Parse IP notation string into range subnet.
*
* @param {String} note
* @api private
*/
function parseipNotation(note) {
var ip;
var kind;
var max;
var pos = note.lastIndexOf('/');
var range;
ip = pos !== -1
? note.substring(0, pos)
: note;
if (!isip(ip)) {
throw new TypeError('invalid IP address: ' + ip);
}
ip = parseip(ip);
kind = ip.kind();
max = kind === 'ipv6'
? 128
: 32;
range = pos !== -1
? note.substring(pos + 1, note.length)
: max;
if (typeof range !== 'number') {
range = digitre.test(range)
? parseInt(range, 10)
: isip(range)
? parseNetmask(range)
: 0;
}
if (ip.kind() === 'ipv6' && ip.isIPv4MappedAddress()) {
// Store as IPv4
ip = ip.toIPv4Address();
range = range <= max
? range - 96
: range;
}
if (range <= 0 || range > max) {
throw new TypeError('invalid range on address: ' + note);
}
return [ip, range];
}
/**
* Parse netmask string into CIDR range.
*
* @param {String} note
* @api private
*/
function parseNetmask(netmask) {
var ip = parseip(netmask);
var parts;
var size;
switch (ip.kind()) {
case 'ipv4':
parts = ip.octets;
size = 8;
break;
case 'ipv6':
parts = ip.parts;
size = 16;
break;
}
var max = Math.pow(2, size) - 1;
var part;
var range = 0;
for (var i = 0; i < parts.length; i++) {
part = parts[i] & max;
if (part === max) {
range += size;
continue;
}
while (part) {
part = (part << 1) & max;
range += 1;
}
break;
}
return range;
}
/**
* Determine address of proxied request.
*
* @param {Object} request
* @param {Function|Array|String} trust
* @api public
*/
function proxyaddr(req, trust) {
if (!req) {
throw new TypeError('req argument is required');
}
if (!trust) {
throw new TypeError('trust argument is required');
}
var addrs = alladdrs(req, trust);
var addr = addrs[addrs.length - 1];
return addr;
}
/**
* Static trust function to trust nothing.
*
* @api private
*/
function trustNone() {
return false;
}
/**
* Compile trust function for multiple subnets.
*
* @param {Array} subnets
* @api private
*/
function trustMulti(subnets) {
return function trust(addr) {
if (!isip(addr)) return false;
var ip = parseip(addr);
var ipv4;
var kind = ip.kind();
var subnet;
var subnetip;
var subnetkind;
var subnetrange;
var trusted;
for (var i = 0; i < subnets.length; i++) {
subnet = subnets[i];
subnetip = subnet[0];
subnetkind = subnetip.kind();
subnetrange = subnet[1];
trusted = ip;
if (kind !== subnetkind) {
if (kind !== 'ipv6' || subnetkind !== 'ipv4' || !ip.isIPv4MappedAddress()) {
continue;
}
// Store addr as IPv4
ipv4 = ipv4 || ip.toIPv4Address();
trusted = ipv4;
}
if (trusted.match(subnetip, subnetrange)) return true;
}
return false;
};
}
/**
* Compile trust function for single subnet.
*
* @param {Object} subnet
* @api private
*/
function trustSingle(subnet) {
var subnetip = subnet[0];
var subnetkind = subnetip.kind();
var subnetisipv4 = subnetkind === 'ipv4';
var subnetrange = subnet[1];
return function trust(addr) {
if (!isip(addr)) return false;
var ip = parseip(addr);
var kind = ip.kind();
return kind === subnetkind
? ip.match(subnetip, subnetrange)
: subnetisipv4 && kind === 'ipv6' && ip.isIPv4MappedAddress()
? ip.toIPv4Address().match(subnetip, subnetrange)
: false;
};
}
(The MIT License)
Copyright (c) 2014 Douglas Christopher Wilson
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
/*!
* forwarded
* Copyright(c) 2014 Douglas Christopher Wilson
* MIT Licensed
*/
/**
* Module exports.
*/
module.exports = forwarded
/**
* Get all addresses in the request, using the `X-Forwarded-For` header.
*
* @param {Object} req
* @api public
*/
function forwarded(req) {
if (!req) {
throw new TypeError('argument req is required')
}
// simple header parsing
var proxyAddrs = (req.headers['x-forwarded-for'] || '')
.split(/ *, */)
.filter(Boolean)
.reverse()
var socketAddr = req.connection.remoteAddress
var addrs = [socketAddr].concat(proxyAddrs)
// return all addresses
return addrs
}
(The MIT License)
Copyright (c) 2014 Douglas Christopher Wilson
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
{
"name": "forwarded",
"description": "Parse HTTP X-Forwarded-For header",
"version": "0.1.0",
"contributors": [
{
"name": "Douglas Christopher Wilson",
"email": "doug@somethingdoug.com"
}
],
"license": "MIT",
"keywords": [
"x-forwarded-for",
"http",
"req"
],
"repository": {
"type": "git",
"url": "https://github.com/jshttp/forwarded"
},
"devDependencies": {
"istanbul": "0.3.2",
"mocha": "~1.21.4"
},
"files": [
"LICENSE",
"HISTORY.md",
"README.md",
"index.js"
],
"engines": {
"node": ">= 0.6"
},
"scripts": {
"test": "mocha --reporter spec --bail --check-leaks test/",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/"
},
"gitHead": "e9a9faeb3cfaadf40eb57d144fff26bca9b818e8",
"bugs": {
"url": "https://github.com/jshttp/forwarded/issues"
},
"homepage": "https://github.com/jshttp/forwarded",
"_id": "forwarded@0.1.0",
"_shasum": "19ef9874c4ae1c297bcf078fde63a09b66a84363",
"_from": "forwarded@>=0.1.0 <0.2.0",
"_npmVersion": "1.4.21",
"_npmUser": {
"name": "dougwilson",
"email": "doug@somethingdoug.com"
},
"maintainers": [
{
"name": "dougwilson",
"email": "doug@somethingdoug.com"
}
],
"dist": {
"shasum": "19ef9874c4ae1c297bcf078fde63a09b66a84363",
"tarball": "http://registry.npmjs.org/forwarded/-/forwarded-0.1.0.tgz"
},
"directories": {},
"_resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.0.tgz",
"readme": "ERROR: No README data found!"
}

forwarded

NPM Version NPM Downloads Node.js Version Build Status Test Coverage

Parse HTTP X-Forwarded-For header

Installation

$ npm install forwarded

API

var forwarded = require('forwarded')

forwarded(req)

var addresses = forwarded(req)

Parse the X-Forwarded-For header from the request. Returns an array of the addresses, including the socket address for the req. In reverse order (i.e. index 0 is the socket address and the last index is the furthest address, typically the end-user).

Testing

$ npm test

License

MIT

fs = require 'fs'
CoffeeScript = require 'coffee-script'
nodeunit = require 'nodeunit'
UglifyJS = require 'uglify-js'
task 'build', 'build the JavaScript files from CoffeeScript source', build = (cb) ->
source = fs.readFileSync 'src/ipaddr.coffee'
fs.writeFileSync 'lib/ipaddr.js', CoffeeScript.compile source.toString()
invoke 'test'
invoke 'compress'
task 'test', 'run the bundled tests', (cb) ->
nodeunit.reporters.default.run ['test']
task 'compress', 'uglify the resulting javascript', (cb) ->
result = UglifyJS.minify('lib/ipaddr.js')
fs.writeFileSync('ipaddr.min.js', result.code)
(function(){var t,r,n,e,i,o,a,s;r={},s=this,"undefined"!=typeof module&&null!==module&&module.exports?module.exports=r:s.ipaddr=r,a=function(t,r,n,e){var i,o;if(t.length!==r.length)throw new Error("ipaddr: cannot match CIDR for objects with different lengths");for(i=0;e>0;){if(o=n-e,0>o&&(o=0),t[i]>>o!==r[i]>>o)return!1;e-=n,i+=1}return!0},r.subnetMatch=function(t,r,n){var e,i,o,a,s;null==n&&(n="unicast");for(e in r)for(i=r[e],"[object Array]"!==toString.call(i[0])&&(i=[i]),a=0,s=i.length;s>a;a++)if(o=i[a],t.match.apply(t,o))return e;return n},r.IPv4=function(){function t(t){var r,n,e;if(4!==t.length)throw new Error("ipaddr: ipv4 octet count should be 4");for(n=0,e=t.length;e>n;n++)if(r=t[n],!(r>=0&&255>=r))throw new Error("ipaddr: ipv4 octet is a byte");this.octets=t}return t.prototype.kind=function(){return"ipv4"},t.prototype.toString=function(){return this.octets.join(".")},t.prototype.toByteArray=function(){return this.octets.slice(0)},t.prototype.match=function(t,r){if("ipv4"!==t.kind())throw new Error("ipaddr: cannot match ipv4 address with non-ipv4 one");return a(this.octets,t.octets,8,r)},t.prototype.SpecialRanges={unspecified:[[new t([0,0,0,0]),8]],broadcast:[[new t([255,255,255,255]),32]],multicast:[[new t([224,0,0,0]),4]],linkLocal:[[new t([169,254,0,0]),16]],loopback:[[new t([127,0,0,0]),8]],"private":[[new t([10,0,0,0]),8],[new t([172,16,0,0]),12],[new t([192,168,0,0]),16]],reserved:[[new t([192,0,0,0]),24],[new t([192,0,2,0]),24],[new t([192,88,99,0]),24],[new t([198,51,100,0]),24],[new t([203,0,113,0]),24],[new t([240,0,0,0]),4]]},t.prototype.range=function(){return r.subnetMatch(this,this.SpecialRanges)},t.prototype.toIPv4MappedAddress=function(){return r.IPv6.parse("::ffff:"+this.toString())},t}(),n="(0?\\d+|0x[a-f0-9]+)",e={fourOctet:new RegExp("^"+n+"\\."+n+"\\."+n+"\\."+n+"$","i"),longValue:new RegExp("^"+n+"$","i")},r.IPv4.parser=function(t){var r,n,i,o,a;if(n=function(t){return"0"===t[0]&&"x"!==t[1]?parseInt(t,8):parseInt(t)},r=t.match(e.fourOctet))return function(){var t,e,o,a;for(o=r.slice(1,6),a=[],t=0,e=o.length;e>t;t++)i=o[t],a.push(n(i));return a}();if(r=t.match(e.longValue)){if(a=n(r[1]),a>4294967295||0>a)throw new Error("ipaddr: address outside defined range");return function(){var t,r;for(r=[],o=t=0;24>=t;o=t+=8)r.push(a>>o&255);return r}().reverse()}return null},r.IPv6=function(){function t(t){var r,n,e;if(8!==t.length)throw new Error("ipaddr: ipv6 part count should be 8");for(n=0,e=t.length;e>n;n++)if(r=t[n],!(r>=0&&65535>=r))throw new Error("ipaddr: ipv6 part should fit to two octets");this.parts=t}return t.prototype.kind=function(){return"ipv6"},t.prototype.toString=function(){var t,r,n,e,i,o,a;for(i=function(){var t,n,e,i;for(e=this.parts,i=[],t=0,n=e.length;n>t;t++)r=e[t],i.push(r.toString(16));return i}.call(this),t=[],n=function(r){return t.push(r)},e=0,o=0,a=i.length;a>o;o++)switch(r=i[o],e){case 0:n("0"===r?"":r),e=1;break;case 1:"0"===r?e=2:n(r);break;case 2:"0"!==r&&(n(""),n(r),e=3);break;case 3:n(r)}return 2===e&&(n(""),n("")),t.join(":")},t.prototype.toByteArray=function(){var t,r,n,e,i;for(t=[],i=this.parts,n=0,e=i.length;e>n;n++)r=i[n],t.push(r>>8),t.push(255&r);return t},t.prototype.toNormalizedString=function(){var t;return function(){var r,n,e,i;for(e=this.parts,i=[],r=0,n=e.length;n>r;r++)t=e[r],i.push(t.toString(16));return i}.call(this).join(":")},t.prototype.match=function(t,r){if("ipv6"!==t.kind())throw new Error("ipaddr: cannot match ipv6 address with non-ipv6 one");return a(this.parts,t.parts,16,r)},t.prototype.SpecialRanges={unspecified:[new t([0,0,0,0,0,0,0,0]),128],linkLocal:[new t([65152,0,0,0,0,0,0,0]),10],multicast:[new t([65280,0,0,0,0,0,0,0]),8],loopback:[new t([0,0,0,0,0,0,0,1]),128],uniqueLocal:[new t([64512,0,0,0,0,0,0,0]),7],ipv4Mapped:[new t([0,0,0,0,0,65535,0,0]),96],rfc6145:[new t([0,0,0,0,65535,0,0,0]),96],rfc6052:[new t([100,65435,0,0,0,0,0,0]),96],"6to4":[new t([8194,0,0,0,0,0,0,0]),16],teredo:[new t([8193,0,0,0,0,0,0,0]),32],reserved:[[new t([8193,3512,0,0,0,0,0,0]),32]]},t.prototype.range=function(){return r.subnetMatch(this,this.SpecialRanges)},t.prototype.isIPv4MappedAddress=function(){return"ipv4Mapped"===this.range()},t.prototype.toIPv4Address=function(){var t,n,e;if(!this.isIPv4MappedAddress())throw new Error("ipaddr: trying to convert a generic ipv6 address to ipv4");return e=this.parts.slice(-2),t=e[0],n=e[1],new r.IPv4([t>>8,255&t,n>>8,255&n])},t}(),i="(?:[0-9a-f]+::?)+",o={"native":new RegExp("^(::)?("+i+")?([0-9a-f]+)?(::)?$","i"),transitional:new RegExp("^((?:"+i+")|(?:::)(?:"+i+")?)"+(""+n+"\\."+n+"\\."+n+"\\."+n+"$"),"i")},t=function(t,r){var n,e,i,o,a;if(t.indexOf("::")!==t.lastIndexOf("::"))return null;for(n=0,e=-1;(e=t.indexOf(":",e+1))>=0;)n++;if(":"===t[0]&&n--,":"===t[t.length-1]&&n--,n>r)return null;for(a=r-n,o=":";a--;)o+="0:";return t=t.replace("::",o),":"===t[0]&&(t=t.slice(1)),":"===t[t.length-1]&&(t=t.slice(0,-1)),function(){var r,n,e,o;for(e=t.split(":"),o=[],r=0,n=e.length;n>r;r++)i=e[r],o.push(parseInt(i,16));return o}()},r.IPv6.parser=function(r){var n,e;return r.match(o["native"])?t(r,8):(n=r.match(o.transitional))&&(e=t(n[1].slice(0,-1),6))?(e.push(parseInt(n[2])<<8|parseInt(n[3])),e.push(parseInt(n[4])<<8|parseInt(n[5])),e):null},r.IPv4.isIPv4=r.IPv6.isIPv6=function(t){return null!==this.parser(t)},r.IPv4.isValid=r.IPv6.isValid=function(t){var r;try{return new this(this.parser(t)),!0}catch(n){return r=n,!1}},r.IPv4.parse=r.IPv6.parse=function(t){var r;if(r=this.parser(t),null===r)throw new Error("ipaddr: string is not formatted like ip address");return new this(r)},r.isValid=function(t){return r.IPv6.isValid(t)||r.IPv4.isValid(t)},r.parse=function(t){if(r.IPv6.isValid(t))return r.IPv6.parse(t);if(r.IPv4.isValid(t))return r.IPv4.parse(t);throw new Error("ipaddr: the address has neither IPv6 nor IPv4 format")},r.process=function(t){var r;return r=this.parse(t),"ipv6"===r.kind()&&r.isIPv4MappedAddress()?r.toIPv4Address():r}}).call(this);
(function() {
var expandIPv6, ipaddr, ipv4Part, ipv4Regexes, ipv6Part, ipv6Regexes, matchCIDR, root;
ipaddr = {};
root = this;
if ((typeof module !== "undefined" && module !== null) && module.exports) {
module.exports = ipaddr;
} else {
root['ipaddr'] = ipaddr;
}
matchCIDR = function(first, second, partSize, cidrBits) {
var part, shift;
if (first.length !== second.length) {
throw new Error("ipaddr: cannot match CIDR for objects with different lengths");
}
part = 0;
while (cidrBits > 0) {
shift = partSize - cidrBits;
if (shift < 0) {
shift = 0;
}
if (first[part] >> shift !== second[part] >> shift) {
return false;
}
cidrBits -= partSize;
part += 1;
}
return true;
};
ipaddr.subnetMatch = function(address, rangeList, defaultName) {
var rangeName, rangeSubnets, subnet, _i, _len;
if (defaultName == null) {
defaultName = 'unicast';
}
for (rangeName in rangeList) {
rangeSubnets = rangeList[rangeName];
if (toString.call(rangeSubnets[0]) !== '[object Array]') {
rangeSubnets = [rangeSubnets];
}
for (_i = 0, _len = rangeSubnets.length; _i < _len; _i++) {
subnet = rangeSubnets[_i];
if (address.match.apply(address, subnet)) {
return rangeName;
}
}
}
return defaultName;
};
ipaddr.IPv4 = (function() {
function IPv4(octets) {
var octet, _i, _len;
if (octets.length !== 4) {
throw new Error("ipaddr: ipv4 octet count should be 4");
}
for (_i = 0, _len = octets.length; _i < _len; _i++) {
octet = octets[_i];
if (!((0 <= octet && octet <= 255))) {
throw new Error("ipaddr: ipv4 octet is a byte");
}
}
this.octets = octets;
}
IPv4.prototype.kind = function() {
return 'ipv4';
};
IPv4.prototype.toString = function() {
return this.octets.join(".");
};
IPv4.prototype.toByteArray = function() {
return this.octets.slice(0);
};
IPv4.prototype.match = function(other, cidrRange) {
if (other.kind() !== 'ipv4') {
throw new Error("ipaddr: cannot match ipv4 address with non-ipv4 one");
}
return matchCIDR(this.octets, other.octets, 8, cidrRange);
};
IPv4.prototype.SpecialRanges = {
unspecified: [[new IPv4([0, 0, 0, 0]), 8]],
broadcast: [[new IPv4([255, 255, 255, 255]), 32]],
multicast: [[new IPv4([224, 0, 0, 0]), 4]],
linkLocal: [[new IPv4([169, 254, 0, 0]), 16]],
loopback: [[new IPv4([127, 0, 0, 0]), 8]],
"private": [[new IPv4([10, 0, 0, 0]), 8], [new IPv4([172, 16, 0, 0]), 12], [new IPv4([192, 168, 0, 0]), 16]],
reserved: [[new IPv4([192, 0, 0, 0]), 24], [new IPv4([192, 0, 2, 0]), 24], [new IPv4([192, 88, 99, 0]), 24], [new IPv4([198, 51, 100, 0]), 24], [new IPv4([203, 0, 113, 0]), 24], [new IPv4([240, 0, 0, 0]), 4]]
};
IPv4.prototype.range = function() {
return ipaddr.subnetMatch(this, this.SpecialRanges);
};
IPv4.prototype.toIPv4MappedAddress = function() {
return ipaddr.IPv6.parse("::ffff:" + (this.toString()));
};
return IPv4;
})();
ipv4Part = "(0?\\d+|0x[a-f0-9]+)";
ipv4Regexes = {
fourOctet: new RegExp("^" + ipv4Part + "\\." + ipv4Part + "\\." + ipv4Part + "\\." + ipv4Part + "$", 'i'),
longValue: new RegExp("^" + ipv4Part + "$", 'i')
};
ipaddr.IPv4.parser = function(string) {
var match, parseIntAuto, part, shift, value;
parseIntAuto = function(string) {
if (string[0] === "0" && string[1] !== "x") {
return parseInt(string, 8);
} else {
return parseInt(string);
}
};
if (match = string.match(ipv4Regexes.fourOctet)) {
return (function() {
var _i, _len, _ref, _results;
_ref = match.slice(1, 6);
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
part = _ref[_i];
_results.push(parseIntAuto(part));
}
return _results;
})();
} else if (match = string.match(ipv4Regexes.longValue)) {
value = parseIntAuto(match[1]);
if (value > 0xffffffff || value < 0) {
throw new Error("ipaddr: address outside defined range");
}
return ((function() {
var _i, _results;
_results = [];
for (shift = _i = 0; _i <= 24; shift = _i += 8) {
_results.push((value >> shift) & 0xff);
}
return _results;
})()).reverse();
} else {
return null;
}
};
ipaddr.IPv6 = (function() {
function IPv6(parts) {
var part, _i, _len;
if (parts.length !== 8) {
throw new Error("ipaddr: ipv6 part count should be 8");
}
for (_i = 0, _len = parts.length; _i < _len; _i++) {
part = parts[_i];
if (!((0 <= part && part <= 0xffff))) {
throw new Error("ipaddr: ipv6 part should fit to two octets");
}
}
this.parts = parts;
}
IPv6.prototype.kind = function() {
return 'ipv6';
};
IPv6.prototype.toString = function() {
var compactStringParts, part, pushPart, state, stringParts, _i, _len;
stringParts = (function() {
var _i, _len, _ref, _results;
_ref = this.parts;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
part = _ref[_i];
_results.push(part.toString(16));
}
return _results;
}).call(this);
compactStringParts = [];
pushPart = function(part) {
return compactStringParts.push(part);
};
state = 0;
for (_i = 0, _len = stringParts.length; _i < _len; _i++) {
part = stringParts[_i];
switch (state) {
case 0:
if (part === '0') {
pushPart('');
} else {
pushPart(part);
}
state = 1;
break;
case 1:
if (part === '0') {
state = 2;
} else {
pushPart(part);
}
break;
case 2:
if (part !== '0') {
pushPart('');
pushPart(part);
state = 3;
}
break;
case 3:
pushPart(part);
}
}
if (state === 2) {
pushPart('');
pushPart('');
}
return compactStringParts.join(":");
};
IPv6.prototype.toByteArray = function() {
var bytes, part, _i, _len, _ref;
bytes = [];
_ref = this.parts;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
part = _ref[_i];
bytes.push(part >> 8);
bytes.push(part & 0xff);
}
return bytes;
};
IPv6.prototype.toNormalizedString = function() {
var part;
return ((function() {
var _i, _len, _ref, _results;
_ref = this.parts;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
part = _ref[_i];
_results.push(part.toString(16));
}
return _results;
}).call(this)).join(":");
};
IPv6.prototype.match = function(other, cidrRange) {
if (other.kind() !== 'ipv6') {
throw new Error("ipaddr: cannot match ipv6 address with non-ipv6 one");
}
return matchCIDR(this.parts, other.parts, 16, cidrRange);
};
IPv6.prototype.SpecialRanges = {
unspecified: [new IPv6([0, 0, 0, 0, 0, 0, 0, 0]), 128],
linkLocal: [new IPv6([0xfe80, 0, 0, 0, 0, 0, 0, 0]), 10],
multicast: [new IPv6([0xff00, 0, 0, 0, 0, 0, 0, 0]), 8],
loopback: [new IPv6([0, 0, 0, 0, 0, 0, 0, 1]), 128],
uniqueLocal: [new IPv6([0xfc00, 0, 0, 0, 0, 0, 0, 0]), 7],
ipv4Mapped: [new IPv6([0, 0, 0, 0, 0, 0xffff, 0, 0]), 96],
rfc6145: [new IPv6([0, 0, 0, 0, 0xffff, 0, 0, 0]), 96],
rfc6052: [new IPv6([0x64, 0xff9b, 0, 0, 0, 0, 0, 0]), 96],
'6to4': [new IPv6([0x2002, 0, 0, 0, 0, 0, 0, 0]), 16],
teredo: [new IPv6([0x2001, 0, 0, 0, 0, 0, 0, 0]), 32],
reserved: [[new IPv6([0x2001, 0xdb8, 0, 0, 0, 0, 0, 0]), 32]]
};
IPv6.prototype.range = function() {
return ipaddr.subnetMatch(this, this.SpecialRanges);
};
IPv6.prototype.isIPv4MappedAddress = function() {
return this.range() === 'ipv4Mapped';
};
IPv6.prototype.toIPv4Address = function() {
var high, low, _ref;
if (!this.isIPv4MappedAddress()) {
throw new Error("ipaddr: trying to convert a generic ipv6 address to ipv4");
}
_ref = this.parts.slice(-2), high = _ref[0], low = _ref[1];
return new ipaddr.IPv4([high >> 8, high & 0xff, low >> 8, low & 0xff]);
};
return IPv6;
})();
ipv6Part = "(?:[0-9a-f]+::?)+";
ipv6Regexes = {
"native": new RegExp("^(::)?(" + ipv6Part + ")?([0-9a-f]+)?(::)?$", 'i'),
transitional: new RegExp(("^((?:" + ipv6Part + ")|(?:::)(?:" + ipv6Part + ")?)") + ("" + ipv4Part + "\\." + ipv4Part + "\\." + ipv4Part + "\\." + ipv4Part + "$"), 'i')
};
expandIPv6 = function(string, parts) {
var colonCount, lastColon, part, replacement, replacementCount;
if (string.indexOf('::') !== string.lastIndexOf('::')) {
return null;
}
colonCount = 0;
lastColon = -1;
while ((lastColon = string.indexOf(':', lastColon + 1)) >= 0) {
colonCount++;
}
if (string[0] === ':') {
colonCount--;
}
if (string[string.length - 1] === ':') {
colonCount--;
}
if (colonCount > parts) {
return null;
}
replacementCount = parts - colonCount;
replacement = ':';
while (replacementCount--) {
replacement += '0:';
}
string = string.replace('::', replacement);
if (string[0] === ':') {
string = string.slice(1);
}
if (string[string.length - 1] === ':') {
string = string.slice(0, -1);
}
return (function() {
var _i, _len, _ref, _results;
_ref = string.split(":");
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
part = _ref[_i];
_results.push(parseInt(part, 16));
}
return _results;
})();
};
ipaddr.IPv6.parser = function(string) {
var match, parts;
if (string.match(ipv6Regexes['native'])) {
return expandIPv6(string, 8);
} else if (match = string.match(ipv6Regexes['transitional'])) {
parts = expandIPv6(match[1].slice(0, -1), 6);
if (parts) {
parts.push(parseInt(match[2]) << 8 | parseInt(match[3]));
parts.push(parseInt(match[4]) << 8 | parseInt(match[5]));
return parts;
}
}
return null;
};
ipaddr.IPv4.isIPv4 = ipaddr.IPv6.isIPv6 = function(string) {
return this.parser(string) !== null;
};
ipaddr.IPv4.isValid = ipaddr.IPv6.isValid = function(string) {
var e;
try {
new this(this.parser(string));
return true;
} catch (_error) {
e = _error;
return false;
}
};
ipaddr.IPv4.parse = ipaddr.IPv6.parse = function(string) {
var parts;
parts = this.parser(string);
if (parts === null) {
throw new Error("ipaddr: string is not formatted like ip address");
}
return new this(parts);
};
ipaddr.isValid = function(string) {
return ipaddr.IPv6.isValid(string) || ipaddr.IPv4.isValid(string);
};
ipaddr.parse = function(string) {
if (ipaddr.IPv6.isValid(string)) {
return ipaddr.IPv6.parse(string);
} else if (ipaddr.IPv4.isValid(string)) {
return ipaddr.IPv4.parse(string);
} else {
throw new Error("ipaddr: the address has neither IPv6 nor IPv4 format");
}
};
ipaddr.process = function(string) {
var addr;
addr = this.parse(string);
if (addr.kind() === 'ipv6' && addr.isIPv4MappedAddress()) {
return addr.toIPv4Address();
} else {
return addr;
}
};
}).call(this);
Copyright (C) 2011 Peter Zotov <whitequark@whitequark.org>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
{
"name": "ipaddr.js",
"description": "A library for manipulating IPv4 and IPv6 addresses in JavaScript.",
"version": "0.1.9",
"author": {
"name": "Peter Zotov",
"email": "whitequark@whitequark.org"
},
"directories": {
"lib": "./lib"
},
"dependencies": {},
"devDependencies": {
"coffee-script": "~1.6",
"nodeunit": "~0.5.3",
"uglify-js": "latest"
},
"scripts": {
"test": "cake build test"
},
"keywords": [
"ip",
"ipv4",
"ipv6"
],
"repository": {
"type": "git",
"url": "git://github.com/whitequark/ipaddr.js"
},
"main": "./lib/ipaddr",
"engines": {
"node": ">= 0.2.5"
},
"license": "MIT",
"gitHead": "d51df7aa41ef1875215ae4ffbd324c486f8c2799",
"bugs": {
"url": "https://github.com/whitequark/ipaddr.js/issues"
},
"_id": "ipaddr.js@0.1.9",
"_shasum": "a9c78ccc12dc9010f296ab9aef2f61f432d69efa",
"_from": "ipaddr.js@0.1.9",
"_npmVersion": "1.4.21",
"_npmUser": {
"name": "whitequark",
"email": "whitequark@whitequark.org"
},
"maintainers": [
{
"name": "whitequark",
"email": "whitequark@whitequark.org"
}
],
"dist": {
"shasum": "a9c78ccc12dc9010f296ab9aef2f61f432d69efa",
"tarball": "http://registry.npmjs.org/ipaddr.js/-/ipaddr.js-0.1.9.tgz"
},
"_resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-0.1.9.tgz",
"readme": "ERROR: No README data found!",
"homepage": "https://github.com/whitequark/ipaddr.js"
}

ipaddr.js — an IPv6 and IPv4 address manipulation library

ipaddr.js is a small (1.9K minified and gzipped) library for manipulating IP addresses in JavaScript environments. It runs on both CommonJS runtimes (e.g. nodejs) and in a web browser.

ipaddr.js allows you to verify and parse string representation of an IP address, match it against a CIDR range or range list, determine if it falls into some reserved ranges (examples include loopback and private ranges), and convert between IPv4 and IPv4-mapped IPv6 addresses.

Installation

npm install ipaddr.js

API

ipaddr.js defines one object in the global scope: ipaddr. In CommonJS, it is exported from the module:

var ipaddr = require('ipaddr.js');

The API consists of several global methods and two classes: ipaddr.IPv6 and ipaddr.IPv4.

Global methods

There are three global methods defined: ipaddr.isValid, ipaddr.parse and ipaddr.process. All of them receive a string as a single parameter.

The ipaddr.isValid method returns true if the address is a valid IPv4 or IPv6 address, and false otherwise. It does not throw any exceptions.

The ipaddr.parse method returns an object representing the IP address, or throws an Error if the passed string is not a valid representation of an IP address.

The ipaddr.process method works just like the ipaddr.parse one, but it automatically converts IPv4-mapped IPv6 addresses to their IPv4 couterparts before returning. It is useful when you have a Node.js instance listening on an IPv6 socket, and the net.ivp6.bindv6only sysctl parameter (or its equivalent on non-Linux OS) is set to 0. In this case, you can accept IPv4 connections on your IPv6-only socket, but the remote address will be mangled. Use ipaddr.process method to automatically demangle it.

Object representation

Parsing methods return an object which descends from ipaddr.IPv6 or ipaddr.IPv4. These objects share some properties, but most of them differ.

Shared properties

One can determine the type of address by calling addr.kind(). It will return either "ipv6" or "ipv4".

An address can be converted back to its string representation with addr.toString(). Note that this method:

  • does not return the original string used to create the object (in fact, there is no way of getting that string)
  • returns a compact representation (when it is applicable)

A match(range, bits) method can be used to check if the address falls into a certain CIDR range. Note that an address can be (obviously) matched only against an address of the same type.

For example:

var addr = ipaddr.parse("2001:db8:1234::1");
var range = ipaddr.parse("2001:db8::");

addr.match(range, 32); // => true

A range() method returns one of predefined names for several special ranges defined by IP protocols. The exact names (and their respective CIDR ranges) can be looked up in the source: IPv6 ranges and IPv4 ranges. Some common ones include "unicast" (the default one) and "reserved".

You can match against your own range list by using ipaddr.subnetMatch(address, rangeList, defaultName) method. It can work with both IPv6 and IPv4 addresses, and accepts a name-to-subnet map as the range list. For example:

var rangeList = {
  documentationOnly: [ ipaddr.parse('2001:db8::'), 32 ],
  tunnelProviders: [
    [ ipaddr.parse('2001:470::'), 32 ], // he.net
    [ ipaddr.parse('2001:5c0::'), 32 ]  // freenet6
  ]
};
ipaddr.subnetMatch(ipaddr.parse('2001:470:8:66::1'), rangeList, 'unknown'); // => "he.net"

The addresses can be converted to their byte representation with toByteArray(). (Actually, JavaScript mostly does not know about byte buffers. They are emulated with arrays of numbers, each in range of 0..255.)

var bytes = ipaddr.parse('2a00:1450:8007::68').toByteArray(); // ipv6.google.com
bytes // => [42, 0x00, 0x14, 0x50, 0x80, 0x07, 0x00, <zeroes...>, 0x00, 0x68 ]

The ipaddr.IPv4 and ipaddr.IPv6 objects have some methods defined, too. All of them have the same interface for both protocols, and are similar to global methods.

ipaddr.IPvX.isValid(string) can be used to check if the string is a valid address for particular protocol, and ipaddr.IPvX.parse(string) is the error-throwing parser.

IPv6 properties

Sometimes you will want to convert IPv6 not to a compact string representation (with the :: substitution); the toNormalizedString() method will return an address where all zeroes are explicit.

For example:

var addr = ipaddr.parse("2001:0db8::0001");
addr.toString(); // => "2001:db8::1"
addr.toNormalizedString(); // => "2001:db8:0:0:0:0:0:1"

The isIPv4MappedAddress() method will return true if this address is an IPv4-mapped one, and toIPv4Address() will return an IPv4 object address.

To access the underlying binary representation of the address, use addr.parts.

var addr = ipaddr.parse("2001:db8:10::1234:DEAD");
addr.parts // => [0x2001, 0xdb8, 0x10, 0, 0, 0, 0x1234, 0xdead]

IPv4 properties

toIPv4MappedAddress() will return a corresponding IPv4-mapped IPv6 address.

To access the underlying representation of the address, use addr.octets.

var addr = ipaddr.parse("192.168.1.1");
addr.octets // => [192, 168, 1, 1]
# Define the main object
ipaddr = {}
root = this
# Export for both the CommonJS and browser-like environment
if module? && module.exports
module.exports = ipaddr
else
root['ipaddr'] = ipaddr
# A generic CIDR (Classless Inter-Domain Routing) RFC1518 range matcher.
matchCIDR = (first, second, partSize, cidrBits) ->
if first.length != second.length
throw new Error "ipaddr: cannot match CIDR for objects with different lengths"
part = 0
while cidrBits > 0
shift = partSize - cidrBits
shift = 0 if shift < 0
if first[part] >> shift != second[part] >> shift
return false
cidrBits -= partSize
part += 1
return true
# An utility function to ease named range matching. See examples below.
ipaddr.subnetMatch = (address, rangeList, defaultName='unicast') ->
for rangeName, rangeSubnets of rangeList
# ECMA5 Array.isArray isn't available everywhere
if toString.call(rangeSubnets[0]) != '[object Array]'
rangeSubnets = [ rangeSubnets ]
for subnet in rangeSubnets
return rangeName if address.match.apply(address, subnet)
return defaultName
# An IPv4 address (RFC791).
class ipaddr.IPv4
# Constructs a new IPv4 address from an array of four octets.
# Verifies the input.
constructor: (octets) ->
if octets.length != 4
throw new Error "ipaddr: ipv4 octet count should be 4"
for octet in octets
if !(0 <= octet <= 255)
throw new Error "ipaddr: ipv4 octet is a byte"
@octets = octets
# The 'kind' method exists on both IPv4 and IPv6 classes.
kind: ->
return 'ipv4'
# Returns the address in convenient, decimal-dotted format.
toString: ->
return @octets.join "."
# Returns an array of byte-sized values in network order
toByteArray: ->
return @octets.slice(0) # octets.clone
# Checks if this address matches other one within given CIDR range.
match: (other, cidrRange) ->
if other.kind() != 'ipv4'
throw new Error "ipaddr: cannot match ipv4 address with non-ipv4 one"
return matchCIDR(this.octets, other.octets, 8, cidrRange)
# Special IPv4 address ranges.
SpecialRanges:
unspecified: [
[ new IPv4([0, 0, 0, 0]), 8 ]
]
broadcast: [
[ new IPv4([255, 255, 255, 255]), 32 ]
]
multicast: [ # RFC3171
[ new IPv4([224, 0, 0, 0]), 4 ]
]
linkLocal: [ # RFC3927
[ new IPv4([169, 254, 0, 0]), 16 ]
]
loopback: [ # RFC5735
[ new IPv4([127, 0, 0, 0]), 8 ]
]
private: [ # RFC1918
[ new IPv4([10, 0, 0, 0]), 8 ]
[ new IPv4([172, 16, 0, 0]), 12 ]
[ new IPv4([192, 168, 0, 0]), 16 ]
]
reserved: [ # Reserved and testing-only ranges; RFCs 5735, 5737, 2544, 1700
[ new IPv4([192, 0, 0, 0]), 24 ]
[ new IPv4([192, 0, 2, 0]), 24 ]
[ new IPv4([192, 88, 99, 0]), 24 ]
[ new IPv4([198, 51, 100, 0]), 24 ]
[ new IPv4([203, 0, 113, 0]), 24 ]
[ new IPv4([240, 0, 0, 0]), 4 ]
]
# Checks if the address corresponds to one of the special ranges.
range: ->
return ipaddr.subnetMatch(this, @SpecialRanges)
# Convrets this IPv4 address to an IPv4-mapped IPv6 address.
toIPv4MappedAddress: ->
return ipaddr.IPv6.parse "::ffff:#{@toString()}"
# A list of regular expressions that match arbitrary IPv4 addresses,
# for which a number of weird notations exist.
# Note that an address like 0010.0xa5.1.1 is considered legal.
ipv4Part = "(0?\\d+|0x[a-f0-9]+)"
ipv4Regexes =
fourOctet: new RegExp "^#{ipv4Part}\\.#{ipv4Part}\\.#{ipv4Part}\\.#{ipv4Part}$", 'i'
longValue: new RegExp "^#{ipv4Part}$", 'i'
# Classful variants (like a.b, where a is an octet, and b is a 24-bit
# value representing last three octets; this corresponds to a class C
# address) are omitted due to classless nature of modern Internet.
ipaddr.IPv4.parser = (string) ->
parseIntAuto = (string) ->
if string[0] == "0" && string[1] != "x"
parseInt(string, 8)
else
parseInt(string)
# parseInt recognizes all that octal & hexadecimal weirdness for us
if match = string.match(ipv4Regexes.fourOctet)
return (parseIntAuto(part) for part in match[1..5])
else if match = string.match(ipv4Regexes.longValue)
value = parseIntAuto(match[1])
if value > 0xffffffff || value < 0
throw new Error "ipaddr: address outside defined range"
return ((value >> shift) & 0xff for shift in [0..24] by 8).reverse()
else
return null
# An IPv6 address (RFC2460)
class ipaddr.IPv6
# Constructs an IPv6 address from an array of eight 16-bit parts.
# Throws an error if the input is invalid.
constructor: (parts) ->
if parts.length != 8
throw new Error "ipaddr: ipv6 part count should be 8"
for part in parts
if !(0 <= part <= 0xffff)
throw new Error "ipaddr: ipv6 part should fit to two octets"
@parts = parts
# The 'kind' method exists on both IPv4 and IPv6 classes.
kind: ->
return 'ipv6'
# Returns the address in compact, human-readable format like
# 2001:db8:8:66::1
toString: ->
stringParts = (part.toString(16) for part in @parts)
compactStringParts = []
pushPart = (part) -> compactStringParts.push part
state = 0
for part in stringParts
switch state
when 0
if part == '0'
pushPart('')
else
pushPart(part)
state = 1
when 1
if part == '0'
state = 2
else
pushPart(part)
when 2
unless part == '0'
pushPart('')
pushPart(part)
state = 3
when 3
pushPart(part)
if state == 2
pushPart('')
pushPart('')
return compactStringParts.join ":"
# Returns an array of byte-sized values in network order
toByteArray: ->
bytes = []
for part in @parts
bytes.push(part >> 8)
bytes.push(part & 0xff)
return bytes
# Returns the address in expanded format with all zeroes included, like
# 2001:db8:8:66:0:0:0:1
toNormalizedString: ->
return (part.toString(16) for part in @parts).join ":"
# Checks if this address matches other one within given CIDR range.
match: (other, cidrRange) ->
if other.kind() != 'ipv6'
throw new Error "ipaddr: cannot match ipv6 address with non-ipv6 one"
return matchCIDR(this.parts, other.parts, 16, cidrRange)
# Special IPv6 ranges
SpecialRanges:
unspecified: [ new IPv6([0, 0, 0, 0, 0, 0, 0, 0]), 128 ] # RFC4291, here and after
linkLocal: [ new IPv6([0xfe80, 0, 0, 0, 0, 0, 0, 0]), 10 ]
multicast: [ new IPv6([0xff00, 0, 0, 0, 0, 0, 0, 0]), 8 ]
loopback: [ new IPv6([0, 0, 0, 0, 0, 0, 0, 1]), 128 ]
uniqueLocal: [ new IPv6([0xfc00, 0, 0, 0, 0, 0, 0, 0]), 7 ]
ipv4Mapped: [ new IPv6([0, 0, 0, 0, 0, 0xffff, 0, 0]), 96 ]
rfc6145: [ new IPv6([0, 0, 0, 0, 0xffff, 0, 0, 0]), 96 ] # RFC6145
rfc6052: [ new IPv6([0x64, 0xff9b, 0, 0, 0, 0, 0, 0]), 96 ] # RFC6052
'6to4': [ new IPv6([0x2002, 0, 0, 0, 0, 0, 0, 0]), 16 ] # RFC3056
teredo: [ new IPv6([0x2001, 0, 0, 0, 0, 0, 0, 0]), 32 ] # RFC6052, RFC6146
reserved: [
[ new IPv6([ 0x2001, 0xdb8, 0, 0, 0, 0, 0, 0]), 32 ] # RFC4291
]
# Checks if the address corresponds to one of the special ranges.
range: ->
return ipaddr.subnetMatch(this, @SpecialRanges)
# Checks if this address is an IPv4-mapped IPv6 address.
isIPv4MappedAddress: ->
return @range() == 'ipv4Mapped'
# Converts this address to IPv4 address if it is an IPv4-mapped IPv6 address.
# Throws an error otherwise.
toIPv4Address: ->
unless @isIPv4MappedAddress()
throw new Error "ipaddr: trying to convert a generic ipv6 address to ipv4"
[high, low] = @parts[-2..-1]
return new ipaddr.IPv4([high >> 8, high & 0xff, low >> 8, low & 0xff])
# IPv6-matching regular expressions.
# For IPv6, the task is simpler: it is enough to match the colon-delimited
# hexadecimal IPv6 and a transitional variant with dotted-decimal IPv4 at
# the end.
ipv6Part = "(?:[0-9a-f]+::?)+"
ipv6Regexes =
native: new RegExp "^(::)?(#{ipv6Part})?([0-9a-f]+)?(::)?$", 'i'
transitional: new RegExp "^((?:#{ipv6Part})|(?:::)(?:#{ipv6Part})?)" +
"#{ipv4Part}\\.#{ipv4Part}\\.#{ipv4Part}\\.#{ipv4Part}$", 'i'
# Expand :: in an IPv6 address or address part consisting of `parts` groups.
expandIPv6 = (string, parts) ->
# More than one '::' means invalid adddress
if string.indexOf('::') != string.lastIndexOf('::')
return null
# How many parts do we already have?
colonCount = 0
lastColon = -1
while (lastColon = string.indexOf(':', lastColon + 1)) >= 0
colonCount++
# 0::0 is two parts more than ::
colonCount-- if string[0] == ':'
colonCount-- if string[string.length-1] == ':'
# The following loop would hang if colonCount > parts
if colonCount > parts
return null
# replacement = ':' + '0:' * (parts - colonCount)
replacementCount = parts - colonCount
replacement = ':'
while replacementCount--
replacement += '0:'
# Insert the missing zeroes
string = string.replace('::', replacement)
# Trim any garbage which may be hanging around if :: was at the edge in
# the source string
string = string[1..-1] if string[0] == ':'
string = string[0..-2] if string[string.length-1] == ':'
return (parseInt(part, 16) for part in string.split(":"))
# Parse an IPv6 address.
ipaddr.IPv6.parser = (string) ->
if string.match(ipv6Regexes['native'])
return expandIPv6(string, 8)
else if match = string.match(ipv6Regexes['transitional'])
parts = expandIPv6(match[1][0..-2], 6)
if parts
parts.push(parseInt(match[2]) << 8 | parseInt(match[3]))
parts.push(parseInt(match[4]) << 8 | parseInt(match[5]))
return parts
return null
# Checks if a given string is formatted like IPv4/IPv6 address.
ipaddr.IPv4.isIPv4 = ipaddr.IPv6.isIPv6 = (string) ->
return @parser(string) != null
# Checks if a given string is a valid IPv4/IPv6 address.
ipaddr.IPv4.isValid = ipaddr.IPv6.isValid = (string) ->
try
new this(@parser(string))
return true
catch e
return false
# Tries to parse and validate a string with IPv4/IPv6 address.
# Throws an error if it fails.
ipaddr.IPv4.parse = ipaddr.IPv6.parse = (string) ->
parts = @parser(string)
if parts == null
throw new Error "ipaddr: string is not formatted like ip address"
return new this(parts)
# Checks if the address is valid IP address
ipaddr.isValid = (string) ->
return ipaddr.IPv6.isValid(string) || ipaddr.IPv4.isValid(string)
# Try to parse an address and throw an error if it is impossible
ipaddr.parse = (string) ->
if ipaddr.IPv6.isValid(string)
return ipaddr.IPv6.parse(string)
else if ipaddr.IPv4.isValid(string)
return ipaddr.IPv4.parse(string)
else
throw new Error "ipaddr: the address has neither IPv6 nor IPv4 format"
# Parse an address and return plain IPv4 address if it is an IPv4-mapped address
ipaddr.process = (string) ->
addr = @parse(string)
if addr.kind() == 'ipv6' && addr.isIPv4MappedAddress()
return addr.toIPv4Address()
else
return addr
ipaddr = require '../lib/ipaddr'
module.exports =
'should define main classes': (test) ->
test.ok(ipaddr.IPv4?, 'defines IPv4 class')
test.ok(ipaddr.IPv6?, 'defines IPv6 class')
test.done()
'can construct IPv4 from octets': (test) ->
test.doesNotThrow ->
new ipaddr.IPv4([192, 168, 1, 2])
test.done()
'refuses to construct invalid IPv4': (test) ->
test.throws ->
new ipaddr.IPv4([300, 1, 2, 3])
test.throws ->
new ipaddr.IPv4([8, 8, 8])
test.done()
'converts IPv4 to string correctly': (test) ->
addr = new ipaddr.IPv4([192, 168, 1, 1])
test.equal(addr.toString(), '192.168.1.1')
test.done()
'returns correct kind for IPv4': (test) ->
addr = new ipaddr.IPv4([1, 2, 3, 4])
test.equal(addr.kind(), 'ipv4')
test.done()
'allows to access IPv4 octets': (test) ->
addr = new ipaddr.IPv4([42, 0, 0, 0])
test.equal(addr.octets[0], 42)
test.done()
'checks IPv4 address format': (test) ->
test.equal(ipaddr.IPv4.isIPv4('192.168.007.0xa'), true)
test.equal(ipaddr.IPv4.isIPv4('1024.0.0.1'), true)
test.equal(ipaddr.IPv4.isIPv4('8.0xa.wtf.6'), false)
test.done()
'validates IPv4 addresses': (test) ->
test.equal(ipaddr.IPv4.isValid('192.168.007.0xa'), true)
test.equal(ipaddr.IPv4.isValid('1024.0.0.1'), false)
test.equal(ipaddr.IPv4.isValid('8.0xa.wtf.6'), false)
test.done()
'parses IPv4 in several weird formats': (test) ->
test.deepEqual(ipaddr.IPv4.parse('192.168.1.1').octets, [192, 168, 1, 1])
test.deepEqual(ipaddr.IPv4.parse('0xc0.168.1.1').octets, [192, 168, 1, 1])
test.deepEqual(ipaddr.IPv4.parse('192.0250.1.1').octets, [192, 168, 1, 1])
test.deepEqual(ipaddr.IPv4.parse('0xc0a80101').octets, [192, 168, 1, 1])
test.deepEqual(ipaddr.IPv4.parse('030052000401').octets, [192, 168, 1, 1])
test.deepEqual(ipaddr.IPv4.parse('3232235777').octets, [192, 168, 1, 1])
test.done()
'barfs at invalid IPv4': (test) ->
test.throws ->
ipaddr.IPv4.parse('10.0.0.wtf')
test.done()
'matches IPv4 CIDR correctly': (test) ->
addr = new ipaddr.IPv4([10, 5, 0, 1])
test.equal(addr.match(ipaddr.IPv4.parse('0.0.0.0'), 0), true)
test.equal(addr.match(ipaddr.IPv4.parse('11.0.0.0'), 8), false)
test.equal(addr.match(ipaddr.IPv4.parse('10.0.0.0'), 8), true)
test.equal(addr.match(ipaddr.IPv4.parse('10.0.0.1'), 8), true)
test.equal(addr.match(ipaddr.IPv4.parse('10.0.0.10'), 8), true)
test.equal(addr.match(ipaddr.IPv4.parse('10.5.5.0'), 16), true)
test.equal(addr.match(ipaddr.IPv4.parse('10.4.5.0'), 16), false)
test.equal(addr.match(ipaddr.IPv4.parse('10.4.5.0'), 15), true)
test.equal(addr.match(ipaddr.IPv4.parse('10.5.0.2'), 32), false)
test.equal(addr.match(addr, 32), true)
test.done()
'detects reserved IPv4 networks': (test) ->
test.equal(ipaddr.IPv4.parse('0.0.0.0').range(), 'unspecified')
test.equal(ipaddr.IPv4.parse('0.1.0.0').range(), 'unspecified')
test.equal(ipaddr.IPv4.parse('10.1.0.1').range(), 'private')
test.equal(ipaddr.IPv4.parse('192.168.2.1').range(), 'private')
test.equal(ipaddr.IPv4.parse('224.100.0.1').range(), 'multicast')
test.equal(ipaddr.IPv4.parse('169.254.15.0').range(), 'linkLocal')
test.equal(ipaddr.IPv4.parse('127.1.1.1').range(), 'loopback')
test.equal(ipaddr.IPv4.parse('255.255.255.255').range(), 'broadcast')
test.equal(ipaddr.IPv4.parse('240.1.2.3').range(), 'reserved')
test.equal(ipaddr.IPv4.parse('8.8.8.8').range(), 'unicast')
test.done()
'can construct IPv6 from parts': (test) ->
test.doesNotThrow ->
new ipaddr.IPv6([0x2001, 0xdb8, 0xf53a, 0, 0, 0, 0, 1])
test.done()
'refuses to construct invalid IPv6': (test) ->
test.throws ->
new ipaddr.IPv6([0xfffff, 0, 0, 0, 0, 0, 0, 1])
test.throws ->
new ipaddr.IPv6([0xfffff, 0, 0, 0, 0, 0, 1])
test.done()
'converts IPv6 to string correctly': (test) ->
addr = new ipaddr.IPv6([0x2001, 0xdb8, 0xf53a, 0, 0, 0, 0, 1])
test.equal(addr.toNormalizedString(), '2001:db8:f53a:0:0:0:0:1')
test.equal(addr.toString(), '2001:db8:f53a::1')
test.equal(new ipaddr.IPv6([0, 0, 0, 0, 0, 0, 0, 1]).toString(), '::1')
test.equal(new ipaddr.IPv6([0x2001, 0xdb8, 0, 0, 0, 0, 0, 0]).toString(), '2001:db8::')
test.done()
'returns correct kind for IPv6': (test) ->
addr = new ipaddr.IPv6([0x2001, 0xdb8, 0xf53a, 0, 0, 0, 0, 1])
test.equal(addr.kind(), 'ipv6')
test.done()
'allows to access IPv6 address parts': (test) ->
addr = new ipaddr.IPv6([0x2001, 0xdb8, 0xf53a, 0, 0, 42, 0, 1])
test.equal(addr.parts[5], 42)
test.done()
'checks IPv6 address format': (test) ->
test.equal(ipaddr.IPv6.isIPv6('2001:db8:F53A::1'), true)
test.equal(ipaddr.IPv6.isIPv6('200001::1'), true)
test.equal(ipaddr.IPv6.isIPv6('::ffff:192.168.1.1'), true)
test.equal(ipaddr.IPv6.isIPv6('::ffff:300.168.1.1'), true)
test.equal(ipaddr.IPv6.isIPv6('::ffff:300.168.1.1:0'), false)
test.equal(ipaddr.IPv6.isIPv6('fe80::wtf'), false)
test.done()
'validates IPv6 addresses': (test) ->
test.equal(ipaddr.IPv6.isValid('2001:db8:F53A::1'), true)
test.equal(ipaddr.IPv6.isValid('200001::1'), false)
test.equal(ipaddr.IPv6.isValid('::ffff:192.168.1.1'), true)
test.equal(ipaddr.IPv6.isValid('::ffff:300.168.1.1'), false)
test.equal(ipaddr.IPv6.isValid('::ffff:300.168.1.1:0'), false)
test.equal(ipaddr.IPv6.isValid('2001:db8::F53A::1'), false)
test.equal(ipaddr.IPv6.isValid('fe80::wtf'), false)
test.done()
'parses IPv6 in different formats': (test) ->
test.deepEqual(ipaddr.IPv6.parse('2001:db8:F53A:0:0:0:0:1').parts, [0x2001, 0xdb8, 0xf53a, 0, 0, 0, 0, 1])
test.deepEqual(ipaddr.IPv6.parse('fe80::10').parts, [0xfe80, 0, 0, 0, 0, 0, 0, 0x10])
test.deepEqual(ipaddr.IPv6.parse('2001:db8:F53A::').parts, [0x2001, 0xdb8, 0xf53a, 0, 0, 0, 0, 0])
test.deepEqual(ipaddr.IPv6.parse('::1').parts, [0, 0, 0, 0, 0, 0, 0, 1])
test.deepEqual(ipaddr.IPv6.parse('::').parts, [0, 0, 0, 0, 0, 0, 0, 0])
test.done()
'barfs at invalid IPv6': (test) ->
test.throws ->
ipaddr.IPv6.parse('fe80::0::1')
test.done()
'matches IPv6 CIDR correctly': (test) ->
addr = ipaddr.IPv6.parse('2001:db8:f53a::1')
test.equal(addr.match(ipaddr.IPv6.parse('::'), 0), true)
test.equal(addr.match(ipaddr.IPv6.parse('2001:db8:f53a::1:1'), 64), true)
test.equal(addr.match(ipaddr.IPv6.parse('2001:db8:f53b::1:1'), 48), false)
test.equal(addr.match(ipaddr.IPv6.parse('2001:db8:f531::1:1'), 44), true)
test.equal(addr.match(ipaddr.IPv6.parse('2001:db8:f500::1'), 40), true)
test.equal(addr.match(ipaddr.IPv6.parse('2001:db9:f500::1'), 40), false)
test.equal(addr.match(addr, 128), true)
test.done()
'converts between IPv4-mapped IPv6 addresses and IPv4 addresses': (test) ->
addr = ipaddr.IPv4.parse('77.88.21.11')
mapped = addr.toIPv4MappedAddress()
test.deepEqual(mapped.parts, [0, 0, 0, 0, 0, 0xffff, 0x4d58, 0x150b])
test.deepEqual(mapped.toIPv4Address().octets, addr.octets)
test.done()
'refuses to convert non-IPv4-mapped IPv6 address to IPv4 address': (test) ->
test.throws ->
ipaddr.IPv6.parse('2001:db8::1').toIPv4Address()
test.done()
'detects reserved IPv6 networks': (test) ->
test.equal(ipaddr.IPv6.parse('::').range(), 'unspecified')
test.equal(ipaddr.IPv6.parse('fe80::1234:5678:abcd:0123').range(), 'linkLocal')
test.equal(ipaddr.IPv6.parse('ff00::1234').range(), 'multicast')
test.equal(ipaddr.IPv6.parse('::1').range(), 'loopback')
test.equal(ipaddr.IPv6.parse('fc00::').range(), 'uniqueLocal')
test.equal(ipaddr.IPv6.parse('::ffff:192.168.1.10').range(), 'ipv4Mapped')
test.equal(ipaddr.IPv6.parse('::ffff:0:192.168.1.10').range(), 'rfc6145')
test.equal(ipaddr.IPv6.parse('64:ff9b::1234').range(), 'rfc6052')
test.equal(ipaddr.IPv6.parse('2002:1f63:45e8::1').range(), '6to4')
test.equal(ipaddr.IPv6.parse('2001::4242').range(), 'teredo')
test.equal(ipaddr.IPv6.parse('2001:db8::3210').range(), 'reserved')
test.equal(ipaddr.IPv6.parse('2001:470:8:66::1').range(), 'unicast')
test.done()
'is able to determine IP address type': (test) ->
test.equal(ipaddr.parse('8.8.8.8').kind(), 'ipv4')
test.equal(ipaddr.parse('2001:db8:3312::1').kind(), 'ipv6')
test.done()
'throws an error if tried to parse an invalid address': (test) ->
test.throws ->
ipaddr.parse('::some.nonsense')
test.done()
'correctly processes IPv4-mapped addresses': (test) ->
test.equal(ipaddr.process('8.8.8.8').kind(), 'ipv4')
test.equal(ipaddr.process('2001:db8:3312::1').kind(), 'ipv6')
test.equal(ipaddr.process('::ffff:192.168.1.1').kind(), 'ipv4')
test.done()
'correctly converts IPv6 and IPv4 addresses to byte arrays': (test) ->
test.deepEqual(ipaddr.parse('1.2.3.4').toByteArray(),
[0x1, 0x2, 0x3, 0x4]);
# Fuck yeah. The first byte of Google's IPv6 address is 42. 42!
test.deepEqual(ipaddr.parse('2a00:1450:8007::68').toByteArray(),
[42, 0x00, 0x14, 0x50, 0x80, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x68 ])
test.done()
'correctly parses 1 as an IPv4 address': (test) ->
test.equal(ipaddr.IPv6.isValid('1'), false)
test.equal(ipaddr.IPv4.isValid('1'), true)
test.deepEqual(new ipaddr.IPv4([0, 0, 0, 1]), ipaddr.parse('1'))
test.done()
'does not consider a very large or very small number a valid IP address': (test) ->
test.equal(ipaddr.isValid('4999999999'), false)
test.equal(ipaddr.isValid('-1'), false)
test.done()
'does not hang on ::8:8:8:8:8:8:8:8:8': (test) ->
test.equal(ipaddr.IPv6.isValid('::8:8:8:8:8:8:8:8:8'), false)
test.done()
{
"name": "proxy-addr",
"description": "Determine address of proxied request",
"version": "1.0.7",
"author": {
"name": "Douglas Christopher Wilson",
"email": "doug@somethingdoug.com"
},
"license": "MIT",
"keywords": [
"ip",
"proxy",
"x-forwarded-for"
],
"repository": {
"type": "git",
"url": "https://github.com/jshttp/proxy-addr"
},
"dependencies": {
"forwarded": "~0.1.0",
"ipaddr.js": "0.1.9"
},
"devDependencies": {
"benchmark": "1.0.0",
"beautify-benchmark": "0.2.4",
"istanbul": "0.3.8",
"mocha": "~1.21.5"
},
"files": [
"LICENSE",
"HISTORY.md",
"README.md",
"index.js"
],
"engines": {
"node": ">= 0.6"
},
"scripts": {
"bench": "node benchmark/index.js",
"test": "mocha --reporter spec --bail --check-leaks test/",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/"
},
"gitHead": "917fa69ae1a4c3e2962d89461b6945538b763b28",
"bugs": {
"url": "https://github.com/jshttp/proxy-addr/issues"
},
"homepage": "https://github.com/jshttp/proxy-addr",
"_id": "proxy-addr@1.0.7",
"_shasum": "6e2655aa9c56b014f09734a7e6d558cc77751939",
"_from": "proxy-addr@>=1.0.7 <1.1.0",
"_npmVersion": "1.4.28",
"_npmUser": {
"name": "dougwilson",
"email": "doug@somethingdoug.com"
},
"maintainers": [
{
"name": "dougwilson",
"email": "doug@somethingdoug.com"
},
{
"name": "jongleberry",
"email": "jonathanrichardong@gmail.com"
},
{
"name": "shtylman",
"email": "shtylman@gmail.com"
},
{
"name": "tjholowaychuk",
"email": "tj@vision-media.ca"
},
{
"name": "mscdex",
"email": "mscdex@mscdex.net"
},
{
"name": "fishrock123",
"email": "fishrock123@rocketmail.com"
}
],
"dist": {
"shasum": "6e2655aa9c56b014f09734a7e6d558cc77751939",
"tarball": "http://registry.npmjs.org/proxy-addr/-/proxy-addr-1.0.7.tgz"
},
"directories": {},
"_resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-1.0.7.tgz",
"readme": "ERROR: No README data found!"
}

proxy-addr

NPM Version NPM Downloads Node.js Version Build Status Test Coverage

Determine address of proxied request

Install

$ npm install proxy-addr

API

var proxyaddr = require('proxy-addr')

proxyaddr(req, trust)

Return the address of the request, using the given trust parameter.

The trust argument is a function that returns true if you trust the address, false if you don't. The closest untrusted address is returned.

proxyaddr(req, function(addr){ return addr === '127.0.0.1' })
proxyaddr(req, function(addr, i){ return i < 1 })

The trust arugment may also be a single IP address string or an array of trusted addresses, as plain IP addresses, CIDR-formatted strings, or IP/netmask strings.

proxyaddr(req, '127.0.0.1')
proxyaddr(req, ['127.0.0.0/8', '10.0.0.0/8'])
proxyaddr(req, ['127.0.0.0/255.0.0.0', '192.168.0.0/255.255.0.0'])

This module also supports IPv6. Your IPv6 addresses will be normalized automatically (i.e. fe80::00ed:1 equals fe80:0:0:0:0:0:ed:1).

proxyaddr(req, '::1')
proxyaddr(req, ['::1/128', 'fe80::/10'])
proxyaddr(req, ['fe80::/ffc0::'])

This module will automatically work with IPv4-mapped IPv6 addresses as well to support node.js in IPv6-only mode. This means that you do not have to specify both ::ffff:a00:1 and 10.0.0.1.

As a convenience, this module also takes certain pre-defined names in addition to IP addresses, which expand into IP addresses:

proxyaddr(req, 'loopback')
proxyaddr(req, ['loopback', 'fc00:ac:1ab5:fff::1/64'])
  • loopback: IPv4 and IPv6 loopback addresses (like ::1 and 127.0.0.1).
  • linklocal: IPv4 and IPv6 link-local addresses (like fe80::1:1:1:1 and 169.254.0.1).
  • uniquelocal: IPv4 private addresses and IPv6 unique-local addresses (like fc00:ac:1ab5:fff::1 and 192.168.0.1).

When trust is specified as a function, it will be called for each address to determine if it is a trusted address. The function is given two arguments: addr and i, where addr is a string of the address to check and i is a number that represents the distance from the socket address.

proxyaddr.all(req, [trust])

Return all the addresses of the request, optionally stopping at the first untrusted. This array is ordered from closest to furthest (i.e. arr[0] === req.connection.remoteAddress).

proxyaddr.all(req)

The optional trust argument takes the same arguments as trust does in proxyaddr(req, trust).

proxyaddr.all(req, 'loopback')

proxyaddr.compile(val)

Compiles argument val into a trust function. This function takes the same arguments as trust does in proxyaddr(req, trust) and returns a function suitable for proxyaddr(req, trust).

var trust = proxyaddr.compile('localhost')
var addr  = proxyaddr(req, trust)

This function is meant to be optimized for use against every request. It is recommend to compile a trust function up-front for the trusted configuration and pass that to proxyaddr(req, trust) for each request.

Testing

$ npm test

Benchmarks

$ npm run-script bench

License

MIT

{
"node": true,
"curly": true,
"latedef": true,
"quotmark": true,
"undef": true,
"unused": true,
"trailing": true
}
.idea
*.iml
npm-debug.log
dump.rdb
node_modules
results.tap
results.xml
npm-shrinkwrap.json
config.json
.DS_Store
*/.DS_Store
*/*/.DS_Store
._*
*/._*
*/*/._*
coverage.*
lib-cov
complexity.md
  • #59 make sure array indexes are >= 0, closes #57
  • #58 make qs usable for browser loader
  • #55 allow merging a string into an object
  • #52 Return "undefined" and "false" instead of throwing "TypeError".
  • #50 add option to omit array indices, closes #46
  • #39 Is there an alternative to Buffer.isBuffer?
  • #49 refactor utils.merge, fixes #45
  • #41 avoid browserifying Buffer, for #39
  • #38 how to handle object keys beginning with a number
  • #37 parser discards first empty value in array
  • #36 Update to lab 4.x
  • #33 Error when plain object in a value
  • #34 use Object.prototype.hasOwnProperty.call instead of obj.hasOwnProperty
  • #24 Changelog? Semver?
  • #32 account for circular references properly, closes #31
  • #31 qs.parse stackoverflow on circular objects
  • #26 Don't use Buffer global if it's not present
  • #30 Bug when merging non-object values into arrays
  • #29 Don't call Utils.clone at the top of Utils.merge
  • #23 Ability to not limit parameters?
  • #22 Enable using a RegExp as delimiter
  • #18 Why is there arrayLimit?
  • #20 Configurable parametersLimit
  • #21 make all limits optional, for #18, for #20
  • #19 Don't overwrite null values
  • #16 ignore non-string delimiters
  • #15 Close code block
  • #12 Add optional delim argument
  • #13 fix #11: flattened keys in array are now correctly parsed
  • #7 Empty values of a POST array disappear after being submitted
  • #9 Should not omit equals signs (=) when value is null
  • #6 Minor grammar fix in README
  • #5 array holes incorrectly copied into object on large index
// Load modules
var Stringify = require('./stringify');
var Parse = require('./parse');
// Declare internals
var internals = {};
module.exports = {
stringify: Stringify,
parse: Parse
};
// Load modules
var Utils = require('./utils');
// Declare internals
var internals = {
delimiter: '&',
depth: 5,
arrayLimit: 20,
parameterLimit: 1000
};
internals.parseValues = function (str, options) {
var obj = {};
var parts = str.split(options.delimiter, options.parameterLimit === Infinity ? undefined : options.parameterLimit);
for (var i = 0, il = parts.length; i < il; ++i) {
var part = parts[i];
var pos = part.indexOf(']=') === -1 ? part.indexOf('=') : part.indexOf(']=') + 1;
if (pos === -1) {
obj[Utils.decode(part)] = '';
}
else {
var key = Utils.decode(part.slice(0, pos));
var val = Utils.decode(part.slice(pos + 1));
if (Object.prototype.hasOwnProperty(key)) {
continue;
}
if (!obj.hasOwnProperty(key)) {
obj[key] = val;
}
else {
obj[key] = [].concat(obj[key]).concat(val);
}
}
}
return obj;
};
internals.parseObject = function (chain, val, options) {
if (!chain.length) {
return val;
}
var root = chain.shift();
var obj = {};
if (root === '[]') {
obj = [];
obj = obj.concat(internals.parseObject(chain, val, options));
}
else {
var cleanRoot = root[0] === '[' && root[root.length - 1] === ']' ? root.slice(1, root.length - 1) : root;
var index = parseInt(cleanRoot, 10);
var indexString = '' + index;
if (!isNaN(index) &&
root !== cleanRoot &&
indexString === cleanRoot &&
index >= 0 &&
index <= options.arrayLimit) {
obj = [];
obj[index] = internals.parseObject(chain, val, options);
}
else {
obj[cleanRoot] = internals.parseObject(chain, val, options);
}
}
return obj;
};
internals.parseKeys = function (key, val, options) {
if (!key) {
return;
}
// The regex chunks
var parent = /^([^\[\]]*)/;
var child = /(\[[^\[\]]*\])/g;
// Get the parent
var segment = parent.exec(key);
// Don't allow them to overwrite object prototype properties
if (Object.prototype.hasOwnProperty(segment[1])) {
return;
}
// Stash the parent if it exists
var keys = [];
if (segment[1]) {
keys.push(segment[1]);
}
// Loop through children appending to the array until we hit depth
var i = 0;
while ((segment = child.exec(key)) !== null && i < options.depth) {
++i;
if (!Object.prototype.hasOwnProperty(segment[1].replace(/\[|\]/g, ''))) {
keys.push(segment[1]);
}
}
// If there's a remainder, just add whatever is left
if (segment) {
keys.push('[' + key.slice(segment.index) + ']');
}
return internals.parseObject(keys, val, options);
};
module.exports = function (str, options) {
if (str === '' ||
str === null ||
typeof str === 'undefined') {
return {};
}
options = options || {};
options.delimiter = typeof options.delimiter === 'string' || Utils.isRegExp(options.delimiter) ? options.delimiter : internals.delimiter;
options.depth = typeof options.depth === 'number' ? options.depth : internals.depth;
options.arrayLimit = typeof options.arrayLimit === 'number' ? options.arrayLimit : internals.arrayLimit;
options.parameterLimit = typeof options.parameterLimit === 'number' ? options.parameterLimit : internals.parameterLimit;
var tempObj = typeof str === 'string' ? internals.parseValues(str, options) : str;
var obj = {};
// Iterate over the keys and setup the new object
var keys = Object.keys(tempObj);
for (var i = 0, il = keys.length; i < il; ++i) {
var key = keys[i];
var newObj = internals.parseKeys(key, tempObj[key], options);
obj = Utils.merge(obj, newObj);
}
return Utils.compact(obj);
};
// Load modules
var Utils = require('./utils');
// Declare internals
var internals = {
delimiter: '&',
arrayPrefixGenerators: {
brackets: function (prefix, key) {
return prefix + '[]';
},
indices: function (prefix, key) {
return prefix + '[' + key + ']';
},
repeat: function (prefix, key) {
return prefix;
}
}
};
internals.stringify = function (obj, prefix, generateArrayPrefix) {
if (Utils.isBuffer(obj)) {
obj = obj.toString();
}
else if (obj instanceof Date) {
obj = obj.toISOString();
}
else if (obj === null) {
obj = '';
}
if (typeof obj === 'string' ||
typeof obj === 'number' ||
typeof obj === 'boolean') {
return [encodeURIComponent(prefix) + '=' + encodeURIComponent(obj)];
}
var values = [];
if (typeof obj === 'undefined') {
return values;
}
var objKeys = Object.keys(obj);
for (var i = 0, il = objKeys.length; i < il; ++i) {
var key = objKeys[i];
if (Array.isArray(obj)) {
values = values.concat(internals.stringify(obj[key], generateArrayPrefix(prefix, key), generateArrayPrefix));
}
else {
values = values.concat(internals.stringify(obj[key], prefix + '[' + key + ']', generateArrayPrefix));
}
}
return values;
};
module.exports = function (obj, options) {
options = options || {};
var delimiter = typeof options.delimiter === 'undefined' ? internals.delimiter : options.delimiter;
var keys = [];
if (typeof obj !== 'object' ||
obj === null) {
return '';
}
var arrayFormat;
if (options.arrayFormat in internals.arrayPrefixGenerators) {
arrayFormat = options.arrayFormat;
}
else if ('indices' in options) {
arrayFormat = options.indices ? 'indices' : 'repeat';
}
else {
arrayFormat = 'indices';
}
var generateArrayPrefix = internals.arrayPrefixGenerators[arrayFormat];
var objKeys = Object.keys(obj);
for (var i = 0, il = objKeys.length; i < il; ++i) {
var key = objKeys[i];
keys = keys.concat(internals.stringify(obj[key], key, generateArrayPrefix));
}
return keys.join(delimiter);
};
// Load modules
// Declare internals
var internals = {};
exports.arrayToObject = function (source) {
var obj = {};
for (var i = 0, il = source.length; i < il; ++i) {
if (typeof source[i] !== 'undefined') {
obj[i] = source[i];
}
}
return obj;
};
exports.merge = function (target, source) {
if (!source) {
return target;
}
if (typeof source !== 'object') {
if (Array.isArray(target)) {
target.push(source);
}
else {
target[source] = true;
}
return target;
}
if (typeof target !== 'object') {
target = [target].concat(source);
return target;
}
if (Array.isArray(target) &&
!Array.isArray(source)) {
target = exports.arrayToObject(target);
}
var keys = Object.keys(source);
for (var k = 0, kl = keys.length; k < kl; ++k) {
var key = keys[k];
var value = source[key];
if (!target[key]) {
target[key] = value;
}
else {
target[key] = exports.merge(target[key], value);
}
}
return target;
};
exports.decode = function (str) {
try {
return decodeURIComponent(str.replace(/\+/g, ' '));
} catch (e) {
return str;
}
};
exports.compact = function (obj, refs) {
if (typeof obj !== 'object' ||
obj === null) {
return obj;
}
refs = refs || [];
var lookup = refs.indexOf(obj);
if (lookup !== -1) {
return refs[lookup];
}
refs.push(obj);
if (Array.isArray(obj)) {
var compacted = [];
for (var i = 0, il = obj.length; i < il; ++i) {
if (typeof obj[i] !== 'undefined') {
compacted.push(obj[i]);
}
}
return compacted;
}
var keys = Object.keys(obj);
for (i = 0, il = keys.length; i < il; ++i) {
var key = keys[i];
obj[key] = exports.compact(obj[key], refs);
}
return obj;
};
exports.isRegExp = function (obj) {
return Object.prototype.toString.call(obj) === '[object RegExp]';
};
exports.isBuffer = function (obj) {
if (obj === null ||
typeof obj === 'undefined') {
return false;
}
return !!(obj.constructor &&
obj.constructor.isBuffer &&
obj.constructor.isBuffer(obj));
};
Copyright (c) 2014 Nathan LaFreniere and other contributors.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* The names of any contributors may not be used to endorse or promote
products derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* * *
The complete list of contributors can be found at: https://github.com/hapijs/qs/graphs/contributors
test:
@node node_modules/lab/bin/lab -a code -L
test-cov:
@node node_modules/lab/bin/lab -a code -t 100 -L
test-cov-html:
@node node_modules/lab/bin/lab -a code -L -r html -o coverage.html
.PHONY: test test-cov test-cov-html
{
"name": "qs",
"version": "2.4.1",
"description": "A querystring parser that supports nesting and arrays, with a depth limit",
"homepage": "https://github.com/hapijs/qs",
"main": "index.js",
"dependencies": {},
"devDependencies": {
"code": "1.x.x",
"lab": "5.x.x"
},
"scripts": {
"test": "make test-cov"
},
"repository": {
"type": "git",
"url": "https://github.com/hapijs/qs.git"
},
"keywords": [
"querystring",
"qs"
],
"licenses": [
{
"type": "BSD",
"url": "http://github.com/hapijs/qs/raw/master/LICENSE"
}
],
"gitHead": "58c6540418954867822c1af3e45fb4c26708b07e",
"bugs": {
"url": "https://github.com/hapijs/qs/issues"
},
"_id": "qs@2.4.1",
"_shasum": "68cbaea971013426a80c1404fad6b1a6b1175245",
"_from": "qs@2.4.1",
"_npmVersion": "2.6.1",
"_nodeVersion": "0.10.36",
"_npmUser": {
"name": "nlf",
"email": "quitlahok@gmail.com"
},
"maintainers": [
{
"name": "nlf",
"email": "quitlahok@gmail.com"
},
{
"name": "hueniverse",
"email": "eran@hueniverse.com"
}
],
"dist": {
"shasum": "68cbaea971013426a80c1404fad6b1a6b1175245",
"tarball": "http://registry.npmjs.org/qs/-/qs-2.4.1.tgz"
},
"directories": {},
"_resolved": "https://registry.npmjs.org/qs/-/qs-2.4.1.tgz",
"readme": "ERROR: No README data found!"
}

qs

A querystring parsing and stringifying library with some added security.

Build Status

Lead Maintainer: Nathan LaFreniere

The qs module was originally created and maintained by TJ Holowaychuk.

Usage

var Qs = require('qs');

var obj = Qs.parse('a=c');    // { a: 'c' }
var str = Qs.stringify(obj);  // 'a=c'

Parsing Objects

Qs.parse(string, [options]);

qs allows you to create nested objects within your query strings, by surrounding the name of sub-keys with square brackets []. For example, the string 'foo[bar]=baz' converts to:

{
  foo: {
    bar: 'baz'
  }
}

URI encoded strings work too:

Qs.parse('a%5Bb%5D=c');
// { a: { b: 'c' } }

You can also nest your objects, like 'foo[bar][baz]=foobarbaz':

{
  foo: {
    bar: {
      baz: 'foobarbaz'
    }
  }
}

By default, when nesting objects qs will only parse up to 5 children deep. This means if you attempt to parse a string like 'a[b][c][d][e][f][g][h][i]=j' your resulting object will be:

{
  a: {
    b: {
      c: {
        d: {
          e: {
            f: {
              '[g][h][i]': 'j'
            }
          }
        }
      }
    }
  }
}

This depth can be overridden by passing a depth option to Qs.parse(string, [options]):

Qs.parse('a[b][c][d][e][f][g][h][i]=j', { depth: 1 });
// { a: { b: { '[c][d][e][f][g][h][i]': 'j' } } }

The depth limit helps mitigate abuse when qs is used to parse user input, and it is recommended to keep it a reasonably small number.

For similar reasons, by default qs will only parse up to 1000 parameters. This can be overridden by passing a parameterLimit option:

Qs.parse('a=b&c=d', { parameterLimit: 1 });
// { a: 'b' }

An optional delimiter can also be passed:

Qs.parse('a=b;c=d', { delimiter: ';' });
// { a: 'b', c: 'd' }

Delimiters can be a regular expression too:

Qs.parse('a=b;c=d,e=f', { delimiter: /[;,]/ });
// { a: 'b', c: 'd', e: 'f' }

Parsing Arrays

qs can also parse arrays using a similar [] notation:

Qs.parse('a[]=b&a[]=c');
// { a: ['b', 'c'] }

You may specify an index as well:

Qs.parse('a[1]=c&a[0]=b');
// { a: ['b', 'c'] }

Note that the only difference between an index in an array and a key in an object is that the value between the brackets must be a number to create an array. When creating arrays with specific indices, qs will compact a sparse array to only the existing values preserving their order:

Qs.parse('a[1]=b&a[15]=c');
// { a: ['b', 'c'] }

Note that an empty string is also a value, and will be preserved:

Qs.parse('a[]=&a[]=b');
// { a: ['', 'b'] }
Qs.parse('a[0]=b&a[1]=&a[2]=c');
// { a: ['b', '', 'c'] }

qs will also limit specifying indices in an array to a maximum index of 20. Any array members with an index of greater than 20 will instead be converted to an object with the index as the key:

Qs.parse('a[100]=b');
// { a: { '100': 'b' } }

This limit can be overridden by passing an arrayLimit option:

Qs.parse('a[1]=b', { arrayLimit: 0 });
// { a: { '1': 'b' } }

To disable array parsing entirely, set arrayLimit to -1.

If you mix notations, qs will merge the two items into an object:

Qs.parse('a[0]=b&a[b]=c');
// { a: { '0': 'b', b: 'c' } }

You can also create arrays of objects:

Qs.parse('a[][b]=c');
// { a: [{ b: 'c' }] }

Stringifying

Qs.stringify(object, [options]);

When stringifying, qs always URI encodes output. Objects are stringified as you would expect:

Qs.stringify({ a: 'b' });
// 'a=b'
Qs.stringify({ a: { b: 'c' } });
// 'a%5Bb%5D=c'

Examples beyond this point will be shown as though the output is not URI encoded for clarity. Please note that the return values in these cases will be URI encoded during real usage.

When arrays are stringified, by default they are given explicit indices:

Qs.stringify({ a: ['b', 'c', 'd'] });
// 'a[0]=b&a[1]=c&a[2]=d'

You may override this by setting the indices option to false:

Qs.stringify({ a: ['b', 'c', 'd'] }, { indices: false });
// 'a=b&a=c&a=d'

You may use the arrayFormat option to specify the format of the output array

Qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'indices' })
// 'a[0]=b&a[1]=c'
Qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'brackets' })
// 'a[]=b&a[]=c'
Qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'repeat' })
// 'a=b&a=c'

Empty strings and null values will omit the value, but the equals sign (=) remains in place:

Qs.stringify({ a: '' });
// 'a='

Properties that are set to undefined will be omitted entirely:

Qs.stringify({ a: null, b: undefined });
// 'a='

The delimiter may be overridden with stringify as well:

Qs.stringify({ a: 'b', c: 'd' }, { delimiter: ';' });
// 'a=b;c=d'
/* eslint no-extend-native:0 */
// Load modules
var Code = require('code');
var Lab = require('lab');
var Qs = require('../');
// Declare internals
var internals = {};
// Test shortcuts
var lab = exports.lab = Lab.script();
var expect = Code.expect;
var describe = lab.experiment;
var it = lab.test;
describe('parse()', function () {
it('parses a simple string', function (done) {
expect(Qs.parse('0=foo')).to.deep.equal({ '0': 'foo' });
expect(Qs.parse('foo=c++')).to.deep.equal({ foo: 'c ' });
expect(Qs.parse('a[>=]=23')).to.deep.equal({ a: { '>=': '23' } });
expect(Qs.parse('a[<=>]==23')).to.deep.equal({ a: { '<=>': '=23' } });
expect(Qs.parse('a[==]=23')).to.deep.equal({ a: { '==': '23' } });
expect(Qs.parse('foo')).to.deep.equal({ foo: '' });
expect(Qs.parse('foo=bar')).to.deep.equal({ foo: 'bar' });
expect(Qs.parse(' foo = bar = baz ')).to.deep.equal({ ' foo ': ' bar = baz ' });
expect(Qs.parse('foo=bar=baz')).to.deep.equal({ foo: 'bar=baz' });
expect(Qs.parse('foo=bar&bar=baz')).to.deep.equal({ foo: 'bar', bar: 'baz' });
expect(Qs.parse('foo=bar&baz')).to.deep.equal({ foo: 'bar', baz: '' });
expect(Qs.parse('cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World')).to.deep.equal({
cht: 'p3',
chd: 't:60,40',
chs: '250x100',
chl: 'Hello|World'
});
done();
});
it('parses a single nested string', function (done) {
expect(Qs.parse('a[b]=c')).to.deep.equal({ a: { b: 'c' } });
done();
});
it('parses a double nested string', function (done) {
expect(Qs.parse('a[b][c]=d')).to.deep.equal({ a: { b: { c: 'd' } } });
done();
});
it('defaults to a depth of 5', function (done) {
expect(Qs.parse('a[b][c][d][e][f][g][h]=i')).to.deep.equal({ a: { b: { c: { d: { e: { f: { '[g][h]': 'i' } } } } } } });
done();
});
it('only parses one level when depth = 1', function (done) {
expect(Qs.parse('a[b][c]=d', { depth: 1 })).to.deep.equal({ a: { b: { '[c]': 'd' } } });
expect(Qs.parse('a[b][c][d]=e', { depth: 1 })).to.deep.equal({ a: { b: { '[c][d]': 'e' } } });
done();
});
it('parses a simple array', function (done) {
expect(Qs.parse('a=b&a=c')).to.deep.equal({ a: ['b', 'c'] });
done();
});
it('parses an explicit array', function (done) {
expect(Qs.parse('a[]=b')).to.deep.equal({ a: ['b'] });
expect(Qs.parse('a[]=b&a[]=c')).to.deep.equal({ a: ['b', 'c'] });
expect(Qs.parse('a[]=b&a[]=c&a[]=d')).to.deep.equal({ a: ['b', 'c', 'd'] });
done();
});
it('parses a mix of simple and explicit arrays', function (done) {
expect(Qs.parse('a=b&a[]=c')).to.deep.equal({ a: ['b', 'c'] });
expect(Qs.parse('a[]=b&a=c')).to.deep.equal({ a: ['b', 'c'] });
expect(Qs.parse('a[0]=b&a=c')).to.deep.equal({ a: ['b', 'c'] });
expect(Qs.parse('a=b&a[0]=c')).to.deep.equal({ a: ['b', 'c'] });
expect(Qs.parse('a[1]=b&a=c')).to.deep.equal({ a: ['b', 'c'] });
expect(Qs.parse('a=b&a[1]=c')).to.deep.equal({ a: ['b', 'c'] });
done();
});
it('parses a nested array', function (done) {
expect(Qs.parse('a[b][]=c&a[b][]=d')).to.deep.equal({ a: { b: ['c', 'd'] } });
expect(Qs.parse('a[>=]=25')).to.deep.equal({ a: { '>=': '25' } });
done();
});
it('allows to specify array indices', function (done) {
expect(Qs.parse('a[1]=c&a[0]=b&a[2]=d')).to.deep.equal({ a: ['b', 'c', 'd'] });
expect(Qs.parse('a[1]=c&a[0]=b')).to.deep.equal({ a: ['b', 'c'] });
expect(Qs.parse('a[1]=c')).to.deep.equal({ a: ['c'] });
done();
});
it('limits specific array indices to 20', function (done) {
expect(Qs.parse('a[20]=a')).to.deep.equal({ a: ['a'] });
expect(Qs.parse('a[21]=a')).to.deep.equal({ a: { '21': 'a' } });
done();
});
it('supports keys that begin with a number', function (done) {
expect(Qs.parse('a[12b]=c')).to.deep.equal({ a: { '12b': 'c' } });
done();
});
it('supports encoded = signs', function (done) {
expect(Qs.parse('he%3Dllo=th%3Dere')).to.deep.equal({ 'he=llo': 'th=ere' });
done();
});
it('is ok with url encoded strings', function (done) {
expect(Qs.parse('a[b%20c]=d')).to.deep.equal({ a: { 'b c': 'd' } });
expect(Qs.parse('a[b]=c%20d')).to.deep.equal({ a: { b: 'c d' } });
done();
});
it('allows brackets in the value', function (done) {
expect(Qs.parse('pets=["tobi"]')).to.deep.equal({ pets: '["tobi"]' });
expect(Qs.parse('operators=[">=", "<="]')).to.deep.equal({ operators: '[">=", "<="]' });
done();
});
it('allows empty values', function (done) {
expect(Qs.parse('')).to.deep.equal({});
expect(Qs.parse(null)).to.deep.equal({});
expect(Qs.parse(undefined)).to.deep.equal({});
done();
});
it('transforms arrays to objects', function (done) {
expect(Qs.parse('foo[0]=bar&foo[bad]=baz')).to.deep.equal({ foo: { '0': 'bar', bad: 'baz' } });
expect(Qs.parse('foo[bad]=baz&foo[0]=bar')).to.deep.equal({ foo: { bad: 'baz', '0': 'bar' } });
expect(Qs.parse('foo[bad]=baz&foo[]=bar')).to.deep.equal({ foo: { bad: 'baz', '0': 'bar' } });
expect(Qs.parse('foo[]=bar&foo[bad]=baz')).to.deep.equal({ foo: { '0': 'bar', bad: 'baz' } });
expect(Qs.parse('foo[bad]=baz&foo[]=bar&foo[]=foo')).to.deep.equal({ foo: { bad: 'baz', '0': 'bar', '1': 'foo' } });
expect(Qs.parse('foo[0][a]=a&foo[0][b]=b&foo[1][a]=aa&foo[1][b]=bb')).to.deep.equal({foo: [ {a: 'a', b: 'b'}, {a: 'aa', b: 'bb'} ]});
done();
});
it('can add keys to objects', function (done) {
expect(Qs.parse('a[b]=c&a=d')).to.deep.equal({ a: { b: 'c', d: true } });
done();
});
it('correctly prunes undefined values when converting an array to an object', function (done) {
expect(Qs.parse('a[2]=b&a[99999999]=c')).to.deep.equal({ a: { '2': 'b', '99999999': 'c' } });
done();
});
it('supports malformed uri characters', function (done) {
expect(Qs.parse('{%:%}')).to.deep.equal({ '{%:%}': '' });
expect(Qs.parse('foo=%:%}')).to.deep.equal({ foo: '%:%}' });
done();
});
it('doesn\'t produce empty keys', function (done) {
expect(Qs.parse('_r=1&')).to.deep.equal({ '_r': '1' });
done();
});
it('cannot override prototypes', function (done) {
var obj = Qs.parse('hasOwnProperty=bad&toString=bad&bad[toString]=bad&constructor=bad');
expect(typeof obj.toString).to.equal('function');
expect(typeof obj.bad.toString).to.equal('function');
expect(typeof obj.constructor).to.equal('function');
done();
});
it('cannot access Object prototype', function (done) {
Qs.parse('constructor[prototype][bad]=bad');
Qs.parse('bad[constructor][prototype][bad]=bad');
expect(typeof Object.prototype.bad).to.equal('undefined');
done();
});
it('parses arrays of objects', function (done) {
expect(Qs.parse('a[][b]=c')).to.deep.equal({ a: [{ b: 'c' }] });
expect(Qs.parse('a[0][b]=c')).to.deep.equal({ a: [{ b: 'c' }] });
done();
});
it('allows for empty strings in arrays', function (done) {
expect(Qs.parse('a[]=b&a[]=&a[]=c')).to.deep.equal({ a: ['b', '', 'c'] });
expect(Qs.parse('a[0]=b&a[1]=&a[2]=c&a[19]=')).to.deep.equal({ a: ['b', '', 'c', ''] });
expect(Qs.parse('a[]=&a[]=b&a[]=c')).to.deep.equal({ a: ['', 'b', 'c'] });
done();
});
it('compacts sparse arrays', function (done) {
expect(Qs.parse('a[10]=1&a[2]=2')).to.deep.equal({ a: ['2', '1'] });
done();
});
it('parses semi-parsed strings', function (done) {
expect(Qs.parse({ 'a[b]': 'c' })).to.deep.equal({ a: { b: 'c' } });
expect(Qs.parse({ 'a[b]': 'c', 'a[d]': 'e' })).to.deep.equal({ a: { b: 'c', d: 'e' } });
done();
});
it('parses buffers correctly', function (done) {
var b = new Buffer('test');
expect(Qs.parse({ a: b })).to.deep.equal({ a: b });
done();
});
it('continues parsing when no parent is found', function (done) {
expect(Qs.parse('[]&a=b')).to.deep.equal({ '0': '', a: 'b' });
expect(Qs.parse('[foo]=bar')).to.deep.equal({ foo: 'bar' });
done();
});
it('does not error when parsing a very long array', function (done) {
var str = 'a[]=a';
while (Buffer.byteLength(str) < 128 * 1024) {
str += '&' + str;
}
expect(function () {
Qs.parse(str);
}).to.not.throw();
done();
});
it('should not throw when a native prototype has an enumerable property', { parallel: false }, function (done) {
Object.prototype.crash = '';
Array.prototype.crash = '';
expect(Qs.parse.bind(null, 'a=b')).to.not.throw();
expect(Qs.parse('a=b')).to.deep.equal({ a: 'b' });
expect(Qs.parse.bind(null, 'a[][b]=c')).to.not.throw();
expect(Qs.parse('a[][b]=c')).to.deep.equal({ a: [{ b: 'c' }] });
delete Object.prototype.crash;
delete Array.prototype.crash;
done();
});
it('parses a string with an alternative string delimiter', function (done) {
expect(Qs.parse('a=b;c=d', { delimiter: ';' })).to.deep.equal({ a: 'b', c: 'd' });
done();
});
it('parses a string with an alternative RegExp delimiter', function (done) {
expect(Qs.parse('a=b; c=d', { delimiter: /[;,] */ })).to.deep.equal({ a: 'b', c: 'd' });
done();
});
it('does not use non-splittable objects as delimiters', function (done) {
expect(Qs.parse('a=b&c=d', { delimiter: true })).to.deep.equal({ a: 'b', c: 'd' });
done();
});
it('allows overriding parameter limit', function (done) {
expect(Qs.parse('a=b&c=d', { parameterLimit: 1 })).to.deep.equal({ a: 'b' });
done();
});
it('allows setting the parameter limit to Infinity', function (done) {
expect(Qs.parse('a=b&c=d', { parameterLimit: Infinity })).to.deep.equal({ a: 'b', c: 'd' });
done();
});
it('allows overriding array limit', function (done) {
expect(Qs.parse('a[0]=b', { arrayLimit: -1 })).to.deep.equal({ a: { '0': 'b' } });
expect(Qs.parse('a[-1]=b', { arrayLimit: -1 })).to.deep.equal({ a: { '-1': 'b' } });
expect(Qs.parse('a[0]=b&a[1]=c', { arrayLimit: 0 })).to.deep.equal({ a: { '0': 'b', '1': 'c' } });
done();
});
it('parses an object', function (done) {
var input = {
'user[name]': {'pop[bob]': 3},
'user[email]': null
};
var expected = {
'user': {
'name': {'pop[bob]': 3},
'email': null
}
};
var result = Qs.parse(input);
expect(result).to.deep.equal(expected);
done();
});
it('parses an object and not child values', function (done) {
var input = {
'user[name]': {'pop[bob]': { 'test': 3 }},
'user[email]': null
};
var expected = {
'user': {
'name': {'pop[bob]': { 'test': 3 }},
'email': null
}
};
var result = Qs.parse(input);
expect(result).to.deep.equal(expected);
done();
});
it('does not blow up when Buffer global is missing', function (done) {
var tempBuffer = global.Buffer;
delete global.Buffer;
var result = Qs.parse('a=b&c=d');
global.Buffer = tempBuffer;
expect(result).to.deep.equal({ a: 'b', c: 'd' });
done();
});
it('does not crash when using invalid dot notation', function (done) {
expect(Qs.parse('roomInfoList[0].childrenAges[0]=15&roomInfoList[0].numberOfAdults=2')).to.deep.equal({ roomInfoList: [['15', '2']] });
done();
});
it('does not crash when parsing circular references', function (done) {
var a = {};
a.b = a;
var parsed;
expect(function () {
parsed = Qs.parse({ 'foo[bar]': 'baz', 'foo[baz]': a });
}).to.not.throw();
expect(parsed).to.contain('foo');
expect(parsed.foo).to.contain('bar', 'baz');
expect(parsed.foo.bar).to.equal('baz');
expect(parsed.foo.baz).to.deep.equal(a);
done();
});
it('parses plain objects correctly', function (done) {
var a = Object.create(null);
a.b = 'c';
expect(Qs.parse(a)).to.deep.equal({ b: 'c' });
var result = Qs.parse({ a: a });
expect(result).to.contain('a');
expect(result.a).to.deep.equal(a);
done();
});
it('parses dates correctly', function (done) {
var now = new Date();
expect(Qs.parse({ a: now })).to.deep.equal({ a: now });
done();
});
it('parses regular expressions correctly', function (done) {
var re = /^test$/;
expect(Qs.parse({ a: re })).to.deep.equal({ a: re });
done();
});
});
/* eslint no-extend-native:0 */
// Load modules
var Code = require('code');
var Lab = require('lab');
var Qs = require('../');
// Declare internals
var internals = {};
// Test shortcuts
var lab = exports.lab = Lab.script();
var expect = Code.expect;
var describe = lab.experiment;
var it = lab.test;
describe('stringify()', function () {
it('stringifies a querystring object', function (done) {
expect(Qs.stringify({ a: 'b' })).to.equal('a=b');
expect(Qs.stringify({ a: 1 })).to.equal('a=1');
expect(Qs.stringify({ a: 1, b: 2 })).to.equal('a=1&b=2');
done();
});
it('stringifies a nested object', function (done) {
expect(Qs.stringify({ a: { b: 'c' } })).to.equal('a%5Bb%5D=c');
expect(Qs.stringify({ a: { b: { c: { d: 'e' } } } })).to.equal('a%5Bb%5D%5Bc%5D%5Bd%5D=e');
done();
});
it('stringifies an array value', function (done) {
expect(Qs.stringify({ a: ['b', 'c', 'd'] })).to.equal('a%5B0%5D=b&a%5B1%5D=c&a%5B2%5D=d');
done();
});
it('omits array indices when asked', function (done) {
expect(Qs.stringify({ a: ['b', 'c', 'd'] }, { indices: false })).to.equal('a=b&a=c&a=d');
done();
});
it('stringifies a nested array value', function (done) {
expect(Qs.stringify({ a: { b: ['c', 'd'] } })).to.equal('a%5Bb%5D%5B0%5D=c&a%5Bb%5D%5B1%5D=d');
done();
});
it('stringifies an object inside an array', function (done) {
expect(Qs.stringify({ a: [{ b: 'c' }] })).to.equal('a%5B0%5D%5Bb%5D=c');
expect(Qs.stringify({ a: [{ b: { c: [1] } }] })).to.equal('a%5B0%5D%5Bb%5D%5Bc%5D%5B0%5D=1');
done();
});
it('does not omit object keys when indices = false', function (done) {
expect(Qs.stringify({ a: [{ b: 'c' }] }, { indices: false })).to.equal('a%5Bb%5D=c');
done();
});
it('uses indices notation for arrays when indices=true', function (done) {
expect(Qs.stringify({ a: ['b', 'c'] }, { indices: true })).to.equal('a%5B0%5D=b&a%5B1%5D=c');
done();
});
it('uses indices notation for arrays when no arrayFormat is specified', function (done) {
expect(Qs.stringify({ a: ['b', 'c'] })).to.equal('a%5B0%5D=b&a%5B1%5D=c');
done();
});
it('uses indices notation for arrays when no arrayFormat=indices', function (done) {
expect(Qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'indices' })).to.equal('a%5B0%5D=b&a%5B1%5D=c');
done();
});
it('uses repeat notation for arrays when no arrayFormat=repeat', function (done) {
expect(Qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'repeat' })).to.equal('a=b&a=c');
done();
});
it('uses brackets notation for arrays when no arrayFormat=brackets', function (done) {
expect(Qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'brackets' })).to.equal('a%5B%5D=b&a%5B%5D=c');
done();
});
it('stringifies a complicated object', function (done) {
expect(Qs.stringify({ a: { b: 'c', d: 'e' } })).to.equal('a%5Bb%5D=c&a%5Bd%5D=e');
done();
});
it('stringifies an empty value', function (done) {
expect(Qs.stringify({ a: '' })).to.equal('a=');
expect(Qs.stringify({ a: '', b: '' })).to.equal('a=&b=');
expect(Qs.stringify({ a: null })).to.equal('a=');
expect(Qs.stringify({ a: { b: null } })).to.equal('a%5Bb%5D=');
done();
});
it('stringifies an empty object', function (done) {
var obj = Object.create(null);
obj.a = 'b';
expect(Qs.stringify(obj)).to.equal('a=b');
done();
});
it('returns an empty string for invalid input', function (done) {
expect(Qs.stringify(undefined)).to.equal('');
expect(Qs.stringify(false)).to.equal('');
expect(Qs.stringify(null)).to.equal('');
expect(Qs.stringify('')).to.equal('');
done();
});
it('stringifies an object with an empty object as a child', function (done) {
var obj = {
a: Object.create(null)
};
obj.a.b = 'c';
expect(Qs.stringify(obj)).to.equal('a%5Bb%5D=c');
done();
});
it('drops keys with a value of undefined', function (done) {
expect(Qs.stringify({ a: undefined })).to.equal('');
expect(Qs.stringify({ a: { b: undefined, c: null } })).to.equal('a%5Bc%5D=');
done();
});
it('url encodes values', function (done) {
expect(Qs.stringify({ a: 'b c' })).to.equal('a=b%20c');
done();
});
it('stringifies a date', function (done) {
var now = new Date();
var str = 'a=' + encodeURIComponent(now.toISOString());
expect(Qs.stringify({ a: now })).to.equal(str);
done();
});
it('stringifies the weird object from qs', function (done) {
expect(Qs.stringify({ 'my weird field': 'q1!2"\'w$5&7/z8)?' })).to.equal('my%20weird%20field=q1!2%22\'w%245%267%2Fz8)%3F');
done();
});
it('skips properties that are part of the object prototype', function (done) {
Object.prototype.crash = 'test';
expect(Qs.stringify({ a: 'b'})).to.equal('a=b');
expect(Qs.stringify({ a: { b: 'c' } })).to.equal('a%5Bb%5D=c');
delete Object.prototype.crash;
done();
});
it('stringifies boolean values', function (done) {
expect(Qs.stringify({ a: true })).to.equal('a=true');
expect(Qs.stringify({ a: { b: true } })).to.equal('a%5Bb%5D=true');
expect(Qs.stringify({ b: false })).to.equal('b=false');
expect(Qs.stringify({ b: { c: false } })).to.equal('b%5Bc%5D=false');
done();
});
it('stringifies buffer values', function (done) {
expect(Qs.stringify({ a: new Buffer('test') })).to.equal('a=test');
expect(Qs.stringify({ a: { b: new Buffer('test') } })).to.equal('a%5Bb%5D=test');
done();
});
it('stringifies an object using an alternative delimiter', function (done) {
expect(Qs.stringify({ a: 'b', c: 'd' }, { delimiter: ';' })).to.equal('a=b;c=d');
done();
});
it('doesn\'t blow up when Buffer global is missing', function (done) {
var tempBuffer = global.Buffer;
delete global.Buffer;
expect(Qs.stringify({ a: 'b', c: 'd' })).to.equal('a=b&c=d');
global.Buffer = tempBuffer;
done();
});
});

1.0.2 / 2014-09-08

  • Support Node.js 0.6

1.0.1 / 2014-09-07

  • Move repository to jshttp

1.0.0 / 2013-12-11

  • Add repository to package.json
  • Add MIT license

0.0.4 / 2012-06-17

  • Change ret -1 for unsatisfiable and -2 when invalid

0.0.3 / 2012-06-17

  • Fix last-byte-pos default to len - 1

0.0.2 / 2012-06-14

  • Add .type

0.0.1 / 2012-06-11

  • Initial release
/**
* Parse "Range" header `str` relative to the given file `size`.
*
* @param {Number} size
* @param {String} str
* @return {Array}
* @api public
*/
module.exports = function(size, str){
var valid = true;
var i = str.indexOf('=');
if (-1 == i) return -2;
var arr = str.slice(i + 1).split(',').map(function(range){
var range = range.split('-')
, start = parseInt(range[0], 10)
, end = parseInt(range[1], 10);
// -nnn
if (isNaN(start)) {
start = size - end;
end = size - 1;
// nnn-
} else if (isNaN(end)) {
end = size - 1;
}
// limit last-byte-pos to current length
if (end > size - 1) end = size - 1;
// invalid
if (isNaN(start)
|| isNaN(end)
|| start > end
|| start < 0) valid = false;
return {
start: start,
end: end
};
});
arr.type = str.slice(0, i);
return valid ? arr : -1;
};
(The MIT License)
Copyright (c) 2012-2014 TJ Holowaychuk <vision-media.ca>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
{
"name": "range-parser",
"author": {
"name": "TJ Holowaychuk",
"email": "tj@vision-media.ca",
"url": "http://tjholowaychuk.com"
},
"description": "Range header field string parser",
"version": "1.0.2",
"license": "MIT",
"keywords": [
"range",
"parser",
"http"
],
"repository": {
"type": "git",
"url": "https://github.com/jshttp/range-parser"
},
"devDependencies": {
"istanbul": "0",
"mocha": "1",
"should": "2"
},
"files": [
"HISTORY.md",
"LICENSE",
"index.js"
],
"engines": {
"node": ">= 0.6"
},
"scripts": {
"test": "mocha --reporter spec --require should",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --require should",
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter dot --require should"
},
"readme": "# range-parser\n\n[![NPM Version][npm-image]][npm-url]\n[![NPM Downloads][downloads-image]][downloads-url]\n[![Node.js Version][node-version-image]][node-version-url]\n[![Build Status][travis-image]][travis-url]\n[![Test Coverage][coveralls-image]][coveralls-url]\n\nRange header field parser.\n\n## Installation\n\n```\n$ npm install range-parser\n```\n\n## Examples\n\n```js\nassert(-1 == parse(200, 'bytes=500-20'));\nassert(-2 == parse(200, 'bytes=malformed'));\nparse(200, 'bytes=0-499').should.eql(arr('bytes', [{ start: 0, end: 199 }]));\nparse(1000, 'bytes=0-499').should.eql(arr('bytes', [{ start: 0, end: 499 }]));\nparse(1000, 'bytes=40-80').should.eql(arr('bytes', [{ start: 40, end: 80 }]));\nparse(1000, 'bytes=-500').should.eql(arr('bytes', [{ start: 500, end: 999 }]));\nparse(1000, 'bytes=-400').should.eql(arr('bytes', [{ start: 600, end: 999 }]));\nparse(1000, 'bytes=500-').should.eql(arr('bytes', [{ start: 500, end: 999 }]));\nparse(1000, 'bytes=400-').should.eql(arr('bytes', [{ start: 400, end: 999 }]));\nparse(1000, 'bytes=0-0').should.eql(arr('bytes', [{ start: 0, end: 0 }]));\nparse(1000, 'bytes=-1').should.eql(arr('bytes', [{ start: 999, end: 999 }]));\nparse(1000, 'items=0-5').should.eql(arr('items', [{ start: 0, end: 5 }]));\nparse(1000, 'bytes=40-80,-1').should.eql(arr('bytes', [{ start: 40, end: 80 }, { start: 999, end: 999 }]));\n```\n\n## License\n\n[MIT](LICENSE)\n\n[npm-image]: https://img.shields.io/npm/v/range-parser.svg?style=flat\n[npm-url]: https://npmjs.org/package/range-parser\n[node-version-image]: https://img.shields.io/badge/node.js-%3E%3D_0.6-brightgreen.svg?style=flat\n[node-version-url]: http://nodejs.org/download/\n[travis-image]: https://img.shields.io/travis/jshttp/range-parser.svg?style=flat\n[travis-url]: https://travis-ci.org/jshttp/range-parser\n[coveralls-image]: https://img.shields.io/coveralls/jshttp/range-parser.svg?style=flat\n[coveralls-url]: https://coveralls.io/r/jshttp/range-parser\n[downloads-image]: https://img.shields.io/npm/dm/range-parser.svg?style=flat\n[downloads-url]: https://npmjs.org/package/range-parser\n",
"readmeFilename": "README.md",
"bugs": {
"url": "https://github.com/jshttp/range-parser/issues"
},
"homepage": "https://github.com/jshttp/range-parser",
"_id": "range-parser@1.0.2",
"_shasum": "06a12a42e5131ba8e457cd892044867f2344e549",
"_resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.0.2.tgz",
"_from": "range-parser@>=1.0.2 <1.1.0"
}

range-parser

NPM Version NPM Downloads Node.js Version Build Status Test Coverage

Range header field parser.

Installation

$ npm install range-parser

Examples

assert(-1 == parse(200, 'bytes=500-20'));
assert(-2 == parse(200, 'bytes=malformed'));
parse(200, 'bytes=0-499').should.eql(arr('bytes', [{ start: 0, end: 199 }]));
parse(1000, 'bytes=0-499').should.eql(arr('bytes', [{ start: 0, end: 499 }]));
parse(1000, 'bytes=40-80').should.eql(arr('bytes', [{ start: 40, end: 80 }]));
parse(1000, 'bytes=-500').should.eql(arr('bytes', [{ start: 500, end: 999 }]));
parse(1000, 'bytes=-400').should.eql(arr('bytes', [{ start: 600, end: 999 }]));
parse(1000, 'bytes=500-').should.eql(arr('bytes', [{ start: 500, end: 999 }]));
parse(1000, 'bytes=400-').should.eql(arr('bytes', [{ start: 400, end: 999 }]));
parse(1000, 'bytes=0-0').should.eql(arr('bytes', [{ start: 0, end: 0 }]));
parse(1000, 'bytes=-1').should.eql(arr('bytes', [{ start: 999, end: 999 }]));
parse(1000, 'items=0-5').should.eql(arr('items', [{ start: 0, end: 5 }]));
parse(1000, 'bytes=40-80,-1').should.eql(arr('bytes', [{ start: 40, end: 80 }, { start: 999, end: 999 }]));

License

MIT

0.12.2 / 2015-03-13

  • Throw errors early for invalid extensions or index options
  • deps: debug@~2.1.3
    • Fix high intensity foreground color for bold
    • deps: ms@0.7.0

0.12.1 / 2015-02-17

  • Fix regression sending zero-length files

0.12.0 / 2015-02-16

  • Always read the stat size from the file
  • Fix mutating passed-in options
  • deps: mime@1.3.4

0.11.1 / 2015-01-20

  • Fix root path disclosure

0.11.0 / 2015-01-05

  • deps: debug@~2.1.1
  • deps: etag@~1.5.1
    • deps: crc@3.2.1
  • deps: ms@0.7.0
    • Add milliseconds
    • Add msecs
    • Add secs
    • Add mins
    • Add hrs
    • Add yrs
  • deps: on-finished@~2.2.0

0.10.1 / 2014-10-22

  • deps: on-finished@~2.1.1
    • Fix handling of pipelined requests

0.10.0 / 2014-10-15

  • deps: debug@~2.1.0
    • Implement DEBUG_FD env variable support
  • deps: depd@~1.0.0
  • deps: etag@~1.5.0
    • Improve string performance
    • Slightly improve speed for weak ETags over 1KB

0.9.3 / 2014-09-24

  • deps: etag@~1.4.0
    • Support "fake" stats objects

0.9.2 / 2014-09-15

  • deps: depd@0.4.5
  • deps: etag@~1.3.1
  • deps: range-parser@~1.0.2

0.9.1 / 2014-09-07

  • deps: fresh@0.2.4

0.9.0 / 2014-09-07

  • Add lastModified option
  • Use etag to generate ETag header
  • deps: debug@~2.0.0

0.8.5 / 2014-09-04

  • Fix malicious path detection for empty string path

0.8.4 / 2014-09-04

  • Fix a path traversal issue when using root

0.8.3 / 2014-08-16

  • deps: destroy@1.0.3
    • renamed from dethroy
  • deps: on-finished@2.1.0

0.8.2 / 2014-08-14

  • Work around fd leak in Node.js 0.10 for fs.ReadStream
  • deps: dethroy@1.0.2

0.8.1 / 2014-08-05

  • Fix extensions behavior when file already has extension

0.8.0 / 2014-08-05

  • Add extensions option

0.7.4 / 2014-08-04

  • Fix serving index files without root dir

0.7.3 / 2014-07-29

  • Fix incorrect 403 on Windows and Node.js 0.11

0.7.2 / 2014-07-27

  • deps: depd@0.4.4
    • Work-around v8 generating empty stack traces

0.7.1 / 2014-07-26

  • deps: depd@0.4.3
    • Fix exception when global Error.stackTraceLimit is too low

0.7.0 / 2014-07-20

  • Deprecate hidden option; use dotfiles option
  • Add dotfiles option
  • deps: debug@1.0.4
  • deps: depd@0.4.2
    • Add TRACE_DEPRECATION environment variable
    • Remove non-standard grey color from color output
    • Support --no-deprecation argument
    • Support --trace-deprecation argument

0.6.0 / 2014-07-11

  • Deprecate from option; use root option
  • Deprecate send.etag() -- use etag in options
  • Deprecate send.hidden() -- use hidden in options
  • Deprecate send.index() -- use index in options
  • Deprecate send.maxage() -- use maxAge in options
  • Deprecate send.root() -- use root in options
  • Cap maxAge value to 1 year
  • deps: debug@1.0.3
    • Add support for multiple wildcards in namespaces

0.5.0 / 2014-06-28

  • Accept string for maxAge (converted by ms)
  • Add headers event
  • Include link in default redirect response
  • Use EventEmitter.listenerCount to count listeners

0.4.3 / 2014-06-11

  • Do not throw un-catchable error on file open race condition
  • Use escape-html for HTML escaping
  • deps: debug@1.0.2
    • fix some debugging output colors on node.js 0.8
  • deps: finished@1.2.2
  • deps: fresh@0.2.2

0.4.2 / 2014-06-09

  • fix "event emitter leak" warnings
  • deps: debug@1.0.1
  • deps: finished@1.2.1

0.4.1 / 2014-06-02

  • Send max-age in Cache-Control in correct format

0.4.0 / 2014-05-27

  • Calculate ETag with md5 for reduced collisions
  • Fix wrong behavior when index file matches directory
  • Ignore stream errors after request ends
    • Goodbye EBADF, read
  • Skip directories in index file search
  • deps: debug@0.8.1

0.3.0 / 2014-04-24

  • Fix sending files with dots without root set
  • Coerce option types
  • Accept API options in options object
  • Set etags to "weak"
  • Include file path in etag
  • Make "Can't set headers after they are sent." catchable
  • Send full entity-body for multi range requests
  • Default directory access to 403 when index disabled
  • Support multiple index paths
  • Support "If-Range" header
  • Control whether to generate etags
  • deps: mime@1.2.11

0.2.0 / 2014-01-29

  • update range-parser and fresh

0.1.4 / 2013-08-11

  • update fresh

0.1.3 / 2013-07-08

  • Revert "Fix fd leak"

0.1.2 / 2013-07-03

  • Fix fd leak

0.1.0 / 2012-08-25

  • add options parameter to send() that is passed to fs.createReadStream() [kanongil]

0.0.4 / 2012-08-16

  • allow custom "Accept-Ranges" definition

0.0.3 / 2012-07-16

  • fix normalization of the root directory. Closes #3

0.0.2 / 2012-07-09

  • add passing of req explicitly for now (YUCK)

0.0.1 / 2010-01-03

  • Initial release
/*!
* send
* Copyright(c) 2012 TJ Holowaychuk
* Copyright(c) 2014-2015 Douglas Christopher Wilson
* MIT Licensed
*/
/**
* Module dependencies.
*/
var debug = require('debug')('send')
var deprecate = require('depd')('send')
var destroy = require('destroy')
var escapeHtml = require('escape-html')
, parseRange = require('range-parser')
, Stream = require('stream')
, mime = require('mime')
, fresh = require('fresh')
, path = require('path')
, http = require('http')
, fs = require('fs')
, normalize = path.normalize
, join = path.join
var etag = require('etag')
var EventEmitter = require('events').EventEmitter;
var ms = require('ms');
var onFinished = require('on-finished')
/**
* Variables.
*/
var extname = path.extname
var maxMaxAge = 60 * 60 * 24 * 365 * 1000; // 1 year
var resolve = path.resolve
var sep = path.sep
var toString = Object.prototype.toString
var upPathRegexp = /(?:^|[\\\/])\.\.(?:[\\\/]|$)/
/**
* Expose `send`.
*/
exports = module.exports = send;
/**
* Expose mime module.
*/
exports.mime = mime;
/**
* Shim EventEmitter.listenerCount for node.js < 0.10
*/
/* istanbul ignore next */
var listenerCount = EventEmitter.listenerCount
|| function(emitter, type){ return emitter.listeners(type).length; };
/**
* Return a `SendStream` for `req` and `path`.
*
* @param {Request} req
* @param {String} path
* @param {object} [options]
* @return {SendStream}
* @api public
*/
function send(req, path, options) {
return new SendStream(req, path, options);
}
/**
* Initialize a `SendStream` with the given `path`.
*
* @param {Request} req
* @param {String} path
* @param {object} [options]
* @api private
*/
function SendStream(req, path, options) {
var opts = options || {}
this.options = opts
this.path = path
this.req = req
this._etag = opts.etag !== undefined
? Boolean(opts.etag)
: true
this._dotfiles = opts.dotfiles !== undefined
? opts.dotfiles
: 'ignore'
if (['allow', 'deny', 'ignore'].indexOf(this._dotfiles) === -1) {
throw new TypeError('dotfiles option must be "allow", "deny", or "ignore"')
}
this._hidden = Boolean(opts.hidden)
if (opts.hidden !== undefined) {
deprecate('hidden: use dotfiles: \'' + (this._hidden ? 'allow' : 'ignore') + '\' instead')
}
// legacy support
if (opts.dotfiles === undefined) {
this._dotfiles = undefined
}
this._extensions = opts.extensions !== undefined
? normalizeList(opts.extensions, 'extensions option')
: []
this._index = opts.index !== undefined
? normalizeList(opts.index, 'index option')
: ['index.html']
this._lastModified = opts.lastModified !== undefined
? Boolean(opts.lastModified)
: true
this._maxage = opts.maxAge || opts.maxage
this._maxage = typeof this._maxage === 'string'
? ms(this._maxage)
: Number(this._maxage)
this._maxage = !isNaN(this._maxage)
? Math.min(Math.max(0, this._maxage), maxMaxAge)
: 0
this._root = opts.root
? resolve(opts.root)
: null
if (!this._root && opts.from) {
this.from(opts.from)
}
}
/**
* Inherits from `Stream.prototype`.
*/
SendStream.prototype.__proto__ = Stream.prototype;
/**
* Enable or disable etag generation.
*
* @param {Boolean} val
* @return {SendStream}
* @api public
*/
SendStream.prototype.etag = deprecate.function(function etag(val) {
val = Boolean(val);
debug('etag %s', val);
this._etag = val;
return this;
}, 'send.etag: pass etag as option');
/**
* Enable or disable "hidden" (dot) files.
*
* @param {Boolean} path
* @return {SendStream}
* @api public
*/
SendStream.prototype.hidden = deprecate.function(function hidden(val) {
val = Boolean(val);
debug('hidden %s', val);
this._hidden = val;
this._dotfiles = undefined
return this;
}, 'send.hidden: use dotfiles option');
/**
* Set index `paths`, set to a falsy
* value to disable index support.
*
* @param {String|Boolean|Array} paths
* @return {SendStream}
* @api public
*/
SendStream.prototype.index = deprecate.function(function index(paths) {
var index = !paths ? [] : normalizeList(paths, 'paths argument');
debug('index %o', paths);
this._index = index;
return this;
}, 'send.index: pass index as option');
/**
* Set root `path`.
*
* @param {String} path
* @return {SendStream}
* @api public
*/
SendStream.prototype.root = function(path){
path = String(path);
this._root = resolve(path)
return this;
};
SendStream.prototype.from = deprecate.function(SendStream.prototype.root,
'send.from: pass root as option');
SendStream.prototype.root = deprecate.function(SendStream.prototype.root,
'send.root: pass root as option');
/**
* Set max-age to `maxAge`.
*
* @param {Number} maxAge
* @return {SendStream}
* @api public
*/
SendStream.prototype.maxage = deprecate.function(function maxage(maxAge) {
maxAge = typeof maxAge === 'string'
? ms(maxAge)
: Number(maxAge);
if (isNaN(maxAge)) maxAge = 0;
if (Infinity == maxAge) maxAge = 60 * 60 * 24 * 365 * 1000;
debug('max-age %d', maxAge);
this._maxage = maxAge;
return this;
}, 'send.maxage: pass maxAge as option');
/**
* Emit error with `status`.
*
* @param {Number} status
* @api private
*/
SendStream.prototype.error = function(status, err){
var res = this.res;
var msg = http.STATUS_CODES[status];
err = err || new Error(msg);
err.status = status;
// emit if listeners instead of responding
if (listenerCount(this, 'error') !== 0) {
return this.emit('error', err);
}
// wipe all existing headers
res._headers = undefined;
res.statusCode = err.status;
res.end(msg);
};
/**
* Check if the pathname ends with "/".
*
* @return {Boolean}
* @api private
*/
SendStream.prototype.hasTrailingSlash = function(){
return '/' == this.path[this.path.length - 1];
};
/**
* Check if this is a conditional GET request.
*
* @return {Boolean}
* @api private
*/
SendStream.prototype.isConditionalGET = function(){
return this.req.headers['if-none-match']
|| this.req.headers['if-modified-since'];
};
/**
* Strip content-* header fields.
*
* @api private
*/
SendStream.prototype.removeContentHeaderFields = function(){
var res = this.res;
Object.keys(res._headers).forEach(function(field){
if (0 == field.indexOf('content')) {
res.removeHeader(field);
}
});
};
/**
* Respond with 304 not modified.
*
* @api private
*/
SendStream.prototype.notModified = function(){
var res = this.res;
debug('not modified');
this.removeContentHeaderFields();
res.statusCode = 304;
res.end();
};
/**
* Raise error that headers already sent.
*
* @api private
*/
SendStream.prototype.headersAlreadySent = function headersAlreadySent(){
var err = new Error('Can\'t set headers after they are sent.');
debug('headers already sent');
this.error(500, err);
};
/**
* Check if the request is cacheable, aka
* responded with 2xx or 304 (see RFC 2616 section 14.2{5,6}).
*
* @return {Boolean}
* @api private
*/
SendStream.prototype.isCachable = function(){
var res = this.res;
return (res.statusCode >= 200 && res.statusCode < 300) || 304 == res.statusCode;
};
/**
* Handle stat() error.
*
* @param {Error} err
* @api private
*/
SendStream.prototype.onStatError = function(err){
var notfound = ['ENOENT', 'ENAMETOOLONG', 'ENOTDIR'];
if (~notfound.indexOf(err.code)) return this.error(404, err);
this.error(500, err);
};
/**
* Check if the cache is fresh.
*
* @return {Boolean}
* @api private
*/
SendStream.prototype.isFresh = function(){
return fresh(this.req.headers, this.res._headers);
};
/**
* Check if the range is fresh.
*
* @return {Boolean}
* @api private
*/
SendStream.prototype.isRangeFresh = function isRangeFresh(){
var ifRange = this.req.headers['if-range'];
if (!ifRange) return true;
return ~ifRange.indexOf('"')
? ~ifRange.indexOf(this.res._headers['etag'])
: Date.parse(this.res._headers['last-modified']) <= Date.parse(ifRange);
};
/**
* Redirect to `path`.
*
* @param {String} path
* @api private
*/
SendStream.prototype.redirect = function(path){
if (listenerCount(this, 'directory') !== 0) {
return this.emit('directory');
}
if (this.hasTrailingSlash()) return this.error(403);
var res = this.res;
path += '/';
res.statusCode = 301;
res.setHeader('Content-Type', 'text/html; charset=utf-8');
res.setHeader('Location', path);
res.end('Redirecting to <a href="' + escapeHtml(path) + '">' + escapeHtml(path) + '</a>\n');
};
/**
* Pipe to `res.
*
* @param {Stream} res
* @return {Stream} res
* @api public
*/
SendStream.prototype.pipe = function(res){
var self = this
, args = arguments
, root = this._root;
// references
this.res = res;
// decode the path
var path = decode(this.path)
if (path === -1) return this.error(400)
// null byte(s)
if (~path.indexOf('\0')) return this.error(400);
var parts
if (root !== null) {
// malicious path
if (upPathRegexp.test(normalize('.' + sep + path))) {
debug('malicious path "%s"', path)
return this.error(403)
}
// join / normalize from optional root dir
path = normalize(join(root, path))
root = normalize(root + sep)
// explode path parts
parts = path.substr(root.length).split(sep)
} else {
// ".." is malicious without "root"
if (upPathRegexp.test(path)) {
debug('malicious path "%s"', path)
return this.error(403)
}
// explode path parts
parts = normalize(path).split(sep)
// resolve the path
path = resolve(path)
}
// dotfile handling
if (containsDotFile(parts)) {
var access = this._dotfiles
// legacy support
if (access === undefined) {
access = parts[parts.length - 1][0] === '.'
? (this._hidden ? 'allow' : 'ignore')
: 'allow'
}
debug('%s dotfile "%s"', access, path)
switch (access) {
case 'allow':
break
case 'deny':
return this.error(403)
case 'ignore':
default:
return this.error(404)
}
}
// index file support
if (this._index.length && this.path[this.path.length - 1] === '/') {
this.sendIndex(path);
return res;
}
this.sendFile(path);
return res;
};
/**
* Transfer `path`.
*
* @param {String} path
* @api public
*/
SendStream.prototype.send = function(path, stat){
var len = stat.size;
var options = this.options
var opts = {}
var res = this.res;
var req = this.req;
var ranges = req.headers.range;
var offset = options.start || 0;
if (res._header) {
// impossible to send now
return this.headersAlreadySent();
}
debug('pipe "%s"', path)
// set header fields
this.setHeader(path, stat);
// set content-type
this.type(path);
// conditional GET support
if (this.isConditionalGET()
&& this.isCachable()
&& this.isFresh()) {
return this.notModified();
}
// adjust len to start/end options
len = Math.max(0, len - offset);
if (options.end !== undefined) {
var bytes = options.end - offset + 1;
if (len > bytes) len = bytes;
}
// Range support
if (ranges) {
ranges = parseRange(len, ranges);
// If-Range support
if (!this.isRangeFresh()) {
debug('range stale');
ranges = -2;
}
// unsatisfiable
if (-1 == ranges) {
debug('range unsatisfiable');
res.setHeader('Content-Range', 'bytes */' + stat.size);
return this.error(416);
}
// valid (syntactically invalid/multiple ranges are treated as a regular response)
if (-2 != ranges && ranges.length === 1) {
debug('range %j', ranges);
// Content-Range
res.statusCode = 206;
res.setHeader('Content-Range', 'bytes '
+ ranges[0].start
+ '-'
+ ranges[0].end
+ '/'
+ len);
offset += ranges[0].start;
len = ranges[0].end - ranges[0].start + 1;
}
}
// clone options
for (var prop in options) {
opts[prop] = options[prop]
}
// set read options
opts.start = offset
opts.end = Math.max(offset, offset + len - 1)
// content-length
res.setHeader('Content-Length', len);
// HEAD support
if ('HEAD' == req.method) return res.end();
this.stream(path, opts)
};
/**
* Transfer file for `path`.
*
* @param {String} path
* @api private
*/
SendStream.prototype.sendFile = function sendFile(path) {
var i = 0
var self = this
debug('stat "%s"', path);
fs.stat(path, function onstat(err, stat) {
if (err && err.code === 'ENOENT'
&& !extname(path)
&& path[path.length - 1] !== sep) {
// not found, check extensions
return next(err)
}
if (err) return self.onStatError(err)
if (stat.isDirectory()) return self.redirect(self.path)
self.emit('file', path, stat)
self.send(path, stat)
})
function next(err) {
if (self._extensions.length <= i) {
return err
? self.onStatError(err)
: self.error(404)
}
var p = path + '.' + self._extensions[i++]
debug('stat "%s"', p)
fs.stat(p, function (err, stat) {
if (err) return next(err)
if (stat.isDirectory()) return next()
self.emit('file', p, stat)
self.send(p, stat)
})
}
}
/**
* Transfer index for `path`.
*
* @param {String} path
* @api private
*/
SendStream.prototype.sendIndex = function sendIndex(path){
var i = -1;
var self = this;
function next(err){
if (++i >= self._index.length) {
if (err) return self.onStatError(err);
return self.error(404);
}
var p = join(path, self._index[i]);
debug('stat "%s"', p);
fs.stat(p, function(err, stat){
if (err) return next(err);
if (stat.isDirectory()) return next();
self.emit('file', p, stat);
self.send(p, stat);
});
}
next();
};
/**
* Stream `path` to the response.
*
* @param {String} path
* @param {Object} options
* @api private
*/
SendStream.prototype.stream = function(path, options){
// TODO: this is all lame, refactor meeee
var finished = false;
var self = this;
var res = this.res;
var req = this.req;
// pipe
var stream = fs.createReadStream(path, options);
this.emit('stream', stream);
stream.pipe(res);
// response finished, done with the fd
onFinished(res, function onfinished(){
finished = true;
destroy(stream);
});
// error handling code-smell
stream.on('error', function onerror(err){
// request already finished
if (finished) return;
// clean up stream
finished = true;
destroy(stream);
// error
self.onStatError(err);
});
// end
stream.on('end', function onend(){
self.emit('end');
});
};
/**
* Set content-type based on `path`
* if it hasn't been explicitly set.
*
* @param {String} path
* @api private
*/
SendStream.prototype.type = function(path){
var res = this.res;
if (res.getHeader('Content-Type')) return;
var type = mime.lookup(path);
var charset = mime.charsets.lookup(type);
debug('content-type %s', type);
res.setHeader('Content-Type', type + (charset ? '; charset=' + charset : ''));
};
/**
* Set response header fields, most
* fields may be pre-defined.
*
* @param {String} path
* @param {Object} stat
* @api private
*/
SendStream.prototype.setHeader = function setHeader(path, stat){
var res = this.res;
this.emit('headers', res, path, stat);
if (!res.getHeader('Accept-Ranges')) res.setHeader('Accept-Ranges', 'bytes');
if (!res.getHeader('Date')) res.setHeader('Date', new Date().toUTCString());
if (!res.getHeader('Cache-Control')) res.setHeader('Cache-Control', 'public, max-age=' + Math.floor(this._maxage / 1000));
if (this._lastModified && !res.getHeader('Last-Modified')) {
var modified = stat.mtime.toUTCString()
debug('modified %s', modified)
res.setHeader('Last-Modified', modified)
}
if (this._etag && !res.getHeader('ETag')) {
var val = etag(stat)
debug('etag %s', val)
res.setHeader('ETag', val)
}
};
/**
* Determine if path parts contain a dotfile.
*
* @api private
*/
function containsDotFile(parts) {
for (var i = 0; i < parts.length; i++) {
if (parts[i][0] === '.') {
return true
}
}
return false
}
/**
* decodeURIComponent.
*
* Allows V8 to only deoptimize this fn instead of all
* of send().
*
* @param {String} path
* @api private
*/
function decode(path) {
try {
return decodeURIComponent(path)
} catch (err) {
return -1
}
}
/**
* Normalize the index option into an array.
*
* @param {boolean|string|array} val
* @param {string} name
* @private
*/
function normalizeList(val, name) {
var list = [].concat(val || [])
for (var i = 0; i < list.length; i++) {
if (typeof list[i] !== 'string') {
throw new TypeError(name + ' must be array of strings or false')
}
}
return list
}
(The MIT License)
Copyright (c) 2012 TJ Holowaychuk
Copyright (c) 2014-2015 Douglas Christopher Wilson
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#!/usr/bin/env node
var mime = require('./mime.js');
var file = process.argv[2];
var type = mime.lookup(file);
process.stdout.write(type + '\n');
var ReadStream = require('fs').ReadStream
var Stream = require('stream')
module.exports = function destroy(stream) {
if (stream instanceof ReadStream) {
return destroyReadStream(stream)
}
if (!(stream instanceof Stream)) {
return stream
}
if (typeof stream.destroy === 'function') {
stream.destroy()
}
return stream
}
function destroyReadStream(stream) {
stream.destroy()
if (typeof stream.close === 'function') {
// node.js core bug work-around
stream.on('open', onopenClose)
}
return stream
}
function onopenClose() {
if (typeof this.fd === 'number') {
// actually close down the fd
this.close()
}
}
{
"name": "destroy",
"description": "destroy a stream if possible",
"version": "1.0.3",
"author": {
"name": "Jonathan Ong",
"email": "me@jongleberry.com",
"url": "http://jongleberry.com"
},
"contributors": [
{
"name": "Douglas Christopher Wilson",
"email": "doug@somethingdoug.com"
}
],
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/stream-utils/destroy"
},
"devDependencies": {
"istanbul": "0",
"mocha": "1"
},
"scripts": {
"test": "mocha --reporter spec",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot",
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter dot"
},
"files": [
"index.js"
],
"keywords": [
"stream",
"streams",
"destroy",
"cleanup",
"leak",
"fd"
],
"gitHead": "50af95ece4a70202f9301bc3edc8f9fdbbad0f26",
"bugs": {
"url": "https://github.com/stream-utils/destroy/issues"
},
"homepage": "https://github.com/stream-utils/destroy",
"_id": "destroy@1.0.3",
"_shasum": "b433b4724e71fd8551d9885174851c5fc377e2c9",
"_from": "destroy@1.0.3",
"_npmVersion": "1.4.21",
"_npmUser": {
"name": "jongleberry",
"email": "jonathanrichardong@gmail.com"
},
"maintainers": [
{
"name": "jongleberry",
"email": "jonathanrichardong@gmail.com"
}
],
"dist": {
"shasum": "b433b4724e71fd8551d9885174851c5fc377e2c9",
"tarball": "http://registry.npmjs.org/destroy/-/destroy-1.0.3.tgz"
},
"directories": {},
"_resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.3.tgz",
"readme": "ERROR: No README data found!"
}

Destroy

NPM version Build status Test coverage Dependency Status License Downloads Gittip

Destroy a stream.

API

var destroy = require('destroy')

var fs = require('fs')
var stream = fs.createReadStream('package.json')
destroy(stream)
var db = require('mime-db');
var mapByType = {};
Object.keys(db).forEach(function(key) {
var extensions = db[key].extensions;
if (extensions) {
mapByType[key] = extensions;
}
});
console.log(JSON.stringify(mapByType));
/**
* Usage: node test.js
*/
var mime = require('../mime');
var assert = require('assert');
var path = require('path');
//
// Test mime lookups
//
assert.equal('text/plain', mime.lookup('text.txt')); // normal file
assert.equal('text/plain', mime.lookup('TEXT.TXT')); // uppercase
assert.equal('text/plain', mime.lookup('dir/text.txt')); // dir + file
assert.equal('text/plain', mime.lookup('.text.txt')); // hidden file
assert.equal('text/plain', mime.lookup('.txt')); // nameless
assert.equal('text/plain', mime.lookup('txt')); // extension-only
assert.equal('text/plain', mime.lookup('/txt')); // extension-less ()
assert.equal('text/plain', mime.lookup('\\txt')); // Windows, extension-less
assert.equal('application/octet-stream', mime.lookup('text.nope')); // unrecognized
assert.equal('fallback', mime.lookup('text.fallback', 'fallback')); // alternate default
//
// Test extensions
//
assert.equal('txt', mime.extension(mime.types.text));
assert.equal('html', mime.extension(mime.types.htm));
assert.equal('bin', mime.extension('application/octet-stream'));
assert.equal('bin', mime.extension('application/octet-stream '));
assert.equal('html', mime.extension(' text/html; charset=UTF-8'));
assert.equal('html', mime.extension('text/html; charset=UTF-8 '));
assert.equal('html', mime.extension('text/html; charset=UTF-8'));
assert.equal('html', mime.extension('text/html ; charset=UTF-8'));
assert.equal('html', mime.extension('text/html;charset=UTF-8'));
assert.equal('html', mime.extension('text/Html;charset=UTF-8'));
assert.equal(undefined, mime.extension('unrecognized'));
//
// Test node.types lookups
//
assert.equal('application/font-woff', mime.lookup('file.woff'));
assert.equal('application/octet-stream', mime.lookup('file.buffer'));
assert.equal('audio/mp4', mime.lookup('file.m4a'));
assert.equal('font/opentype', mime.lookup('file.otf'));
//
// Test charsets
//
assert.equal('UTF-8', mime.charsets.lookup('text/plain'));
assert.equal(undefined, mime.charsets.lookup(mime.types.js));
assert.equal('fallback', mime.charsets.lookup('application/octet-stream', 'fallback'));
console.log('\nAll tests passed');
#!/usr/bin/env node
var mime = require('./mime.js');
var file = process.argv[2];
var type = mime.lookup(file);
process.stdout.write(type + '\n');
Copyright (c) 2010 Benjamin Thomas, Robert Kieffer
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
var path = require('path');
var fs = require('fs');
function Mime() {
// Map of extension -> mime type
this.types = Object.create(null);
// Map of mime type -> extension
this.extensions = Object.create(null);
}
/**
* Define mimetype -> extension mappings. Each key is a mime-type that maps
* to an array of extensions associated with the type. The first extension is
* used as the default extension for the type.
*
* e.g. mime.define({'audio/ogg', ['oga', 'ogg', 'spx']});
*
* @param map (Object) type definitions
*/
Mime.prototype.define = function (map) {
for (var type in map) {
var exts = map[type];
for (var i = 0; i < exts.length; i++) {
if (process.env.DEBUG_MIME && this.types[exts]) {
console.warn(this._loading.replace(/.*\//, ''), 'changes "' + exts[i] + '" extension type from ' +
this.types[exts] + ' to ' + type);
}
this.types[exts[i]] = type;
}
// Default extension is the first one we encounter
if (!this.extensions[type]) {
this.extensions[type] = exts[0];
}
}
};
/**
* Load an Apache2-style ".types" file
*
* This may be called multiple times (it's expected). Where files declare
* overlapping types/extensions, the last file wins.
*
* @param file (String) path of file to load.
*/
Mime.prototype.load = function(file) {
this._loading = file;
// Read file and split into lines
var map = {},
content = fs.readFileSync(file, 'ascii'),
lines = content.split(/[\r\n]+/);
lines.forEach(function(line) {
// Clean up whitespace/comments, and split into fields
var fields = line.replace(/\s*#.*|^\s*|\s*$/g, '').split(/\s+/);
map[fields.shift()] = fields;
});
this.define(map);
this._loading = null;
};
/**
* Lookup a mime type based on extension
*/
Mime.prototype.lookup = function(path, fallback) {
var ext = path.replace(/.*[\.\/\\]/, '').toLowerCase();
return this.types[ext] || fallback || this.default_type;
};
/**
* Return file extension associated with a mime type
*/
Mime.prototype.extension = function(mimeType) {
var type = mimeType.match(/^\s*([^;\s]*)(?:;|\s|$)/)[1].toLowerCase();
return this.extensions[type];
};
// Default instance
var mime = new Mime();
// Define built-in types
mime.define(require('./types.json'));
// Default type
mime.default_type = mime.lookup('bin');
//
// Additional API specific to the default instance
//
mime.Mime = Mime;
/**
* Lookup a charset based on mime type.
*/
mime.charsets = {
lookup: function(mimeType, fallback) {
// Assume text types are utf8
return (/^text\//).test(mimeType) ? 'UTF-8' : fallback;
}
};
module.exports = mime;
{
"author": {
"name": "Robert Kieffer",
"email": "robert@broofa.com",
"url": "http://github.com/broofa"
},
"scripts": {
"prepublish": "node build/build.js > types.json",
"test": "node build/test.js"
},
"bin": {
"mime": "cli.js"
},
"contributors": [
{
"name": "Benjamin Thomas",
"email": "benjamin@benjaminthomas.org",
"url": "http://github.com/bentomas"
}
],
"description": "A comprehensive library for mime-type mapping",
"licenses": [
{
"type": "MIT",
"url": "https://raw.github.com/broofa/node-mime/master/LICENSE"
}
],
"dependencies": {},
"devDependencies": {
"mime-db": "^1.2.0"
},
"keywords": [
"util",
"mime"
],
"main": "mime.js",
"name": "mime",
"repository": {
"url": "https://github.com/broofa/node-mime",
"type": "git"
},
"version": "1.3.4",
"gitHead": "1628f6e0187095009dcef4805c3a49706f137974",
"bugs": {
"url": "https://github.com/broofa/node-mime/issues"
},
"homepage": "https://github.com/broofa/node-mime",
"_id": "mime@1.3.4",
"_shasum": "115f9e3b6b3daf2959983cb38f149a2d40eb5d53",
"_from": "mime@1.3.4",
"_npmVersion": "1.4.28",
"_npmUser": {
"name": "broofa",
"email": "robert@broofa.com"
},
"maintainers": [
{
"name": "broofa",
"email": "robert@broofa.com"
},
{
"name": "bentomas",
"email": "benjamin@benjaminthomas.org"
}
],
"dist": {
"shasum": "115f9e3b6b3daf2959983cb38f149a2d40eb5d53",
"tarball": "http://registry.npmjs.org/mime/-/mime-1.3.4.tgz"
},
"directories": {},
"_resolved": "https://registry.npmjs.org/mime/-/mime-1.3.4.tgz",
"readme": "ERROR: No README data found!"
}

mime

Comprehensive MIME type mapping API based on mime-db module.

Install

Install with npm:

npm install mime

Contributing / Testing

npm run test

Command Line

mime [path_string]

E.g.

> mime scripts/jquery.js
application/javascript

API - Queries

mime.lookup(path)

Get the mime type associated with a file, if no mime type is found application/octet-stream is returned. Performs a case-insensitive lookup using the extension in path (the substring after the last '/' or '.'). E.g.

var mime = require('mime');

mime.lookup('/path/to/file.txt');         // => 'text/plain'
mime.lookup('file.txt');                  // => 'text/plain'
mime.lookup('.TXT');                      // => 'text/plain'
mime.lookup('htm');                       // => 'text/html'

mime.default_type

Sets the mime type returned when mime.lookup fails to find the extension searched for. (Default is application/octet-stream.)

mime.extension(type)

Get the default extension for type

mime.extension('text/html');                 // => 'html'
mime.extension('application/octet-stream');  // => 'bin'

mime.charsets.lookup()

Map mime-type to charset

mime.charsets.lookup('text/plain');        // => 'UTF-8'

(The logic for charset lookups is pretty rudimentary. Feel free to suggest improvements.)

API - Defining Custom Types

Custom type mappings can be added on a per-project basis via the following APIs.

mime.define()

Add custom mime/extension mappings

mime.define({
    'text/x-some-format': ['x-sf', 'x-sft', 'x-sfml'],
    'application/x-my-type': ['x-mt', 'x-mtt'],
    // etc ...
});

mime.lookup('x-sft');                 // => 'text/x-some-format'

The first entry in the extensions array is returned by mime.extension(). E.g.

mime.extension('text/x-some-format'); // => 'x-sf'

mime.load(filepath)

Load mappings from an Apache ".types" format file

mime.load('./my_project.types');

The .types file format is simple - See the types dir for examples.

{"application/andrew-inset":["ez"],"application/applixware":["aw"],"application/atom+xml":["atom"],"application/atomcat+xml":["atomcat"],"application/atomsvc+xml":["atomsvc"],"application/ccxml+xml":["ccxml"],"application/cdmi-capability":["cdmia"],"application/cdmi-container":["cdmic"],"application/cdmi-domain":["cdmid"],"application/cdmi-object":["cdmio"],"application/cdmi-queue":["cdmiq"],"application/cu-seeme":["cu"],"application/dash+xml":["mdp"],"application/davmount+xml":["davmount"],"application/docbook+xml":["dbk"],"application/dssc+der":["dssc"],"application/dssc+xml":["xdssc"],"application/ecmascript":["ecma"],"application/emma+xml":["emma"],"application/epub+zip":["epub"],"application/exi":["exi"],"application/font-tdpfr":["pfr"],"application/font-woff":["woff"],"application/font-woff2":["woff2"],"application/gml+xml":["gml"],"application/gpx+xml":["gpx"],"application/gxf":["gxf"],"application/hyperstudio":["stk"],"application/inkml+xml":["ink","inkml"],"application/ipfix":["ipfix"],"application/java-archive":["jar"],"application/java-serialized-object":["ser"],"application/java-vm":["class"],"application/javascript":["js"],"application/json":["json","map"],"application/json5":["json5"],"application/jsonml+json":["jsonml"],"application/lost+xml":["lostxml"],"application/mac-binhex40":["hqx"],"application/mac-compactpro":["cpt"],"application/mads+xml":["mads"],"application/marc":["mrc"],"application/marcxml+xml":["mrcx"],"application/mathematica":["ma","nb","mb"],"application/mathml+xml":["mathml"],"application/mbox":["mbox"],"application/mediaservercontrol+xml":["mscml"],"application/metalink+xml":["metalink"],"application/metalink4+xml":["meta4"],"application/mets+xml":["mets"],"application/mods+xml":["mods"],"application/mp21":["m21","mp21"],"application/mp4":["mp4s","m4p"],"application/msword":["doc","dot"],"application/mxf":["mxf"],"application/octet-stream":["bin","dms","lrf","mar","so","dist","distz","pkg","bpk","dump","elc","deploy","buffer"],"application/oda":["oda"],"application/oebps-package+xml":["opf"],"application/ogg":["ogx"],"application/omdoc+xml":["omdoc"],"application/onenote":["onetoc","onetoc2","onetmp","onepkg"],"application/oxps":["oxps"],"application/patch-ops-error+xml":["xer"],"application/pdf":["pdf"],"application/pgp-encrypted":["pgp"],"application/pgp-signature":["asc","sig"],"application/pics-rules":["prf"],"application/pkcs10":["p10"],"application/pkcs7-mime":["p7m","p7c"],"application/pkcs7-signature":["p7s"],"application/pkcs8":["p8"],"application/pkix-attr-cert":["ac"],"application/pkix-cert":["cer"],"application/pkix-crl":["crl"],"application/pkix-pkipath":["pkipath"],"application/pkixcmp":["pki"],"application/pls+xml":["pls"],"application/postscript":["ai","eps","ps"],"application/prs.cww":["cww"],"application/pskc+xml":["pskcxml"],"application/rdf+xml":["rdf"],"application/reginfo+xml":["rif"],"application/relax-ng-compact-syntax":["rnc"],"application/resource-lists+xml":["rl"],"application/resource-lists-diff+xml":["rld"],"application/rls-services+xml":["rs"],"application/rpki-ghostbusters":["gbr"],"application/rpki-manifest":["mft"],"application/rpki-roa":["roa"],"application/rsd+xml":["rsd"],"application/rss+xml":["rss"],"application/rtf":["rtf"],"application/sbml+xml":["sbml"],"application/scvp-cv-request":["scq"],"application/scvp-cv-response":["scs"],"application/scvp-vp-request":["spq"],"application/scvp-vp-response":["spp"],"application/sdp":["sdp"],"application/set-payment-initiation":["setpay"],"application/set-registration-initiation":["setreg"],"application/shf+xml":["shf"],"application/smil+xml":["smi","smil"],"application/sparql-query":["rq"],"application/sparql-results+xml":["srx"],"application/srgs":["gram"],"application/srgs+xml":["grxml"],"application/sru+xml":["sru"],"application/ssdl+xml":["ssdl"],"application/ssml+xml":["ssml"],"application/tei+xml":["tei","teicorpus"],"application/thraud+xml":["tfi"],"application/timestamped-data":["tsd"],"application/vnd.3gpp.pic-bw-large":["plb"],"application/vnd.3gpp.pic-bw-small":["psb"],"application/vnd.3gpp.pic-bw-var":["pvb"],"application/vnd.3gpp2.tcap":["tcap"],"application/vnd.3m.post-it-notes":["pwn"],"application/vnd.accpac.simply.aso":["aso"],"application/vnd.accpac.simply.imp":["imp"],"application/vnd.acucobol":["acu"],"application/vnd.acucorp":["atc","acutc"],"application/vnd.adobe.air-application-installer-package+zip":["air"],"application/vnd.adobe.formscentral.fcdt":["fcdt"],"application/vnd.adobe.fxp":["fxp","fxpl"],"application/vnd.adobe.xdp+xml":["xdp"],"application/vnd.adobe.xfdf":["xfdf"],"application/vnd.ahead.space":["ahead"],"application/vnd.airzip.filesecure.azf":["azf"],"application/vnd.airzip.filesecure.azs":["azs"],"application/vnd.amazon.ebook":["azw"],"application/vnd.americandynamics.acc":["acc"],"application/vnd.amiga.ami":["ami"],"application/vnd.android.package-archive":["apk"],"application/vnd.anser-web-certificate-issue-initiation":["cii"],"application/vnd.anser-web-funds-transfer-initiation":["fti"],"application/vnd.antix.game-component":["atx"],"application/vnd.apple.installer+xml":["mpkg"],"application/vnd.apple.mpegurl":["m3u8"],"application/vnd.aristanetworks.swi":["swi"],"application/vnd.astraea-software.iota":["iota"],"application/vnd.audiograph":["aep"],"application/vnd.blueice.multipass":["mpm"],"application/vnd.bmi":["bmi"],"application/vnd.businessobjects":["rep"],"application/vnd.chemdraw+xml":["cdxml"],"application/vnd.chipnuts.karaoke-mmd":["mmd"],"application/vnd.cinderella":["cdy"],"application/vnd.claymore":["cla"],"application/vnd.cloanto.rp9":["rp9"],"application/vnd.clonk.c4group":["c4g","c4d","c4f","c4p","c4u"],"application/vnd.cluetrust.cartomobile-config":["c11amc"],"application/vnd.cluetrust.cartomobile-config-pkg":["c11amz"],"application/vnd.commonspace":["csp"],"application/vnd.contact.cmsg":["cdbcmsg"],"application/vnd.cosmocaller":["cmc"],"application/vnd.crick.clicker":["clkx"],"application/vnd.crick.clicker.keyboard":["clkk"],"application/vnd.crick.clicker.palette":["clkp"],"application/vnd.crick.clicker.template":["clkt"],"application/vnd.crick.clicker.wordbank":["clkw"],"application/vnd.criticaltools.wbs+xml":["wbs"],"application/vnd.ctc-posml":["pml"],"application/vnd.cups-ppd":["ppd"],"application/vnd.curl.car":["car"],"application/vnd.curl.pcurl":["pcurl"],"application/vnd.dart":["dart"],"application/vnd.data-vision.rdz":["rdz"],"application/vnd.dece.data":["uvf","uvvf","uvd","uvvd"],"application/vnd.dece.ttml+xml":["uvt","uvvt"],"application/vnd.dece.unspecified":["uvx","uvvx"],"application/vnd.dece.zip":["uvz","uvvz"],"application/vnd.denovo.fcselayout-link":["fe_launch"],"application/vnd.dna":["dna"],"application/vnd.dolby.mlp":["mlp"],"application/vnd.dpgraph":["dpg"],"application/vnd.dreamfactory":["dfac"],"application/vnd.ds-keypoint":["kpxx"],"application/vnd.dvb.ait":["ait"],"application/vnd.dvb.service":["svc"],"application/vnd.dynageo":["geo"],"application/vnd.ecowin.chart":["mag"],"application/vnd.enliven":["nml"],"application/vnd.epson.esf":["esf"],"application/vnd.epson.msf":["msf"],"application/vnd.epson.quickanime":["qam"],"application/vnd.epson.salt":["slt"],"application/vnd.epson.ssf":["ssf"],"application/vnd.eszigno3+xml":["es3","et3"],"application/vnd.ezpix-album":["ez2"],"application/vnd.ezpix-package":["ez3"],"application/vnd.fdf":["fdf"],"application/vnd.fdsn.mseed":["mseed"],"application/vnd.fdsn.seed":["seed","dataless"],"application/vnd.flographit":["gph"],"application/vnd.fluxtime.clip":["ftc"],"application/vnd.framemaker":["fm","frame","maker","book"],"application/vnd.frogans.fnc":["fnc"],"application/vnd.frogans.ltf":["ltf"],"application/vnd.fsc.weblaunch":["fsc"],"application/vnd.fujitsu.oasys":["oas"],"application/vnd.fujitsu.oasys2":["oa2"],"application/vnd.fujitsu.oasys3":["oa3"],"application/vnd.fujitsu.oasysgp":["fg5"],"application/vnd.fujitsu.oasysprs":["bh2"],"application/vnd.fujixerox.ddd":["ddd"],"application/vnd.fujixerox.docuworks":["xdw"],"application/vnd.fujixerox.docuworks.binder":["xbd"],"application/vnd.fuzzysheet":["fzs"],"application/vnd.genomatix.tuxedo":["txd"],"application/vnd.geogebra.file":["ggb"],"application/vnd.geogebra.tool":["ggt"],"application/vnd.geometry-explorer":["gex","gre"],"application/vnd.geonext":["gxt"],"application/vnd.geoplan":["g2w"],"application/vnd.geospace":["g3w"],"application/vnd.gmx":["gmx"],"application/vnd.google-earth.kml+xml":["kml"],"application/vnd.google-earth.kmz":["kmz"],"application/vnd.grafeq":["gqf","gqs"],"application/vnd.groove-account":["gac"],"application/vnd.groove-help":["ghf"],"application/vnd.groove-identity-message":["gim"],"application/vnd.groove-injector":["grv"],"application/vnd.groove-tool-message":["gtm"],"application/vnd.groove-tool-template":["tpl"],"application/vnd.groove-vcard":["vcg"],"application/vnd.hal+xml":["hal"],"application/vnd.handheld-entertainment+xml":["zmm"],"application/vnd.hbci":["hbci"],"application/vnd.hhe.lesson-player":["les"],"application/vnd.hp-hpgl":["hpgl"],"application/vnd.hp-hpid":["hpid"],"application/vnd.hp-hps":["hps"],"application/vnd.hp-jlyt":["jlt"],"application/vnd.hp-pcl":["pcl"],"application/vnd.hp-pclxl":["pclxl"],"application/vnd.ibm.minipay":["mpy"],"application/vnd.ibm.modcap":["afp","listafp","list3820"],"application/vnd.ibm.rights-management":["irm"],"application/vnd.ibm.secure-container":["sc"],"application/vnd.iccprofile":["icc","icm"],"application/vnd.igloader":["igl"],"application/vnd.immervision-ivp":["ivp"],"application/vnd.immervision-ivu":["ivu"],"application/vnd.insors.igm":["igm"],"application/vnd.intercon.formnet":["xpw","xpx"],"application/vnd.intergeo":["i2g"],"application/vnd.intu.qbo":["qbo"],"application/vnd.intu.qfx":["qfx"],"application/vnd.ipunplugged.rcprofile":["rcprofile"],"application/vnd.irepository.package+xml":["irp"],"application/vnd.is-xpr":["xpr"],"application/vnd.isac.fcs":["fcs"],"application/vnd.jam":["jam"],"application/vnd.jcp.javame.midlet-rms":["rms"],"application/vnd.jisp":["jisp"],"application/vnd.joost.joda-archive":["joda"],"application/vnd.kahootz":["ktz","ktr"],"application/vnd.kde.karbon":["karbon"],"application/vnd.kde.kchart":["chrt"],"application/vnd.kde.kformula":["kfo"],"application/vnd.kde.kivio":["flw"],"application/vnd.kde.kontour":["kon"],"application/vnd.kde.kpresenter":["kpr","kpt"],"application/vnd.kde.kspread":["ksp"],"application/vnd.kde.kword":["kwd","kwt"],"application/vnd.kenameaapp":["htke"],"application/vnd.kidspiration":["kia"],"application/vnd.kinar":["kne","knp"],"application/vnd.koan":["skp","skd","skt","skm"],"application/vnd.kodak-descriptor":["sse"],"application/vnd.las.las+xml":["lasxml"],"application/vnd.llamagraphics.life-balance.desktop":["lbd"],"application/vnd.llamagraphics.life-balance.exchange+xml":["lbe"],"application/vnd.lotus-1-2-3":["123"],"application/vnd.lotus-approach":["apr"],"application/vnd.lotus-freelance":["pre"],"application/vnd.lotus-notes":["nsf"],"application/vnd.lotus-organizer":["org"],"application/vnd.lotus-screencam":["scm"],"application/vnd.lotus-wordpro":["lwp"],"application/vnd.macports.portpkg":["portpkg"],"application/vnd.mcd":["mcd"],"application/vnd.medcalcdata":["mc1"],"application/vnd.mediastation.cdkey":["cdkey"],"application/vnd.mfer":["mwf"],"application/vnd.mfmp":["mfm"],"application/vnd.micrografx.flo":["flo"],"application/vnd.micrografx.igx":["igx"],"application/vnd.mif":["mif"],"application/vnd.mobius.daf":["daf"],"application/vnd.mobius.dis":["dis"],"application/vnd.mobius.mbk":["mbk"],"application/vnd.mobius.mqy":["mqy"],"application/vnd.mobius.msl":["msl"],"application/vnd.mobius.plc":["plc"],"application/vnd.mobius.txf":["txf"],"application/vnd.mophun.application":["mpn"],"application/vnd.mophun.certificate":["mpc"],"application/vnd.mozilla.xul+xml":["xul"],"application/vnd.ms-artgalry":["cil"],"application/vnd.ms-cab-compressed":["cab"],"application/vnd.ms-excel":["xls","xlm","xla","xlc","xlt","xlw"],"application/vnd.ms-excel.addin.macroenabled.12":["xlam"],"application/vnd.ms-excel.sheet.binary.macroenabled.12":["xlsb"],"application/vnd.ms-excel.sheet.macroenabled.12":["xlsm"],"application/vnd.ms-excel.template.macroenabled.12":["xltm"],"application/vnd.ms-fontobject":["eot"],"application/vnd.ms-htmlhelp":["chm"],"application/vnd.ms-ims":["ims"],"application/vnd.ms-lrm":["lrm"],"application/vnd.ms-officetheme":["thmx"],"application/vnd.ms-pki.seccat":["cat"],"application/vnd.ms-pki.stl":["stl"],"application/vnd.ms-powerpoint":["ppt","pps","pot"],"application/vnd.ms-powerpoint.addin.macroenabled.12":["ppam"],"application/vnd.ms-powerpoint.presentation.macroenabled.12":["pptm"],"application/vnd.ms-powerpoint.slide.macroenabled.12":["sldm"],"application/vnd.ms-powerpoint.slideshow.macroenabled.12":["ppsm"],"application/vnd.ms-powerpoint.template.macroenabled.12":["potm"],"application/vnd.ms-project":["mpp","mpt"],"application/vnd.ms-word.document.macroenabled.12":["docm"],"application/vnd.ms-word.template.macroenabled.12":["dotm"],"application/vnd.ms-works":["wps","wks","wcm","wdb"],"application/vnd.ms-wpl":["wpl"],"application/vnd.ms-xpsdocument":["xps"],"application/vnd.mseq":["mseq"],"application/vnd.musician":["mus"],"application/vnd.muvee.style":["msty"],"application/vnd.mynfc":["taglet"],"application/vnd.neurolanguage.nlu":["nlu"],"application/vnd.nitf":["ntf","nitf"],"application/vnd.noblenet-directory":["nnd"],"application/vnd.noblenet-sealer":["nns"],"application/vnd.noblenet-web":["nnw"],"application/vnd.nokia.n-gage.data":["ngdat"],"application/vnd.nokia.radio-preset":["rpst"],"application/vnd.nokia.radio-presets":["rpss"],"application/vnd.novadigm.edm":["edm"],"application/vnd.novadigm.edx":["edx"],"application/vnd.novadigm.ext":["ext"],"application/vnd.oasis.opendocument.chart":["odc"],"application/vnd.oasis.opendocument.chart-template":["otc"],"application/vnd.oasis.opendocument.database":["odb"],"application/vnd.oasis.opendocument.formula":["odf"],"application/vnd.oasis.opendocument.formula-template":["odft"],"application/vnd.oasis.opendocument.graphics":["odg"],"application/vnd.oasis.opendocument.graphics-template":["otg"],"application/vnd.oasis.opendocument.image":["odi"],"application/vnd.oasis.opendocument.image-template":["oti"],"application/vnd.oasis.opendocument.presentation":["odp"],"application/vnd.oasis.opendocument.presentation-template":["otp"],"application/vnd.oasis.opendocument.spreadsheet":["ods"],"application/vnd.oasis.opendocument.spreadsheet-template":["ots"],"application/vnd.oasis.opendocument.text":["odt"],"application/vnd.oasis.opendocument.text-master":["odm"],"application/vnd.oasis.opendocument.text-template":["ott"],"application/vnd.oasis.opendocument.text-web":["oth"],"application/vnd.olpc-sugar":["xo"],"application/vnd.oma.dd2+xml":["dd2"],"application/vnd.openofficeorg.extension":["oxt"],"application/vnd.openxmlformats-officedocument.presentationml.presentation":["pptx"],"application/vnd.openxmlformats-officedocument.presentationml.slide":["sldx"],"application/vnd.openxmlformats-officedocument.presentationml.slideshow":["ppsx"],"application/vnd.openxmlformats-officedocument.presentationml.template":["potx"],"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":["xlsx"],"application/vnd.openxmlformats-officedocument.spreadsheetml.template":["xltx"],"application/vnd.openxmlformats-officedocument.wordprocessingml.document":["docx"],"application/vnd.openxmlformats-officedocument.wordprocessingml.template":["dotx"],"application/vnd.osgeo.mapguide.package":["mgp"],"application/vnd.osgi.dp":["dp"],"application/vnd.osgi.subsystem":["esa"],"application/vnd.palm":["pdb","pqa","oprc"],"application/vnd.pawaafile":["paw"],"application/vnd.pg.format":["str"],"application/vnd.pg.osasli":["ei6"],"application/vnd.picsel":["efif"],"application/vnd.pmi.widget":["wg"],"application/vnd.pocketlearn":["plf"],"application/vnd.powerbuilder6":["pbd"],"application/vnd.previewsystems.box":["box"],"application/vnd.proteus.magazine":["mgz"],"application/vnd.publishare-delta-tree":["qps"],"application/vnd.pvi.ptid1":["ptid"],"application/vnd.quark.quarkxpress":["qxd","qxt","qwd","qwt","qxl","qxb"],"application/vnd.realvnc.bed":["bed"],"application/vnd.recordare.musicxml":["mxl"],"application/vnd.recordare.musicxml+xml":["musicxml"],"application/vnd.rig.cryptonote":["cryptonote"],"application/vnd.rim.cod":["cod"],"application/vnd.rn-realmedia":["rm"],"application/vnd.rn-realmedia-vbr":["rmvb"],"application/vnd.route66.link66+xml":["link66"],"application/vnd.sailingtracker.track":["st"],"application/vnd.seemail":["see"],"application/vnd.sema":["sema"],"application/vnd.semd":["semd"],"application/vnd.semf":["semf"],"application/vnd.shana.informed.formdata":["ifm"],"application/vnd.shana.informed.formtemplate":["itp"],"application/vnd.shana.informed.interchange":["iif"],"application/vnd.shana.informed.package":["ipk"],"application/vnd.simtech-mindmapper":["twd","twds"],"application/vnd.smaf":["mmf"],"application/vnd.smart.teacher":["teacher"],"application/vnd.solent.sdkm+xml":["sdkm","sdkd"],"application/vnd.spotfire.dxp":["dxp"],"application/vnd.spotfire.sfs":["sfs"],"application/vnd.stardivision.calc":["sdc"],"application/vnd.stardivision.draw":["sda"],"application/vnd.stardivision.impress":["sdd"],"application/vnd.stardivision.math":["smf"],"application/vnd.stardivision.writer":["sdw","vor"],"application/vnd.stardivision.writer-global":["sgl"],"application/vnd.stepmania.package":["smzip"],"application/vnd.stepmania.stepchart":["sm"],"application/vnd.sun.xml.calc":["sxc"],"application/vnd.sun.xml.calc.template":["stc"],"application/vnd.sun.xml.draw":["sxd"],"application/vnd.sun.xml.draw.template":["std"],"application/vnd.sun.xml.impress":["sxi"],"application/vnd.sun.xml.impress.template":["sti"],"application/vnd.sun.xml.math":["sxm"],"application/vnd.sun.xml.writer":["sxw"],"application/vnd.sun.xml.writer.global":["sxg"],"application/vnd.sun.xml.writer.template":["stw"],"application/vnd.sus-calendar":["sus","susp"],"application/vnd.svd":["svd"],"application/vnd.symbian.install":["sis","sisx"],"application/vnd.syncml+xml":["xsm"],"application/vnd.syncml.dm+wbxml":["bdm"],"application/vnd.syncml.dm+xml":["xdm"],"application/vnd.tao.intent-module-archive":["tao"],"application/vnd.tcpdump.pcap":["pcap","cap","dmp"],"application/vnd.tmobile-livetv":["tmo"],"application/vnd.trid.tpt":["tpt"],"application/vnd.triscape.mxs":["mxs"],"application/vnd.trueapp":["tra"],"application/vnd.ufdl":["ufd","ufdl"],"application/vnd.uiq.theme":["utz"],"application/vnd.umajin":["umj"],"application/vnd.unity":["unityweb"],"application/vnd.uoml+xml":["uoml"],"application/vnd.vcx":["vcx"],"application/vnd.visio":["vsd","vst","vss","vsw"],"application/vnd.visionary":["vis"],"application/vnd.vsf":["vsf"],"application/vnd.wap.wbxml":["wbxml"],"application/vnd.wap.wmlc":["wmlc"],"application/vnd.wap.wmlscriptc":["wmlsc"],"application/vnd.webturbo":["wtb"],"application/vnd.wolfram.player":["nbp"],"application/vnd.wordperfect":["wpd"],"application/vnd.wqd":["wqd"],"application/vnd.wt.stf":["stf"],"application/vnd.xara":["xar"],"application/vnd.xfdl":["xfdl"],"application/vnd.yamaha.hv-dic":["hvd"],"application/vnd.yamaha.hv-script":["hvs"],"application/vnd.yamaha.hv-voice":["hvp"],"application/vnd.yamaha.openscoreformat":["osf"],"application/vnd.yamaha.openscoreformat.osfpvg+xml":["osfpvg"],"application/vnd.yamaha.smaf-audio":["saf"],"application/vnd.yamaha.smaf-phrase":["spf"],"application/vnd.yellowriver-custom-menu":["cmp"],"application/vnd.zul":["zir","zirz"],"application/vnd.zzazz.deck+xml":["zaz"],"application/voicexml+xml":["vxml"],"application/widget":["wgt"],"application/winhlp":["hlp"],"application/wsdl+xml":["wsdl"],"application/wspolicy+xml":["wspolicy"],"application/x-7z-compressed":["7z"],"application/x-abiword":["abw"],"application/x-ace-compressed":["ace"],"application/x-apple-diskimage":["dmg"],"application/x-authorware-bin":["aab","x32","u32","vox"],"application/x-authorware-map":["aam"],"application/x-authorware-seg":["aas"],"application/x-bcpio":["bcpio"],"application/x-bittorrent":["torrent"],"application/x-blorb":["blb","blorb"],"application/x-bzip":["bz"],"application/x-bzip2":["bz2","boz"],"application/x-cbr":["cbr","cba","cbt","cbz","cb7"],"application/x-cdlink":["vcd"],"application/x-cfs-compressed":["cfs"],"application/x-chat":["chat"],"application/x-chess-pgn":["pgn"],"application/x-chrome-extension":["crx"],"application/x-conference":["nsc"],"application/x-cpio":["cpio"],"application/x-csh":["csh"],"application/x-debian-package":["deb","udeb"],"application/x-dgc-compressed":["dgc"],"application/x-director":["dir","dcr","dxr","cst","cct","cxt","w3d","fgd","swa"],"application/x-doom":["wad"],"application/x-dtbncx+xml":["ncx"],"application/x-dtbook+xml":["dtb"],"application/x-dtbresource+xml":["res"],"application/x-dvi":["dvi"],"application/x-envoy":["evy"],"application/x-eva":["eva"],"application/x-font-bdf":["bdf"],"application/x-font-ghostscript":["gsf"],"application/x-font-linux-psf":["psf"],"application/x-font-otf":["otf"],"application/x-font-pcf":["pcf"],"application/x-font-snf":["snf"],"application/x-font-ttf":["ttf","ttc"],"application/x-font-type1":["pfa","pfb","pfm","afm"],"application/x-freearc":["arc"],"application/x-futuresplash":["spl"],"application/x-gca-compressed":["gca"],"application/x-glulx":["ulx"],"application/x-gnumeric":["gnumeric"],"application/x-gramps-xml":["gramps"],"application/x-gtar":["gtar"],"application/x-hdf":["hdf"],"application/x-install-instructions":["install"],"application/x-iso9660-image":["iso"],"application/x-java-jnlp-file":["jnlp"],"application/x-latex":["latex"],"application/x-lua-bytecode":["luac"],"application/x-lzh-compressed":["lzh","lha"],"application/x-mie":["mie"],"application/x-mobipocket-ebook":["prc","mobi"],"application/x-ms-application":["application"],"application/x-ms-shortcut":["lnk"],"application/x-ms-wmd":["wmd"],"application/x-ms-wmz":["wmz"],"application/x-ms-xbap":["xbap"],"application/x-msaccess":["mdb"],"application/x-msbinder":["obd"],"application/x-mscardfile":["crd"],"application/x-msclip":["clp"],"application/x-msdownload":["exe","dll","com","bat","msi"],"application/x-msmediaview":["mvb","m13","m14"],"application/x-msmetafile":["wmf","wmz","emf","emz"],"application/x-msmoney":["mny"],"application/x-mspublisher":["pub"],"application/x-msschedule":["scd"],"application/x-msterminal":["trm"],"application/x-mswrite":["wri"],"application/x-netcdf":["nc","cdf"],"application/x-nzb":["nzb"],"application/x-pkcs12":["p12","pfx"],"application/x-pkcs7-certificates":["p7b","spc"],"application/x-pkcs7-certreqresp":["p7r"],"application/x-rar-compressed":["rar"],"application/x-research-info-systems":["ris"],"application/x-sh":["sh"],"application/x-shar":["shar"],"application/x-shockwave-flash":["swf"],"application/x-silverlight-app":["xap"],"application/x-sql":["sql"],"application/x-stuffit":["sit"],"application/x-stuffitx":["sitx"],"application/x-subrip":["srt"],"application/x-sv4cpio":["sv4cpio"],"application/x-sv4crc":["sv4crc"],"application/x-t3vm-image":["t3"],"application/x-tads":["gam"],"application/x-tar":["tar"],"application/x-tcl":["tcl"],"application/x-tex":["tex"],"application/x-tex-tfm":["tfm"],"application/x-texinfo":["texinfo","texi"],"application/x-tgif":["obj"],"application/x-ustar":["ustar"],"application/x-wais-source":["src"],"application/x-web-app-manifest+json":["webapp"],"application/x-x509-ca-cert":["der","crt"],"application/x-xfig":["fig"],"application/x-xliff+xml":["xlf"],"application/x-xpinstall":["xpi"],"application/x-xz":["xz"],"application/x-zmachine":["z1","z2","z3","z4","z5","z6","z7","z8"],"application/xaml+xml":["xaml"],"application/xcap-diff+xml":["xdf"],"application/xenc+xml":["xenc"],"application/xhtml+xml":["xhtml","xht"],"application/xml":["xml","xsl","xsd"],"application/xml-dtd":["dtd"],"application/xop+xml":["xop"],"application/xproc+xml":["xpl"],"application/xslt+xml":["xslt"],"application/xspf+xml":["xspf"],"application/xv+xml":["mxml","xhvml","xvml","xvm"],"application/yang":["yang"],"application/yin+xml":["yin"],"application/zip":["zip"],"audio/adpcm":["adp"],"audio/basic":["au","snd"],"audio/midi":["mid","midi","kar","rmi"],"audio/mp4":["mp4a","m4a"],"audio/mpeg":["mpga","mp2","mp2a","mp3","m2a","m3a"],"audio/ogg":["oga","ogg","spx"],"audio/s3m":["s3m"],"audio/silk":["sil"],"audio/vnd.dece.audio":["uva","uvva"],"audio/vnd.digital-winds":["eol"],"audio/vnd.dra":["dra"],"audio/vnd.dts":["dts"],"audio/vnd.dts.hd":["dtshd"],"audio/vnd.lucent.voice":["lvp"],"audio/vnd.ms-playready.media.pya":["pya"],"audio/vnd.nuera.ecelp4800":["ecelp4800"],"audio/vnd.nuera.ecelp7470":["ecelp7470"],"audio/vnd.nuera.ecelp9600":["ecelp9600"],"audio/vnd.rip":["rip"],"audio/webm":["weba"],"audio/x-aac":["aac"],"audio/x-aiff":["aif","aiff","aifc"],"audio/x-caf":["caf"],"audio/x-flac":["flac"],"audio/x-matroska":["mka"],"audio/x-mpegurl":["m3u"],"audio/x-ms-wax":["wax"],"audio/x-ms-wma":["wma"],"audio/x-pn-realaudio":["ram","ra"],"audio/x-pn-realaudio-plugin":["rmp"],"audio/x-wav":["wav"],"audio/xm":["xm"],"chemical/x-cdx":["cdx"],"chemical/x-cif":["cif"],"chemical/x-cmdf":["cmdf"],"chemical/x-cml":["cml"],"chemical/x-csml":["csml"],"chemical/x-xyz":["xyz"],"font/opentype":["otf"],"image/bmp":["bmp"],"image/cgm":["cgm"],"image/g3fax":["g3"],"image/gif":["gif"],"image/ief":["ief"],"image/jpeg":["jpeg","jpg","jpe"],"image/ktx":["ktx"],"image/png":["png"],"image/prs.btif":["btif"],"image/sgi":["sgi"],"image/svg+xml":["svg","svgz"],"image/tiff":["tiff","tif"],"image/vnd.adobe.photoshop":["psd"],"image/vnd.dece.graphic":["uvi","uvvi","uvg","uvvg"],"image/vnd.djvu":["djvu","djv"],"image/vnd.dvb.subtitle":["sub"],"image/vnd.dwg":["dwg"],"image/vnd.dxf":["dxf"],"image/vnd.fastbidsheet":["fbs"],"image/vnd.fpx":["fpx"],"image/vnd.fst":["fst"],"image/vnd.fujixerox.edmics-mmr":["mmr"],"image/vnd.fujixerox.edmics-rlc":["rlc"],"image/vnd.ms-modi":["mdi"],"image/vnd.ms-photo":["wdp"],"image/vnd.net-fpx":["npx"],"image/vnd.wap.wbmp":["wbmp"],"image/vnd.xiff":["xif"],"image/webp":["webp"],"image/x-3ds":["3ds"],"image/x-cmu-raster":["ras"],"image/x-cmx":["cmx"],"image/x-freehand":["fh","fhc","fh4","fh5","fh7"],"image/x-icon":["ico"],"image/x-mrsid-image":["sid"],"image/x-pcx":["pcx"],"image/x-pict":["pic","pct"],"image/x-portable-anymap":["pnm"],"image/x-portable-bitmap":["pbm"],"image/x-portable-graymap":["pgm"],"image/x-portable-pixmap":["ppm"],"image/x-rgb":["rgb"],"image/x-tga":["tga"],"image/x-xbitmap":["xbm"],"image/x-xpixmap":["xpm"],"image/x-xwindowdump":["xwd"],"message/rfc822":["eml","mime"],"model/iges":["igs","iges"],"model/mesh":["msh","mesh","silo"],"model/vnd.collada+xml":["dae"],"model/vnd.dwf":["dwf"],"model/vnd.gdl":["gdl"],"model/vnd.gtw":["gtw"],"model/vnd.mts":["mts"],"model/vnd.vtu":["vtu"],"model/vrml":["wrl","vrml"],"model/x3d+binary":["x3db","x3dbz"],"model/x3d+vrml":["x3dv","x3dvz"],"model/x3d+xml":["x3d","x3dz"],"text/cache-manifest":["appcache","manifest"],"text/calendar":["ics","ifb"],"text/coffeescript":["coffee"],"text/css":["css"],"text/csv":["csv"],"text/hjson":["hjson"],"text/html":["html","htm"],"text/jade":["jade"],"text/jsx":["jsx"],"text/less":["less"],"text/n3":["n3"],"text/plain":["txt","text","conf","def","list","log","in","ini"],"text/prs.lines.tag":["dsc"],"text/richtext":["rtx"],"text/sgml":["sgml","sgm"],"text/stylus":["stylus","styl"],"text/tab-separated-values":["tsv"],"text/troff":["t","tr","roff","man","me","ms"],"text/turtle":["ttl"],"text/uri-list":["uri","uris","urls"],"text/vcard":["vcard"],"text/vnd.curl":["curl"],"text/vnd.curl.dcurl":["dcurl"],"text/vnd.curl.mcurl":["mcurl"],"text/vnd.curl.scurl":["scurl"],"text/vnd.dvb.subtitle":["sub"],"text/vnd.fly":["fly"],"text/vnd.fmi.flexstor":["flx"],"text/vnd.graphviz":["gv"],"text/vnd.in3d.3dml":["3dml"],"text/vnd.in3d.spot":["spot"],"text/vnd.sun.j2me.app-descriptor":["jad"],"text/vnd.wap.wml":["wml"],"text/vnd.wap.wmlscript":["wmls"],"text/vtt":["vtt"],"text/x-asm":["s","asm"],"text/x-c":["c","cc","cxx","cpp","h","hh","dic"],"text/x-component":["htc"],"text/x-fortran":["f","for","f77","f90"],"text/x-handlebars-template":["hbs"],"text/x-java-source":["java"],"text/x-lua":["lua"],"text/x-markdown":["markdown","md","mkd"],"text/x-nfo":["nfo"],"text/x-opml":["opml"],"text/x-pascal":["p","pas"],"text/x-sass":["sass"],"text/x-scss":["scss"],"text/x-setext":["etx"],"text/x-sfv":["sfv"],"text/x-uuencode":["uu"],"text/x-vcalendar":["vcs"],"text/x-vcard":["vcf"],"text/yaml":["yaml","yml"],"video/3gpp":["3gp"],"video/3gpp2":["3g2"],"video/h261":["h261"],"video/h263":["h263"],"video/h264":["h264"],"video/jpeg":["jpgv"],"video/jpm":["jpm","jpgm"],"video/mj2":["mj2","mjp2"],"video/mp2t":["ts"],"video/mp4":["mp4","mp4v","mpg4"],"video/mpeg":["mpeg","mpg","mpe","m1v","m2v"],"video/ogg":["ogv"],"video/quicktime":["qt","mov"],"video/vnd.dece.hd":["uvh","uvvh"],"video/vnd.dece.mobile":["uvm","uvvm"],"video/vnd.dece.pd":["uvp","uvvp"],"video/vnd.dece.sd":["uvs","uvvs"],"video/vnd.dece.video":["uvv","uvvv"],"video/vnd.dvb.file":["dvb"],"video/vnd.fvt":["fvt"],"video/vnd.mpegurl":["mxu","m4u"],"video/vnd.ms-playready.media.pyv":["pyv"],"video/vnd.uvvu.mp4":["uvu","uvvu"],"video/vnd.vivo":["viv"],"video/webm":["webm"],"video/x-f4v":["f4v"],"video/x-fli":["fli"],"video/x-flv":["flv"],"video/x-m4v":["m4v"],"video/x-matroska":["mkv","mk3d","mks"],"video/x-mng":["mng"],"video/x-ms-asf":["asf","asx"],"video/x-ms-vob":["vob"],"video/x-ms-wm":["wm"],"video/x-ms-wmv":["wmv"],"video/x-ms-wmx":["wmx"],"video/x-ms-wvx":["wvx"],"video/x-msvideo":["avi"],"video/x-sgi-movie":["movie"],"video/x-smv":["smv"],"x-conference/x-cooltalk":["ice"]}
/**
* Helpers.
*/
var s = 1000;
var m = s * 60;
var h = m * 60;
var d = h * 24;
var y = d * 365.25;
/**
* Parse or format the given `val`.
*
* Options:
*
* - `long` verbose formatting [false]
*
* @param {String|Number} val
* @param {Object} options
* @return {String|Number}
* @api public
*/
module.exports = function(val, options){
options = options || {};
if ('string' == typeof val) return parse(val);
return options.long
? long(val)
: short(val);
};
/**
* Parse the given `str` and return milliseconds.
*
* @param {String} str
* @return {Number}
* @api private
*/
function parse(str) {
var match = /^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(str);
if (!match) return;
var n = parseFloat(match[1]);
var type = (match[2] || 'ms').toLowerCase();
switch (type) {
case 'years':
case 'year':
case 'yrs':
case 'yr':
case 'y':
return n * y;
case 'days':
case 'day':
case 'd':
return n * d;
case 'hours':
case 'hour':
case 'hrs':
case 'hr':
case 'h':
return n * h;
case 'minutes':
case 'minute':
case 'mins':
case 'min':
case 'm':
return n * m;
case 'seconds':
case 'second':
case 'secs':
case 'sec':
case 's':
return n * s;
case 'milliseconds':
case 'millisecond':
case 'msecs':
case 'msec':
case 'ms':
return n;
}
}
/**
* Short format for `ms`.
*
* @param {Number} ms
* @return {String}
* @api private
*/
function short(ms) {
if (ms >= d) return Math.round(ms / d) + 'd';
if (ms >= h) return Math.round(ms / h) + 'h';
if (ms >= m) return Math.round(ms / m) + 'm';
if (ms >= s) return Math.round(ms / s) + 's';
return ms + 'ms';
}
/**
* Long format for `ms`.
*
* @param {Number} ms
* @return {String}
* @api private
*/
function long(ms) {
return plural(ms, d, 'day')
|| plural(ms, h, 'hour')
|| plural(ms, m, 'minute')
|| plural(ms, s, 'second')
|| ms + ' ms';
}
/**
* Pluralization helper.
*/
function plural(ms, n, name) {
if (ms < n) return;
if (ms < n * 1.5) return Math.floor(ms / n) + ' ' + name;
return Math.ceil(ms / n) + ' ' + name + 's';
}
(The MIT License)
Copyright (c) 2014 Guillermo Rauch <rauchg@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
{
"name": "ms",
"version": "0.7.0",
"description": "Tiny ms conversion utility",
"repository": {
"type": "git",
"url": "git://github.com/guille/ms.js.git"
},
"main": "./index",
"devDependencies": {
"mocha": "*",
"expect.js": "*",
"serve": "*"
},
"component": {
"scripts": {
"ms/index.js": "index.js"
}
},
"gitHead": "1e9cd9b05ef0dc26f765434d2bfee42394376e52",
"bugs": {
"url": "https://github.com/guille/ms.js/issues"
},
"homepage": "https://github.com/guille/ms.js",
"_id": "ms@0.7.0",
"scripts": {},
"_shasum": "865be94c2e7397ad8a57da6a633a6e2f30798b83",
"_from": "ms@0.7.0",
"_npmVersion": "1.4.21",
"_npmUser": {
"name": "rauchg",
"email": "rauchg@gmail.com"
},
"maintainers": [
{
"name": "rauchg",
"email": "rauchg@gmail.com"
}
],
"dist": {
"shasum": "865be94c2e7397ad8a57da6a633a6e2f30798b83",
"tarball": "http://registry.npmjs.org/ms/-/ms-0.7.0.tgz"
},
"directories": {},
"_resolved": "https://registry.npmjs.org/ms/-/ms-0.7.0.tgz",
"readme": "ERROR: No README data found!"
}

ms.js: miliseconds conversion utility

ms('2 days')  // 172800000
ms('1d')      // 86400000
ms('10h')     // 36000000
ms('2.5 hrs') // 9000000
ms('2h')      // 7200000
ms('1m')      // 60000
ms('5s')      // 5000
ms('100')     // 100
ms(60000)             // "1m"
ms(2 * 60000)         // "2m"
ms(ms('10 hours'))    // "10h"
ms(60000, { long: true })             // "1 minute"
ms(2 * 60000, { long: true })         // "2 minutes"
ms(ms('10 hours'), { long: true })    // "10 hours"
  • Node/Browser compatible. Published as ms in NPM.
  • If a number is supplied to ms, a string with a unit is returned.
  • If a string that contains the number is supplied, it returns it as a number (e.g: it returns 100 for '100').
  • If you pass a string with a number and a valid unit, the number of equivalent ms is returned.

License

MIT

{
"name": "send",
"description": "Better streaming static file server with Range and conditional-GET support",
"version": "0.12.2",
"author": {
"name": "TJ Holowaychuk",
"email": "tj@vision-media.ca"
},
"contributors": [
{
"name": "Douglas Christopher Wilson",
"email": "doug@somethingdoug.com"
}
],
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/pillarjs/send"
},
"keywords": [
"static",
"file",
"server"
],
"dependencies": {
"debug": "~2.1.3",
"depd": "~1.0.0",
"destroy": "1.0.3",
"escape-html": "1.0.1",
"etag": "~1.5.1",
"fresh": "0.2.4",
"mime": "1.3.4",
"ms": "0.7.0",
"on-finished": "~2.2.0",
"range-parser": "~1.0.2"
},
"devDependencies": {
"after": "0.8.1",
"istanbul": "0.3.7",
"mocha": "~2.2.1",
"supertest": "~0.15.0"
},
"files": [
"HISTORY.md",
"LICENSE",
"README.md",
"index.js"
],
"engines": {
"node": ">= 0.8.0"
},
"scripts": {
"test": "mocha --check-leaks --reporter spec --bail",
"test-ci": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --check-leaks --reporter spec",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --check-leaks --reporter dot"
},
"gitHead": "c9a4bf66fa7add5976b2fdbbf3ea20d7f83673f8",
"bugs": {
"url": "https://github.com/pillarjs/send/issues"
},
"homepage": "https://github.com/pillarjs/send",
"_id": "send@0.12.2",
"_shasum": "ba6785e47ab41aa0358b9da401ab22ff0f58eab6",
"_from": "send@0.12.2",
"_npmVersion": "1.4.28",
"_npmUser": {
"name": "dougwilson",
"email": "doug@somethingdoug.com"
},
"maintainers": [
{
"name": "tjholowaychuk",
"email": "tj@vision-media.ca"
},
{
"name": "dougwilson",
"email": "doug@somethingdoug.com"
}
],
"dist": {
"shasum": "ba6785e47ab41aa0358b9da401ab22ff0f58eab6",
"tarball": "http://registry.npmjs.org/send/-/send-0.12.2.tgz"
},
"directories": {},
"_resolved": "https://registry.npmjs.org/send/-/send-0.12.2.tgz",
"readme": "ERROR: No README data found!"
}

send

NPM Version NPM Downloads Linux Build Windows Build Test Coverage Gratipay

Send is a library for streaming files from the file system as a http response supporting partial responses (Ranges), conditional-GET negotiation, high test coverage, and granular events which may be leveraged to take appropriate actions in your application or framework.

Looking to serve up entire folders mapped to URLs? Try serve-static.

Installation

$ npm install send

API

var send = require('send')

send(req, path, [options])

Create a new SendStream for the given path to send to a res. The req is the Node.js HTTP request and the path is a urlencoded path to send (urlencoded, not the actual file-system path).

Options

dotfiles

Set how "dotfiles" are treated when encountered. A dotfile is a file or directory that begins with a dot ("."). Note this check is done on the path itself without checking if the path actually exists on the disk. If root is specified, only the dotfiles above the root are checked (i.e. the root itself can be within a dotfile when when set to "deny").

  • 'allow' No special treatment for dotfiles.
  • 'deny' Send a 403 for any request for a dotfile.
  • 'ignore' Pretend like the dotfile does not exist and 404.

The default value is similar to 'ignore', with the exception that this default will not ignore the files within a directory that begins with a dot, for backward-compatibility.

etag

Enable or disable etag generation, defaults to true.

extensions

If a given file doesn't exist, try appending one of the given extensions, in the given order. By default, this is disabled (set to false). An example value that will serve extension-less HTML files: ['html', 'htm']. This is skipped if the requested file already has an extension.

index

By default send supports "index.html" files, to disable this set false or to supply a new index pass a string or an array in preferred order.

lastModified

Enable or disable Last-Modified header, defaults to true. Uses the file system's last modified value.

maxAge

Provide a max-age in milliseconds for http caching, defaults to 0. This can also be a string accepted by the ms module.

root

Serve files relative to path.

Events

The SendStream is an event emitter and will emit the following events:

  • error an error occurred (err)
  • directory a directory was requested
  • file a file was requested (path, stat)
  • headers the headers are about to be set on a file (res, path, stat)
  • stream file streaming has started (stream)
  • end streaming has completed

.pipe

The pipe method is used to pipe the response into the Node.js HTTP response object, typically send(req, path, options).pipe(res).

Error-handling

By default when no error listeners are present an automatic response will be made, otherwise you have full control over the response, aka you may show a 5xx page etc.

Caching

It does not perform internal caching, you should use a reverse proxy cache such as Varnish for this, or those fancy things called CDNs. If your application is small enough that it would benefit from single-node memory caching, it's small enough that it does not need caching at all ;).

Debugging

To enable debug() instrumentation output export DEBUG:

$ DEBUG=send node app

Running tests

$ npm install
$ npm test

Examples

Small example

var http = require('http');
var send = require('send');

var app = http.createServer(function(req, res){
  send(req, req.url).pipe(res);
}).listen(3000);

Serving from a root directory with custom error-handling:

var http = require('http');
var send = require('send');
var url = require('url');

var app = http.createServer(function(req, res){
  // your custom error-handling logic:
  function error(err) {
    res.statusCode = err.status || 500;
    res.end(err.message);
  }

  // your custom headers
  function headers(res, path, stat) {
    // serve all files for download
    res.setHeader('Content-Disposition', 'attachment');
  }

  // your custom directory handling logic:
  function redirect() {
    res.statusCode = 301;
    res.setHeader('Location', req.url + '/');
    res.end('Redirecting to ' + req.url + '/');
  }

  // transfer arbitrary files from within
  // /www/example.com/public/*
  send(req, url.parse(req.url).pathname, {root: '/www/example.com/public'})
  .on('error', error)
  .on('directory', redirect)
  .on('headers', headers)
  .pipe(res);
}).listen(3000);

License

MIT

1.9.2 / 2015-03-14

  • deps: send@0.12.2
    • Throw errors early for invalid extensions or index options
    • deps: debug@~2.1.3

1.9.1 / 2015-02-17

  • deps: send@0.12.1
    • Fix regression sending zero-length files

1.9.0 / 2015-02-16

  • deps: send@0.12.0
    • Always read the stat size from the file
    • Fix mutating passed-in options
    • deps: mime@1.3.4

1.8.1 / 2015-01-20

  • Fix redirect loop in Node.js 0.11.14
  • deps: send@0.11.1
    • Fix root path disclosure

1.8.0 / 2015-01-05

  • deps: send@0.11.0
    • deps: debug@~2.1.1
    • deps: etag@~1.5.1
    • deps: ms@0.7.0
    • deps: on-finished@~2.2.0

1.7.2 / 2015-01-02

  • Fix potential open redirect when mounted at root

1.7.1 / 2014-10-22

  • deps: send@0.10.1
    • deps: on-finished@~2.1.1

1.7.0 / 2014-10-15

  • deps: send@0.10.0
    • deps: debug@~2.1.0
    • deps: depd@~1.0.0
    • deps: etag@~1.5.0

1.6.5 / 2015-02-04

  • Fix potential open redirect when mounted at root
    • Back-ported from v1.7.2

1.6.4 / 2014-10-08

  • Fix redirect loop when index file serving disabled

1.6.3 / 2014-09-24

  • deps: send@0.9.3
    • deps: etag@~1.4.0

1.6.2 / 2014-09-15

  • deps: send@0.9.2
    • deps: depd@0.4.5
    • deps: etag@~1.3.1
    • deps: range-parser@~1.0.2

1.6.1 / 2014-09-07

  • deps: send@0.9.1
    • deps: fresh@0.2.4

1.6.0 / 2014-09-07

  • deps: send@0.9.0
    • Add lastModified option
    • Use etag to generate ETag header
    • deps: debug@~2.0.0

1.5.4 / 2014-09-04

  • deps: send@0.8.5
    • Fix a path traversal issue when using root
    • Fix malicious path detection for empty string path

1.5.3 / 2014-08-17

  • deps: send@0.8.3

1.5.2 / 2014-08-14

  • deps: send@0.8.2
    • Work around fd leak in Node.js 0.10 for fs.ReadStream

1.5.1 / 2014-08-09

  • Fix parsing of weird req.originalUrl values
  • deps: parseurl@~1.3.0
  • deps: utils-merge@1.0.0

1.5.0 / 2014-08-05

  • deps: send@0.8.1
    • Add extensions option

1.4.4 / 2014-08-04

  • deps: send@0.7.4
    • Fix serving index files without root dir

1.4.3 / 2014-07-29

  • deps: send@0.7.3
    • Fix incorrect 403 on Windows and Node.js 0.11

1.4.2 / 2014-07-27

  • deps: send@0.7.2
    • deps: depd@0.4.4

1.4.1 / 2014-07-26

  • deps: send@0.7.1
    • deps: depd@0.4.3

1.4.0 / 2014-07-21

  • deps: parseurl@~1.2.0
    • Cache URLs based on original value
    • Remove no-longer-needed URL mis-parse work-around
    • Simplify the "fast-path" RegExp
  • deps: send@0.7.0
    • Add dotfiles option
    • deps: debug@1.0.4
    • deps: depd@0.4.2

1.3.2 / 2014-07-11

  • deps: send@0.6.0
    • Cap maxAge value to 1 year
    • deps: debug@1.0.3

1.3.1 / 2014-07-09

  • deps: parseurl@~1.1.3
    • faster parsing of href-only URLs

1.3.0 / 2014-06-28

  • Add setHeaders option
  • Include HTML link in redirect response
  • deps: send@0.5.0
    • Accept string for maxAge (converted by ms)

1.2.3 / 2014-06-11

  • deps: send@0.4.3
    • Do not throw un-catchable error on file open race condition
    • Use escape-html for HTML escaping
    • deps: debug@1.0.2
    • deps: finished@1.2.2
    • deps: fresh@0.2.2

1.2.2 / 2014-06-09

  • deps: send@0.4.2
    • fix "event emitter leak" warnings
    • deps: debug@1.0.1
    • deps: finished@1.2.1

1.2.1 / 2014-06-02

  • use escape-html for escaping
  • deps: send@0.4.1
    • Send max-age in Cache-Control in correct format

1.2.0 / 2014-05-29

  • deps: send@0.4.0
    • Calculate ETag with md5 for reduced collisions
    • Fix wrong behavior when index file matches directory
    • Ignore stream errors after request ends
    • Skip directories in index file search
    • deps: debug@0.8.1

1.1.0 / 2014-04-24

  • Accept options directly to send module
  • deps: send@0.3.0

1.0.4 / 2014-04-07

  • Resolve relative paths at middleware setup
  • Use parseurl to parse the URL from request

1.0.3 / 2014-03-20

  • Do not rely on connect-like environments

1.0.2 / 2014-03-06

  • deps: send@0.2.0

1.0.1 / 2014-03-05

  • Add mime export for back-compat

1.0.0 / 2014-03-05

  • Genesis from connect
/*!
* serve-static
* Copyright(c) 2010 Sencha Inc.
* Copyright(c) 2011 TJ Holowaychuk
* Copyright(c) 2014 Douglas Christopher Wilson
* MIT Licensed
*/
/**
* Module dependencies.
*/
var escapeHtml = require('escape-html');
var merge = require('utils-merge');
var parseurl = require('parseurl');
var resolve = require('path').resolve;
var send = require('send');
var url = require('url');
/**
* @param {String} root
* @param {Object} options
* @return {Function}
* @api public
*/
exports = module.exports = function serveStatic(root, options) {
if (!root) {
throw new TypeError('root path required')
}
if (typeof root !== 'string') {
throw new TypeError('root path must be a string')
}
// copy options object
options = merge({}, options)
// resolve root to absolute
root = resolve(root)
// default redirect
var redirect = options.redirect !== false
// headers listener
var setHeaders = options.setHeaders
delete options.setHeaders
if (setHeaders && typeof setHeaders !== 'function') {
throw new TypeError('option setHeaders must be function')
}
// setup options for send
options.maxage = options.maxage || options.maxAge || 0
options.root = root
return function serveStatic(req, res, next) {
if (req.method !== 'GET' && req.method !== 'HEAD') {
return next()
}
var opts = merge({}, options)
var originalUrl = parseurl.original(req)
var path = parseurl(req).pathname
var hasTrailingSlash = originalUrl.pathname[originalUrl.pathname.length - 1] === '/'
if (path === '/' && !hasTrailingSlash) {
// make sure redirect occurs at mount
path = ''
}
// create send stream
var stream = send(req, path, opts)
if (redirect) {
// redirect relative to originalUrl
stream.on('directory', function redirect() {
if (hasTrailingSlash) {
return next()
}
// append trailing slash
originalUrl.path = null
originalUrl.pathname = collapseLeadingSlashes(originalUrl.pathname + '/')
// reformat the URL
var target = url.format(originalUrl)
// send redirect response
res.statusCode = 303
res.setHeader('Content-Type', 'text/html; charset=utf-8')
res.setHeader('Location', target)
res.end('Redirecting to <a href="' + escapeHtml(target) + '">' + escapeHtml(target) + '</a>\n')
})
} else {
// forward to next middleware on directory
stream.on('directory', next)
}
// add headers listener
if (setHeaders) {
stream.on('headers', setHeaders)
}
// forward non-404 errors
stream.on('error', function error(err) {
next(err.status === 404 ? null : err)
})
// pipe
stream.pipe(res)
}
}
/**
* Expose mime module.
*
* If you wish to extend the mime table use this
* reference to the "mime" module in the npm registry.
*/
exports.mime = send.mime
/**
* Collapse all leading slashes into a single slash
* @private
*/
function collapseLeadingSlashes(str) {
for (var i = 0; i < str.length; i++) {
if (str[i] !== '/') {
break
}
}
return i > 1
? '/' + str.substr(i)
: str
}
(The MIT License)
Copyright (c) 2010 Sencha Inc.
Copyright (c) 2011 LearnBoost
Copyright (c) 2011 TJ Holowaychuk
Copyright (c) 2014 Douglas Christopher Wilson
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
{
"name": "serve-static",
"description": "Serve static files",
"version": "1.9.2",
"author": {
"name": "Douglas Christopher Wilson",
"email": "doug@somethingdoug.com"
},
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/expressjs/serve-static"
},
"dependencies": {
"escape-html": "1.0.1",
"parseurl": "~1.3.0",
"send": "0.12.2",
"utils-merge": "1.0.0"
},
"devDependencies": {
"istanbul": "0.3.7",
"mocha": "~2.2.1",
"supertest": "~0.15.0"
},
"files": [
"LICENSE",
"HISTORY.md",
"index.js"
],
"engines": {
"node": ">= 0.8.0"
},
"scripts": {
"test": "mocha --reporter spec --bail --check-leaks test/",
"test-ci": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/"
},
"gitHead": "6446e1c45de75f143b36ce60dd75c4daf52d2376",
"bugs": {
"url": "https://github.com/expressjs/serve-static/issues"
},
"homepage": "https://github.com/expressjs/serve-static",
"_id": "serve-static@1.9.2",
"_shasum": "069fa32453557b218ec2e39140c82d8905d5672c",
"_from": "serve-static@>=1.9.2 <1.10.0",
"_npmVersion": "1.4.28",
"_npmUser": {
"name": "dougwilson",
"email": "doug@somethingdoug.com"
},
"maintainers": [
{
"name": "dougwilson",
"email": "doug@somethingdoug.com"
},
{
"name": "jongleberry",
"email": "jonathanrichardong@gmail.com"
},
{
"name": "shtylman",
"email": "shtylman@gmail.com"
},
{
"name": "tjholowaychuk",
"email": "tj@vision-media.ca"
},
{
"name": "mscdex",
"email": "mscdex@mscdex.net"
},
{
"name": "fishrock123",
"email": "fishrock123@rocketmail.com"
}
],
"dist": {
"shasum": "069fa32453557b218ec2e39140c82d8905d5672c",
"tarball": "http://registry.npmjs.org/serve-static/-/serve-static-1.9.2.tgz"
},
"directories": {},
"_resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.9.2.tgz",
"readme": "ERROR: No README data found!"
}

serve-static

NPM Version NPM Downloads Linux Build Windows Build Test Coverage Gratipay

Install

$ npm install serve-static

API

var serveStatic = require('serve-static')

serveStatic(root, options)

Create a new middleware function to serve files from within a given root directory. The file to serve will be determined by combining req.url with the provided root directory. When a file is not found, instead of sending a 404 response, this module will instead call next() to move on to the next middleware, allowing for stacking and fall-backs.

Options

dotfiles

Set how "dotfiles" are treated when encountered. A dotfile is a file or directory that begins with a dot ("."). Note this check is done on the path itself without checking if the path actually exists on the disk. If root is specified, only the dotfiles above the root are checked (i.e. the root itself can be within a dotfile when set to "deny").

The default value is 'ignore'.

  • 'allow' No special treatment for dotfiles.
  • 'deny' Send a 403 for any request for a dotfile.
  • 'ignore' Pretend like the dotfile does not exist and call next().
etag

Enable or disable etag generation, defaults to true.

extensions

Set file extension fallbacks. When set, if a file is not found, the given extensions will be added to the file name and search for. The first that exists will be served. Example: ['html', 'htm'].

The default value is false.

index

By default this module will send "index.html" files in response to a request on a directory. To disable this set false or to supply a new index pass a string or an array in preferred order.

lastModified

Enable or disable Last-Modified header, defaults to true. Uses the file system's last modified value.

maxAge

Provide a max-age in milliseconds for http caching, defaults to 0. This can also be a string accepted by the ms module.

redirect

Redirect to trailing "/" when the pathname is a dir. Defaults to true.

setHeaders

Function to set custom headers on response. Alterations to the headers need to occur synchronously. The function is called as fn(res, path, stat), where the arguments are:

  • res the response object
  • path the file path that is being sent
  • stat the stat object of the file that is being sent

Examples

Serve files with vanilla node.js http server

var finalhandler = require('finalhandler')
var http = require('http')
var serveStatic = require('serve-static')

// Serve up public/ftp folder
var serve = serveStatic('public/ftp', {'index': ['index.html', 'index.htm']})

// Create server
var server = http.createServer(function(req, res){
  var done = finalhandler(req, res)
  serve(req, res, done)
})

// Listen
server.listen(3000)

Serve all files as downloads

var contentDisposition = require('content-disposition')
var finalhandler = require('finalhandler')
var http = require('http')
var serveStatic = require('serve-static')

// Serve up public/ftp folder
var serve = serveStatic('public/ftp', {
  'index': false,
  'setHeaders': setHeaders
})

// Set header to force download
function setHeaders(res, path) {
  res.setHeader('Content-Disposition', contentDisposition(path))
}

// Create server
var server = http.createServer(function(req, res){
  var done = finalhandler(req, res)
  serve(req, res, done)
})

// Listen
server.listen(3000)

Serving using express

Simple

This is a simple example of using Express.

var express = require('express')
var serveStatic = require('serve-static')

var app = express()

app.use(serveStatic('public/ftp', {'index': ['default.html', 'default.htm']}))
app.listen(3000)

Multiple roots

This example shows a simple way to search through multiple directories. Files are look for in public-optimized/ first, then public/ second as a fallback.

var express = require('express')
var serveStatic = require('serve-static')

var app = express()

app.use(serveStatic(__dirname + '/public-optimized'))
app.use(serveStatic(__dirname + '/public'))
app.listen(3000)

Different settings for paths

This example shows how to set a different max age depending on the served file type. In this example, HTML files are not cached, while everything else is for 1 day.

var express = require('express')
var serveStatic = require('serve-static')

var app = express()

app.use(serveStatic(__dirname + '/public', {
  maxAge: '1d',
  setHeaders: setCustomCacheControl
}))

app.listen(3000)

function setCustomCacheControl(res, path) {
  if (serveStatic.mime.lookup(path) === 'text/html') {
    // Custom Cache-Control for HTML files
    res.setHeader('Cache-Control', 'public, max-age=0')
  }
}

License

MIT

1.6.1 / 2015-03-13

  • deps: mime-types@~2.0.10
    • Add new mime types

1.6.0 / 2015-02-12

  • fix false-positives in hasBody Transfer-Encoding check
  • support wildcard for both type and subtype (*/*)

1.5.7 / 2015-02-09

  • fix argument reassignment
  • deps: mime-types@~2.0.9
    • Add new mime types

1.5.6 / 2015-01-29

  • deps: mime-types@~2.0.8
    • Add new mime types

1.5.5 / 2014-12-30

  • deps: mime-types@~2.0.7
    • Add new mime types
    • Fix missing extensions
    • Fix various invalid MIME type entries
    • Remove example template MIME types
    • deps: mime-db@~1.5.0

1.5.4 / 2014-12-10

  • deps: mime-types@~2.0.4
    • Add new mime types
    • deps: mime-db@~1.3.0

1.5.3 / 2014-11-09

  • deps: mime-types@~2.0.3
    • Add new mime types
    • deps: mime-db@~1.2.0

1.5.2 / 2014-09-28

  • deps: mime-types@~2.0.2
    • Add new mime types
    • deps: mime-db@~1.1.0

1.5.1 / 2014-09-07

  • Support Node.js 0.6
  • deps: media-typer@0.3.0
  • deps: mime-types@~2.0.1
    • Support Node.js 0.6

1.5.0 / 2014-09-05

  • fix hasbody to be true for content-length: 0

1.4.0 / 2014-09-02

  • update mime-types

1.3.2 / 2014-06-24

  • use ~ range on mime-types

1.3.1 / 2014-06-19

  • fix global variable leak

1.3.0 / 2014-06-19

  • improve type parsing

    • invalid media type never matches
    • media type not case-sensitive
    • extra LWS does not affect results

1.2.2 / 2014-06-19

  • fix behavior on unknown type argument

1.2.1 / 2014-06-03

  • switch dependency from mime to mime-types@1.0.0

1.2.0 / 2014-05-11

  • support suffix matching:

    • +json matches application/vnd+json
    • */vnd+json matches application/vnd+json
    • application/*+json matches application/vnd+json

1.1.0 / 2014-04-12

  • add non-array values support

  • expose internal utilities:

    • .is()
    • .hasBody()
    • .normalize()
    • .match()

1.0.1 / 2014-03-30

  • add multipart as a shorthand
var typer = require('media-typer')
var mime = require('mime-types')
module.exports = typeofrequest;
typeofrequest.is = typeis;
typeofrequest.hasBody = hasbody;
typeofrequest.normalize = normalize;
typeofrequest.match = mimeMatch;
/**
* Compare a `value` content-type with `types`.
* Each `type` can be an extension like `html`,
* a special shortcut like `multipart` or `urlencoded`,
* or a mime type.
*
* If no types match, `false` is returned.
* Otherwise, the first `type` that matches is returned.
*
* @param {String} value
* @param {Array} types
* @return String
*/
function typeis(value, types_) {
var i
var types = types_
// remove parameters and normalize
var val = typenormalize(value)
// no type or invalid
if (!val) {
return false
}
// support flattened arguments
if (types && !Array.isArray(types)) {
types = new Array(arguments.length - 1)
for (i = 0; i < types.length; i++) {
types[i] = arguments[i + 1]
}
}
// no types, return the content type
if (!types || !types.length) {
return val
}
var type
for (i = 0; i < types.length; i++) {
if (mimeMatch(normalize(type = types[i]), val)) {
return type[0] === '+' || ~type.indexOf('*')
? val
: type
}
}
// no matches
return false;
}
/**
* Check if a request has a request body.
* A request with a body __must__ either have `transfer-encoding`
* or `content-length` headers set.
* http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.3
*
* @param {Object} request
* @return {Boolean}
* @api public
*/
function hasbody(req) {
return req.headers['transfer-encoding'] !== undefined
|| !isNaN(req.headers['content-length'])
}
/**
* Check if the incoming request contains the "Content-Type"
* header field, and it contains any of the give mime `type`s.
* If there is no request body, `null` is returned.
* If there is no content type, `false` is returned.
* Otherwise, it returns the first `type` that matches.
*
* Examples:
*
* // With Content-Type: text/html; charset=utf-8
* this.is('html'); // => 'html'
* this.is('text/html'); // => 'text/html'
* this.is('text/*', 'application/json'); // => 'text/html'
*
* // When Content-Type is application/json
* this.is('json', 'urlencoded'); // => 'json'
* this.is('application/json'); // => 'application/json'
* this.is('html', 'application/*'); // => 'application/json'
*
* this.is('html'); // => false
*
* @param {String|Array} types...
* @return {String|false|null}
* @api public
*/
function typeofrequest(req, types_) {
var types = types_
// no body
if (!hasbody(req)) {
return null
}
// support flattened arguments
if (arguments.length > 2) {
types = new Array(arguments.length - 1)
for (var i = 0; i < types.length; i++) {
types[i] = arguments[i + 1]
}
}
// request content type
var value = req.headers['content-type']
return typeis(value, types);
}
/**
* Normalize a mime type.
* If it's a shorthand, expand it to a valid mime type.
*
* In general, you probably want:
*
* var type = is(req, ['urlencoded', 'json', 'multipart']);
*
* Then use the appropriate body parsers.
* These three are the most common request body types
* and are thus ensured to work.
*
* @param {String} type
* @api private
*/
function normalize(type) {
switch (type) {
case 'urlencoded':
type = 'application/x-www-form-urlencoded'
break
case 'multipart':
type = 'multipart/*'
break
}
if (type[0] === '+') {
// "+json" -> "*/*+json" expando
type = '*/*' + type
}
return type.indexOf('/') === -1
? mime.lookup(type)
: type
}
/**
* Check if `exected` mime type
* matches `actual` mime type with
* wildcard and +suffix support.
*
* @param {String} expected
* @param {String} actual
* @return {Boolean}
* @api private
*/
function mimeMatch(expected, actual) {
// invalid type
if (expected === false) {
return false
}
// split types
var actualParts = actual.split('/')
var expectedParts = expected.split('/')
// invalid format
if (actualParts.length !== 2 || expectedParts.length !== 2) {
return false
}
// validate type
if (expectedParts[0] !== '*' && expectedParts[0] !== actualParts[0]) {
return false
}
// validate suffix wildcard
if (expectedParts[1].substr(0, 2) === '*+') {
return expectedParts[1].length <= actualParts[1].length + 1
&& expectedParts[1].substr(1) === actualParts[1].substr(1 - expectedParts[1].length)
}
// validate subtype
if (expectedParts[1] !== '*' && expectedParts[1] !== actualParts[1]) {
return false
}
return true
}
/**
* Normalize a type and remove parameters.
*
* @param {string} value
* @return {string}
* @api private
*/
function typenormalize(value) {
try {
var type = typer.parse(value)
delete type.parameters
return typer.format(type)
} catch (err) {
return null
}
}
The MIT License (MIT)
Copyright (c) 2014 Jonathan Ong me@jongleberry.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

0.3.0 / 2014-09-07

  • Support Node.js 0.6
  • Throw error when parameter format invalid on parse

0.2.0 / 2014-06-18

  • Add typer.format() to format media types

0.1.0 / 2014-06-17

  • Accept req as argument to parse
  • Accept res as argument to parse
  • Parse media type with extra LWS between type and first parameter

0.0.0 / 2014-06-13

  • Initial implementation
/*!
* media-typer
* Copyright(c) 2014 Douglas Christopher Wilson
* MIT Licensed
*/
/**
* RegExp to match *( ";" parameter ) in RFC 2616 sec 3.7
*
* parameter = token "=" ( token | quoted-string )
* token = 1*<any CHAR except CTLs or separators>
* separators = "(" | ")" | "<" | ">" | "@"
* | "," | ";" | ":" | "\" | <">
* | "/" | "[" | "]" | "?" | "="
* | "{" | "}" | SP | HT
* quoted-string = ( <"> *(qdtext | quoted-pair ) <"> )
* qdtext = <any TEXT except <">>
* quoted-pair = "\" CHAR
* CHAR = <any US-ASCII character (octets 0 - 127)>
* TEXT = <any OCTET except CTLs, but including LWS>
* LWS = [CRLF] 1*( SP | HT )
* CRLF = CR LF
* CR = <US-ASCII CR, carriage return (13)>
* LF = <US-ASCII LF, linefeed (10)>
* SP = <US-ASCII SP, space (32)>
* SHT = <US-ASCII HT, horizontal-tab (9)>
* CTL = <any US-ASCII control character (octets 0 - 31) and DEL (127)>
* OCTET = <any 8-bit sequence of data>
*/
var paramRegExp = /; *([!#$%&'\*\+\-\.0-9A-Z\^_`a-z\|~]+) *= *("(?:[ !\u0023-\u005b\u005d-\u007e\u0080-\u00ff]|\\[\u0020-\u007e])*"|[!#$%&'\*\+\-\.0-9A-Z\^_`a-z\|~]+) */g;
var textRegExp = /^[\u0020-\u007e\u0080-\u00ff]+$/
var tokenRegExp = /^[!#$%&'\*\+\-\.0-9A-Z\^_`a-z\|~]+$/
/**
* RegExp to match quoted-pair in RFC 2616
*
* quoted-pair = "\" CHAR
* CHAR = <any US-ASCII character (octets 0 - 127)>
*/
var qescRegExp = /\\([\u0000-\u007f])/g;
/**
* RegExp to match chars that must be quoted-pair in RFC 2616
*/
var quoteRegExp = /([\\"])/g;
/**
* RegExp to match type in RFC 6838
*
* type-name = restricted-name
* subtype-name = restricted-name
* restricted-name = restricted-name-first *126restricted-name-chars
* restricted-name-first = ALPHA / DIGIT
* restricted-name-chars = ALPHA / DIGIT / "!" / "#" /
* "$" / "&" / "-" / "^" / "_"
* restricted-name-chars =/ "." ; Characters before first dot always
* ; specify a facet name
* restricted-name-chars =/ "+" ; Characters after last plus always
* ; specify a structured syntax suffix
* ALPHA = %x41-5A / %x61-7A ; A-Z / a-z
* DIGIT = %x30-39 ; 0-9
*/
var subtypeNameRegExp = /^[A-Za-z0-9][A-Za-z0-9!#$&^_.-]{0,126}$/
var typeNameRegExp = /^[A-Za-z0-9][A-Za-z0-9!#$&^_-]{0,126}$/
var typeRegExp = /^ *([A-Za-z0-9][A-Za-z0-9!#$&^_-]{0,126})\/([A-Za-z0-9][A-Za-z0-9!#$&^_.+-]{0,126}) *$/;
/**
* Module exports.
*/
exports.format = format
exports.parse = parse
/**
* Format object to media type.
*
* @param {object} obj
* @return {string}
* @api public
*/
function format(obj) {
if (!obj || typeof obj !== 'object') {
throw new TypeError('argument obj is required')
}
var parameters = obj.parameters
var subtype = obj.subtype
var suffix = obj.suffix
var type = obj.type
if (!type || !typeNameRegExp.test(type)) {
throw new TypeError('invalid type')
}
if (!subtype || !subtypeNameRegExp.test(subtype)) {
throw new TypeError('invalid subtype')
}
// format as type/subtype
var string = type + '/' + subtype
// append +suffix
if (suffix) {
if (!typeNameRegExp.test(suffix)) {
throw new TypeError('invalid suffix')
}
string += '+' + suffix
}
// append parameters
if (parameters && typeof parameters === 'object') {
var param
var params = Object.keys(parameters).sort()
for (var i = 0; i < params.length; i++) {
param = params[i]
if (!tokenRegExp.test(param)) {
throw new TypeError('invalid parameter name')
}
string += '; ' + param + '=' + qstring(parameters[param])
}
}
return string
}
/**
* Parse media type to object.
*
* @param {string|object} string
* @return {Object}
* @api public
*/
function parse(string) {
if (!string) {
throw new TypeError('argument string is required')
}
// support req/res-like objects as argument
if (typeof string === 'object') {
string = getcontenttype(string)
}
if (typeof string !== 'string') {
throw new TypeError('argument string is required to be a string')
}
var index = string.indexOf(';')
var type = index !== -1
? string.substr(0, index)
: string
var key
var match
var obj = splitType(type)
var params = {}
var value
paramRegExp.lastIndex = index
while (match = paramRegExp.exec(string)) {
if (match.index !== index) {
throw new TypeError('invalid parameter format')
}
index += match[0].length
key = match[1].toLowerCase()
value = match[2]
if (value[0] === '"') {
// remove quotes and escapes
value = value
.substr(1, value.length - 2)
.replace(qescRegExp, '$1')
}
params[key] = value
}
if (index !== -1 && index !== string.length) {
throw new TypeError('invalid parameter format')
}
obj.parameters = params
return obj
}
/**
* Get content-type from req/res objects.
*
* @param {object}
* @return {Object}
* @api private
*/
function getcontenttype(obj) {
if (typeof obj.getHeader === 'function') {
// res-like
return obj.getHeader('content-type')
}
if (typeof obj.headers === 'object') {
// req-like
return obj.headers && obj.headers['content-type']
}
}
/**
* Quote a string if necessary.
*
* @param {string} val
* @return {string}
* @api private
*/
function qstring(val) {
var str = String(val)
// no need to quote tokens
if (tokenRegExp.test(str)) {
return str
}
if (str.length > 0 && !textRegExp.test(str)) {
throw new TypeError('invalid parameter value')
}
return '"' + str.replace(quoteRegExp, '\\$1') + '"'
}
/**
* Simply "type/subtype+siffx" into parts.
*
* @param {string} string
* @return {Object}
* @api private
*/
function splitType(string) {
var match = typeRegExp.exec(string.toLowerCase())
if (!match) {
throw new TypeError('invalid media type')
}
var type = match[1]
var subtype = match[2]
var suffix
// suffix after last +
var index = subtype.lastIndexOf('+')
if (index !== -1) {
suffix = subtype.substr(index + 1)
subtype = subtype.substr(0, index)
}
var obj = {
type: type,
subtype: subtype,
suffix: suffix
}
return obj
}
(The MIT License)
Copyright (c) 2014 Douglas Christopher Wilson
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
{
"name": "media-typer",
"description": "Simple RFC 6838 media type parser and formatter",
"version": "0.3.0",
"author": {
"name": "Douglas Christopher Wilson",
"email": "doug@somethingdoug.com"
},
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/jshttp/media-typer"
},
"devDependencies": {
"istanbul": "0.3.2",
"mocha": "~1.21.4",
"should": "~4.0.4"
},
"files": [
"LICENSE",
"HISTORY.md",
"index.js"
],
"engines": {
"node": ">= 0.6"
},
"scripts": {
"test": "mocha --reporter spec --check-leaks --bail test/",
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/"
},
"gitHead": "d49d41ffd0bb5a0655fa44a59df2ec0bfc835b16",
"bugs": {
"url": "https://github.com/jshttp/media-typer/issues"
},
"homepage": "https://github.com/jshttp/media-typer",
"_id": "media-typer@0.3.0",
"_shasum": "8710d7af0aa626f8fffa1ce00168545263255748",
"_from": "media-typer@0.3.0",
"_npmVersion": "1.4.21",
"_npmUser": {
"name": "dougwilson",
"email": "doug@somethingdoug.com"
},
"maintainers": [
{
"name": "dougwilson",
"email": "doug@somethingdoug.com"
}
],
"dist": {
"shasum": "8710d7af0aa626f8fffa1ce00168545263255748",
"tarball": "http://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz"
},
"directories": {},
"_resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
"readme": "ERROR: No README data found!"
}

media-typer

NPM Version NPM Downloads Node.js Version Build Status Test Coverage

Simple RFC 6838 media type parser

Installation

$ npm install media-typer

API

var typer = require('media-typer')

typer.parse(string)

var obj = typer.parse('image/svg+xml; charset=utf-8')

Parse a media type string. This will return an object with the following properties (examples are shown for the string 'image/svg+xml; charset=utf-8'):

  • type: The type of the media type (always lower case). Example: 'image'

  • subtype: The subtype of the media type (always lower case). Example: 'svg'

  • suffix: The suffix of the media type (always lower case). Example: 'xml'

  • parameters: An object of the parameters in the media type (name of parameter always lower case). Example: {charset: 'utf-8'}

typer.parse(req)

var obj = typer.parse(req)

Parse the content-type header from the given req. Short-cut for typer.parse(req.headers['content-type']).

typer.parse(res)

var obj = typer.parse(res)

Parse the content-type header set on the given res. Short-cut for typer.parse(res.getHeader('content-type')).

typer.format(obj)

var obj = typer.format({type: 'image', subtype: 'svg', suffix: 'xml'})

Format an object into a media type string. This will return a string of the mime type for the given object. For the properties of the object, see the documentation for typer.parse(string).

License

MIT

2.0.10 / 2015-03-13

  • deps: mime-db@~1.8.0
    • Add new mime types

2.0.9 / 2015-02-09

  • deps: mime-db@~1.7.0
    • Add new mime types
    • Community extensions ownership transferred from node-mime

2.0.8 / 2015-01-29

  • deps: mime-db@~1.6.0
    • Add new mime types

2.0.7 / 2014-12-30

  • deps: mime-db@~1.5.0
    • Add new mime types
    • Fix various invalid MIME type entries

2.0.6 / 2014-12-30

  • deps: mime-db@~1.4.0
    • Add new mime types
    • Fix various invalid MIME type entries
    • Remove example template MIME types

2.0.5 / 2014-12-29

  • deps: mime-db@~1.3.1
    • Fix missing extensions

2.0.4 / 2014-12-10

  • deps: mime-db@~1.3.0
    • Add new mime types

2.0.3 / 2014-11-09

  • deps: mime-db@~1.2.0
    • Add new mime types

2.0.2 / 2014-09-28

  • deps: mime-db@~1.1.0
    • Add new mime types
    • Add additional compressible
    • Update charsets

2.0.1 / 2014-09-07

  • Support Node.js 0.6

2.0.0 / 2014-09-02

  • Use mime-db
  • Remove .define()

1.0.2 / 2014-08-04

  • Set charset=utf-8 for text/javascript

1.0.1 / 2014-06-24

  • Add text/jsx type

1.0.0 / 2014-05-12

  • Return false for unknown types
  • Set charset=utf-8 for application/json

0.1.0 / 2014-05-02

  • Initial release
var db = require('mime-db')
// types[extension] = type
exports.types = Object.create(null)
// extensions[type] = [extensions]
exports.extensions = Object.create(null)
Object.keys(db).forEach(function (name) {
var mime = db[name]
var exts = mime.extensions
if (!exts || !exts.length) return
exports.extensions[name] = exts
exts.forEach(function (ext) {
exports.types[ext] = name
})
})
exports.lookup = function (string) {
if (!string || typeof string !== "string") return false
// remove any leading paths, though we should just use path.basename
string = string.replace(/.*[\.\/\\]/, '').toLowerCase()
if (!string) return false
return exports.types[string] || false
}
exports.extension = function (type) {
if (!type || typeof type !== "string") return false
// to do: use media-typer
type = type.match(/^\s*([^;\s]*)(?:;|\s|$)/)
if (!type) return false
var exts = exports.extensions[type[1].toLowerCase()]
if (!exts || !exts.length) return false
return exts[0]
}
// type has to be an exact mime type
exports.charset = function (type) {
var mime = db[type]
if (mime && mime.charset) return mime.charset
// default text/* to utf-8
if (/^text\//.test(type)) return 'UTF-8'
return false
}
// backwards compatibility
exports.charsets = {
lookup: exports.charset
}
// to do: maybe use set-type module or something
exports.contentType = function (type) {
if (!type || typeof type !== "string") return false
if (!~type.indexOf('/')) type = exports.lookup(type)
if (!type) return false
if (!~type.indexOf('charset')) {
var charset = exports.charset(type)
if (charset) type += '; charset=' + charset.toLowerCase()
}
return type
}
The MIT License (MIT)
Copyright (c) 2014 Jonathan Ong me@jongleberry.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

1.8.0 / 2015-03-13

  • Add application/vnd.citationstyles.style+xml
  • Add application/vnd.fastcopy-disk-image
  • Add application/vnd.gov.sk.xmldatacontainer+xml
  • Add extension .jsonld to application/ld+json

1.7.0 / 2015-02-08

  • Add application/vnd.gerber
  • Add application/vnd.msa-disk-image

1.6.1 / 2015-02-05

  • Community extensions ownership transferred from node-mime

1.6.0 / 2015-01-29

  • Add application/jose
  • Add application/jose+json
  • Add application/json-seq
  • Add application/jwk+json
  • Add application/jwk-set+json
  • Add application/jwt
  • Add application/rdap+json
  • Add application/vnd.gov.sk.e-form+xml
  • Add application/vnd.ims.imsccv1p3

1.5.0 / 2014-12-30

  • Add application/vnd.oracle.resource+json
  • Fix various invalid MIME type entries
    • application/mbox+xml
    • application/oscp-response
    • application/vwg-multiplexed
    • audio/g721

1.4.0 / 2014-12-21

  • Add application/vnd.ims.imsccv1p2
  • Fix various invalid MIME type entries
    • application/vnd-acucobol
    • application/vnd-curl
    • application/vnd-dart
    • application/vnd-dxr
    • application/vnd-fdf
    • application/vnd-mif
    • application/vnd-sema
    • application/vnd-wap-wmlc
    • application/vnd.adobe.flash-movie
    • application/vnd.dece-zip
    • application/vnd.dvb_service
    • application/vnd.micrografx-igx
    • application/vnd.sealed-doc
    • application/vnd.sealed-eml
    • application/vnd.sealed-mht
    • application/vnd.sealed-ppt
    • application/vnd.sealed-tiff
    • application/vnd.sealed-xls
    • application/vnd.sealedmedia.softseal-html
    • application/vnd.sealedmedia.softseal-pdf
    • application/vnd.wap-slc
    • application/vnd.wap-wbxml
    • audio/vnd.sealedmedia.softseal-mpeg
    • image/vnd-djvu
    • image/vnd-svf
    • image/vnd-wap-wbmp
    • image/vnd.sealed-png
    • image/vnd.sealedmedia.softseal-gif
    • image/vnd.sealedmedia.softseal-jpg
    • model/vnd-dwf
    • model/vnd.parasolid.transmit-binary
    • model/vnd.parasolid.transmit-text
    • text/vnd-a
    • text/vnd-curl
    • text/vnd.wap-wml
  • Remove example template MIME types
    • application/example
    • audio/example
    • image/example
    • message/example
    • model/example
    • multipart/example
    • text/example
    • video/example

1.3.1 / 2014-12-16

  • Fix missing extensions
    • application/json5
    • text/hjson

1.3.0 / 2014-12-07

  • Add application/a2l
  • Add application/aml
  • Add application/atfx
  • Add application/atxml
  • Add application/cdfx+xml
  • Add application/dii
  • Add application/json5
  • Add application/lxf
  • Add application/mf4
  • Add application/vnd.apache.thrift.compact
  • Add application/vnd.apache.thrift.json
  • Add application/vnd.coffeescript
  • Add application/vnd.enphase.envoy
  • Add application/vnd.ims.imsccv1p1
  • Add text/csv-schema
  • Add text/hjson
  • Add text/markdown
  • Add text/yaml

1.2.0 / 2014-11-09

  • Add application/cea
  • Add application/dit
  • Add application/vnd.gov.sk.e-form+zip
  • Add application/vnd.tmd.mediaflex.api+xml
  • Type application/epub+zip is now IANA-registered

1.1.2 / 2014-10-23

  • Rebuild database for application/x-www-form-urlencoded change

1.1.1 / 2014-10-20

  • Mark application/x-www-form-urlencoded as compressible.

1.1.0 / 2014-09-28

  • Add application/font-woff2

1.0.3 / 2014-09-25

  • Fix engine requirement in package

1.0.2 / 2014-09-25

  • Add application/coap-group+json
  • Add application/dcd
  • Add application/vnd.apache.thrift.binary
  • Add image/vnd.tencent.tap
  • Mark all JSON-derived types as compressible
  • Update text/vtt data

1.0.1 / 2014-08-30

  • Fix extension ordering

1.0.0 / 2014-08-30

  • Add application/atf
  • Add application/merge-patch+json
  • Add multipart/x-mixed-replace
  • Add source: 'apache' metadata
  • Add source: 'iana' metadata
  • Remove badly-assumed charset data
The MIT License (MIT)
Copyright (c) 2014 Jonathan Ong me@jongleberry.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

mime-db

NPM Version NPM Downloads Node.js Version Build Status Coverage Status

This is a database of all mime types. It consists of a single, public JSON file and does not include any logic, allowing it to remain as un-opinionated as possible with an API. It aggregates data from the following sources:

Installation

npm install mime-db

If you're crazy enough to use this in the browser, you can just grab the JSON file:

https://cdn.rawgit.com/jshttp/mime-db/master/db.json

Usage

var db = require('mime-db');

// grab data on .js files
var data = db['application/javascript'];

Data Structure

The JSON file is a map lookup for lowercased mime types. Each mime type has the following properties:

  • .source - where the mime type is defined. If not set, it's probably a custom media type.
  • .extensions[] - known extensions associated with this mime type.
  • .compressible - whether a file of this type is can be gzipped.
  • .charset - the default charset associated with this type, if any.

If unknown, every property could be undefined.

Contributing

To edit the database, only make PRs against src/custom.json or src/custom-suffix.json.

To update the build, run npm run update.

Adding Custom Media Types

The best way to get new media types included in this library is to register them with the IANA. The community registration procedure is outlined in RFC 6838 section 5. Types registered with the IANA are automatically pulled into this library.

mime-types

NPM Version NPM Downloads Node.js Version Build Status Test Coverage

The ultimate javascript content-type utility.

Similar to node-mime, except:

  • No fallbacks. Instead of naively returning the first available type, mime-types simply returns false, so do var type = mime.lookup('unrecognized') || 'application/octet-stream'.
  • No new Mime() business, so you could do var lookup = require('mime-types').lookup.
  • Additional mime types are added such as jade and stylus via mime-db
  • No .define() functionality

Otherwise, the API is compatible.

Install

$ npm install mime-types

Adding Types

All mime types are based on mime-db, so open a PR there if you'd like to add mime types.

API

var mime = require('mime-types')

All functions return false if input is invalid or not found.

mime.lookup(path)

Lookup the content-type associated with a file.

mime.lookup('json')           // 'application/json'
mime.lookup('.md')            // 'text/x-markdown'
mime.lookup('file.html')      // 'text/html'
mime.lookup('folder/file.js') // 'application/javascript'

mime.lookup('cats') // false

mime.contentType(type)

Create a full content-type header given a content-type or extension.

mime.contentType('markdown')  // 'text/x-markdown; charset=utf-8'
mime.contentType('file.json') // 'application/json; charset=utf-8'

// from a full path
mime.contentType(path.extname('/path/to/file.json')) // 'application/json; charset=utf-8'

mime.extension(type)

Get the default extension for a content-type.

mime.extension('application/octet-stream') // 'bin'

mime.charset(type)

Lookup the implied default charset of a content-type.

mime.charset('text/x-markdown') // 'UTF-8'

var type = mime.types[extension]

A map of content-types by extension.

[extensions...] = mime.extensions[type]

A map of extensions by content-type.

License

MIT

type-is

NPM Version NPM Downloads Node.js Version Build Status Test Coverage

Infer the content-type of a request.

Install

$ npm install type-is

API

var http = require('http')
var is   = require('type-is')

http.createServer(function (req, res) {
  var istext = is(req, ['text/*'])
  res.end('you ' + (istext ? 'sent' : 'did not send') + ' me text')
})

type = is(request, types)

request is the node HTTP request. types is an array of types.

// req.headers.content-type = 'application/json'

is(req, ['json'])             // 'json'
is(req, ['html', 'json'])     // 'json'
is(req, ['application/*'])    // 'application/json'
is(req, ['application/json']) // 'application/json'

is(req, ['html']) // false

type = is.is(mediaType, types)

mediaType is the media type string. types is an array of types.

var mediaType = 'application/json'

is.is(mediaType, ['json'])             // 'json'
is.is(mediaType, ['html', 'json'])     // 'json'
is.is(mediaType, ['application/*'])    // 'application/json'
is.is(mediaType, ['application/json']) // 'application/json'

is.is(mediaType, ['html']) // false

Each type can be:

  • An extension name such as json. This name will be returned if matched.
  • A mime type such as application/json.
  • A mime type with a wildcard such as */* or */json or application/*. The full mime type will be returned if matched.
  • A suffix such as +json. This can be combined with a wildcard such as */vnd+json or application/*+json. The full mime type will be returned if matched.

false will be returned if no type matches.

null will be returned if the request does not have a body.

Examples

Example body parser

var is = require('type-is');

function bodyParser(req, res, next) {
  if (!is.hasBody(req)) {
    return next()
  }

  switch (is(req, ['urlencoded', 'json', 'multipart'])) {
    case 'urlencoded':
      // parse urlencoded body
      throw new Error('implement urlencoded body parsing')
      break
    case 'json':
      // parse json body
      throw new Error('implement json body parsing')
      break
    case 'multipart':
      // parse multipart body
      throw new Error('implement multipart body parsing')
      break
    default:
      // 415 error code
      res.statusCode = 415
      res.end()
      return
  }
}

License

MIT

Express Logo

Fast, unopinionated, minimalist web framework for node.

NPM Version NPM Downloads Linux Build Windows Build Test Coverage

var express = require('express')
var app = express()

app.get('/', function (req, res) {
  res.send('Hello World')
})

app.listen(3000)

Installation

$ npm install express

Features

  • Robust routing
  • Focus on high performance
  • Super-high test coverage
  • HTTP helpers (redirection, caching, etc)
  • View system supporting 14+ template engines
  • Content negotiation
  • Executable for generating applications quickly

Docs & Community

PROTIP Be sure to read Migrating from 3.x to 4.x as well as New features in 4.x.

Quick Start

The quickest way to get started with express is to utilize the executable express(1) to generate an application as shown below:

Install the executable. The executable's major version will match Express's:

$ npm install -g express-generator@4

Create the app:

$ express /tmp/foo && cd /tmp/foo

Install dependencies:

$ npm install

Start the server:

$ npm start

Philosophy

The Express philosophy is to provide small, robust tooling for HTTP servers, making it a great solution for single page applications, web sites, hybrids, or public HTTP APIs.

Express does not force you to use any specific ORM or template engine. With support for over 14 template engines via Consolidate.js, you can quickly craft your perfect framework.

Examples

To view the examples, clone the Express repo and install the dependancies:

$ git clone git://github.com/strongloop/express.git --depth 1
$ cd express
$ npm install

Then run whichever example you want:

$ node examples/content-negotiation

Tests

To run the test suite, first install the dependencies, then run npm test:

$ npm install
$ npm test

People

The original author of Express is TJ Holowaychuk TJ's Gratipay

The current lead maintainer is Douglas Christopher Wilson Doug's Gratipay

List of all contributors

License

MIT

This file has been truncated, but you can view the full file.
{
"application/1d-interleaved-parityfec": {
"source": "iana"
},
"application/3gpdash-qoe-report+xml": {
"source": "iana"
},
"application/3gpp-ims+xml": {
"source": "iana"
},
"application/a2l": {
"source": "iana"
},
"application/activemessage": {
"source": "iana"
},
"application/alto-costmap+json": {
"source": "iana",
"compressible": true
},
"application/alto-costmapfilter+json": {
"source": "iana",
"compressible": true
},
"application/alto-directory+json": {
"source": "iana",
"compressible": true
},
"application/alto-endpointcost+json": {
"source": "iana",
"compressible": true
},
"application/alto-endpointcostparams+json": {
"source": "iana",
"compressible": true
},
"application/alto-endpointprop+json": {
"source": "iana",
"compressible": true
},
"application/alto-endpointpropparams+json": {
"source": "iana",
"compressible": true
},
"application/alto-error+json": {
"source": "iana",
"compressible": true
},
"application/alto-networkmap+json": {
"source": "iana",
"compressible": true
},
"application/alto-networkmapfilter+json": {
"source": "iana",
"compressible": true
},
"application/aml": {
"source": "iana"
},
"application/andrew-inset": {
"source": "iana",
"extensions": ["ez"]
},
"application/applefile": {
"source": "iana"
},
"application/applixware": {
"source": "apache",
"extensions": ["aw"]
},
"application/atf": {
"source": "iana"
},
"application/atfx": {
"source": "iana"
},
"application/atom+xml": {
"source": "iana",
"compressible": true,
"extensions": ["atom"]
},
"application/atomcat+xml": {
"source": "iana",
"extensions": ["atomcat"]
},
"application/atomdeleted+xml": {
"source": "iana"
},
"application/atomicmail": {
"source": "iana"
},
"application/atomsvc+xml": {
"source": "iana",
"extensions": ["atomsvc"]
},
"application/atxml": {
"source": "iana"
},
"application/auth-policy+xml": {
"source": "iana"
},
"application/bacnet-xdd+zip": {
"source": "iana"
},
"application/batch-smtp": {
"source": "iana"
},
"application/beep+xml": {
"source": "iana"
},
"application/calendar+json": {
"source": "iana",
"compressible": true
},
"application/calendar+xml": {
"source": "iana"
},
"application/call-completion": {
"source": "iana"
},
"application/cals-1840": {
"source": "iana"
},
"application/cbor": {
"source": "iana"
},
"application/ccmp+xml": {
"source": "iana"
},
"application/ccxml+xml": {
"source": "iana",
"extensions": ["ccxml"]
},
"application/cdfx+xml": {
"source": "iana"
},
"application/cdmi-capability": {
"source": "iana",
"extensions": ["cdmia"]
},
"application/cdmi-container": {
"source": "iana",
"extensions": ["cdmic"]
},
"application/cdmi-domain": {
"source": "iana",
"extensions": ["cdmid"]
},
"application/cdmi-object": {
"source": "iana",
"extensions": ["cdmio"]
},
"application/cdmi-queue": {
"source": "iana",
"extensions": ["cdmiq"]
},
"application/cea": {
"source": "iana"
},
"application/cea-2018+xml": {
"source": "iana"
},
"application/cellml+xml": {
"source": "iana"
},
"application/cfw": {
"source": "iana"
},
"application/cms": {
"source": "iana"
},
"application/cnrp+xml": {
"source": "iana"
},
"application/coap-group+json": {
"source": "iana",
"compressible": true
},
"application/commonground": {
"source": "iana"
},
"application/conference-info+xml": {
"source": "iana"
},
"application/cpl+xml": {
"source": "iana"
},
"application/csrattrs": {
"source": "iana"
},
"application/csta+xml": {
"source": "iana"
},
"application/cstadata+xml": {
"source": "iana"
},
"application/cu-seeme": {
"source": "apache",
"extensions": ["cu"]
},
"application/cybercash": {
"source": "iana"
},
"application/dart": {
"compressible": true
},
"application/dash+xml": {
"source": "iana",
"extensions": ["mdp"]
},
"application/dashdelta": {
"source": "iana"
},
"application/davmount+xml": {
"source": "iana",
"extensions": ["davmount"]
},
"application/dca-rft": {
"source": "iana"
},
"application/dcd": {
"source": "iana"
},
"application/dec-dx": {
"source": "iana"
},
"application/dialog-info+xml": {
"source": "iana"
},
"application/dicom": {
"source": "iana"
},
"application/dii": {
"source": "iana"
},
"application/dit": {
"source": "iana"
},
"application/dns": {
"source": "iana"
},
"application/docbook+xml": {
"source": "apache",
"extensions": ["dbk"]
},
"application/dskpp+xml": {
"source": "iana"
},
"application/dssc+der": {
"source": "iana",
"extensions": ["dssc"]
},
"application/dssc+xml": {
"source": "iana",
"extensions": ["xdssc"]
},
"application/dvcs": {
"source": "iana"
},
"application/ecmascript": {
"source": "iana",
"compressible": true,
"extensions": ["ecma"]
},
"application/edi-consent": {
"source": "iana"
},
"application/edi-x12": {
"source": "iana",
"compressible": false
},
"application/edifact": {
"source": "iana",
"compressible": false
},
"application/emma+xml": {
"source": "iana",
"extensions": ["emma"]
},
"application/emotionml+xml": {
"source": "iana"
},
"application/encaprtp": {
"source": "iana"
},
"application/epp+xml": {
"source": "iana"
},
"application/epub+zip": {
"source": "iana",
"extensions": ["epub"]
},
"application/eshop": {
"source": "iana"
},
"application/exi": {
"source": "iana",
"extensions": ["exi"]
},
"application/fastinfoset": {
"source": "iana"
},
"application/fastsoap": {
"source": "iana"
},
"application/fdt+xml": {
"source": "iana"
},
"application/fits": {
"source": "iana"
},
"application/font-sfnt": {
"source": "iana"
},
"application/font-tdpfr": {
"source": "iana",
"extensions": ["pfr"]
},
"application/font-woff": {
"source": "iana",
"compressible": false,
"extensions": ["woff"]
},
"application/font-woff2": {
"compressible": false,
"extensions": ["woff2"]
},
"application/framework-attributes+xml": {
"source": "iana"
},
"application/gml+xml": {
"source": "apache",
"extensions": ["gml"]
},
"application/gpx+xml": {
"source": "apache",
"extensions": ["gpx"]
},
"application/gxf": {
"source": "apache",
"extensions": ["gxf"]
},
"application/gzip": {
"source": "iana",
"compressible": false
},
"application/h224": {
"source": "iana"
},
"application/held+xml": {
"source": "iana"
},
"application/http": {
"source": "iana"
},
"application/hyperstudio": {
"source": "iana",
"extensions": ["stk"]
},
"application/ibe-key-request+xml": {
"source": "iana"
},
"application/ibe-pkg-reply+xml": {
"source": "iana"
},
"application/ibe-pp-data": {
"source": "iana"
},
"application/iges": {
"source": "iana"
},
"application/im-iscomposing+xml": {
"source": "iana"
},
"application/index": {
"source": "iana"
},
"application/index.cmd": {
"source": "iana"
},
"application/index.obj": {
"source": "iana"
},
"application/index.response": {
"source": "iana"
},
"application/index.vnd": {
"source": "iana"
},
"application/inkml+xml": {
"source": "iana",
"extensions": ["ink","inkml"]
},
"application/iotp": {
"source": "iana"
},
"application/ipfix": {
"source": "iana",
"extensions": ["ipfix"]
},
"application/ipp": {
"source": "iana"
},
"application/isup": {
"source": "iana"
},
"application/its+xml": {
"source": "iana"
},
"application/java-archive": {
"source": "apache",
"compressible": false,
"extensions": ["jar"]
},
"application/java-serialized-object": {
"source": "apache",
"compressible": false,
"extensions": ["ser"]
},
"application/java-vm": {
"source": "apache",
"compressible": false,
"extensions": ["class"]
},
"application/javascript": {
"source": "iana",
"charset": "UTF-8",
"compressible": true,
"extensions": ["js"]
},
"application/jose": {
"source": "iana"
},
"application/jose+json": {
"source": "iana",
"compressible": true
},
"application/jrd+json": {
"source": "iana",
"compressible": true
},
"application/json": {
"source": "iana",
"charset": "UTF-8",
"compressible": true,
"extensions": ["json","map"]
},
"application/json-patch+json": {
"source": "iana",
"compressible": true
},
"application/json-seq": {
"source": "iana"
},
"application/json5": {
"extensions": ["json5"]
},
"application/jsonml+json": {
"source": "apache",
"compressible": true,
"extensions": ["jsonml"]
},
"application/jwk+json": {
"source": "iana",
"compressible": true
},
"application/jwk-set+json": {
"source": "iana",
"compressible": true
},
"application/jwt": {
"source": "iana"
},
"application/kpml-request+xml": {
"source": "iana"
},
"application/kpml-response+xml": {
"source": "iana"
},
"application/ld+json": {
"source": "iana",
"compressible": true,
"extensions": ["jsonld"]
},
"application/link-format": {
"source": "iana"
},
"application/load-control+xml": {
"source": "iana"
},
"application/lost+xml": {
"source": "iana",
"extensions": ["lostxml"]
},
"application/lostsync+xml": {
"source": "iana"
},
"application/lxf": {
"source": "iana"
},
"application/mac-binhex40": {
"source": "iana",
"extensions": ["hqx"]
},
"application/mac-compactpro": {
"source": "apache",
"extensions": ["cpt"]
},
"application/macwriteii": {
"source": "iana"
},
"application/mads+xml": {
"source": "iana",
"extensions": ["mads"]
},
"application/marc": {
"source": "iana",
"extensions": ["mrc"]
},
"application/marcxml+xml": {
"source": "iana",
"extensions": ["mrcx"]
},
"application/mathematica": {
"source": "iana",
"extensions": ["ma","nb","mb"]
},
"application/mathml+xml": {
"source": "iana",
"extensions": ["mathml"]
},
"application/mathml-content+xml": {
"source": "iana"
},
"application/mathml-presentation+xml": {
"source": "iana"
},
"application/mbms-associated-procedure-description+xml": {
"source": "iana"
},
"application/mbms-deregister+xml": {
"source": "iana"
},
"application/mbms-envelope+xml": {
"source": "iana"
},
"application/mbms-msk+xml": {
"source": "iana"
},
"application/mbms-msk-response+xml": {
"source": "iana"
},
"application/mbms-protection-description+xml": {
"source": "iana"
},
"application/mbms-reception-report+xml": {
"source": "iana"
},
"application/mbms-register+xml": {
"source": "iana"
},
"application/mbms-register-response+xml": {
"source": "iana"
},
"application/mbms-schedule+xml": {
"source": "iana"
},
"application/mbms-user-service-description+xml": {
"source": "iana"
},
"application/mbox": {
"source": "iana",
"extensions": ["mbox"]
},
"application/media-policy-dataset+xml": {
"source": "iana"
},
"application/media_control+xml": {
"source": "iana"
},
"application/mediaservercontrol+xml": {
"source": "iana",
"extensions": ["mscml"]
},
"application/merge-patch+json": {
"source": "iana",
"compressible": true
},
"application/metalink+xml": {
"source": "apache",
"extensions": ["metalink"]
},
"application/metalink4+xml": {
"source": "iana",
"extensions": ["meta4"]
},
"application/mets+xml": {
"source": "iana",
"extensions": ["mets"]
},
"application/mf4": {
"source": "iana"
},
"application/mikey": {
"source": "iana"
},
"application/mods+xml": {
"source": "iana",
"extensions": ["mods"]
},
"application/moss-keys": {
"source": "iana"
},
"application/moss-signature": {
"source": "iana"
},
"application/mosskey-data": {
"source": "iana"
},
"application/mosskey-request": {
"source": "iana"
},
"application/mp21": {
"source": "iana",
"extensions": ["m21","mp21"]
},
"application/mp4": {
"source": "iana",
"extensions": ["mp4s","m4p"]
},
"application/mpeg4-generic": {
"source": "iana"
},
"application/mpeg4-iod": {
"source": "iana"
},
"application/mpeg4-iod-xmt": {
"source": "iana"
},
"application/mrb-consumer+xml": {
"source": "iana"
},
"application/mrb-publish+xml": {
"source": "iana"
},
"application/msc-ivr+xml": {
"source": "iana"
},
"application/msc-mixer+xml": {
"source": "iana"
},
"application/msword": {
"source": "iana",
"compressible": false,
"extensions": ["doc","dot"]
},
"application/mxf": {
"source": "iana",
"extensions": ["mxf"]
},
"application/nasdata": {
"source": "iana"
},
"application/news-checkgroups": {
"source": "iana"
},
"application/news-groupinfo": {
"source": "iana"
},
"application/news-transmission": {
"source": "iana"
},
"application/nlsml+xml": {
"source": "iana"
},
"application/nss": {
"source": "iana"
},
"application/ocsp-request": {
"source": "iana"
},
"application/ocsp-response": {
"source": "iana"
},
"application/octet-stream": {
"source": "iana",
"compressible": false,
"extensions": ["bin","dms","lrf","mar","so","dist","distz","pkg","bpk","dump","elc","deploy","buffer"]
},
"application/oda": {
"source": "iana",
"extensions": ["oda"]
},
"application/odx": {
"source": "iana"
},
"application/oebps-package+xml": {
"source": "iana",
"extensions": ["opf"]
},
"application/ogg": {
"source": "iana",
"compressible": false,
"extensions": ["ogx"]
},
"application/omdoc+xml": {
"source": "apache",
"extensions": ["omdoc"]
},
"application/onenote": {
"source": "apache",
"extensions": ["onetoc","onetoc2","onetmp","onepkg"]
},
"application/oxps": {
"source": "iana",
"extensions": ["oxps"]
},
"application/p2p-overlay+xml": {
"source": "iana"
},
"application/parityfec": {
"source": "iana"
},
"application/patch-ops-error+xml": {
"source": "iana",
"extensions": ["xer"]
},
"application/pdf": {
"source": "iana",
"compressible": false,
"extensions": ["pdf"]
},
"application/pdx": {
"source": "iana"
},
"application/pgp-encrypted": {
"source": "iana",
"compressible": false,
"extensions": ["pgp"]
},
"application/pgp-keys": {
"source": "iana"
},
"application/pgp-signature": {
"source": "iana",
"extensions": ["asc","sig"]
},
"application/pics-rules": {
"source": "apache",
"extensions": ["prf"]
},
"application/pidf+xml": {
"source": "iana"
},
"application/pidf-diff+xml": {
"source": "iana"
},
"application/pkcs10": {
"source": "iana",
"extensions": ["p10"]
},
"application/pkcs7-mime": {
"source": "iana",
"extensions": ["p7m","p7c"]
},
"application/pkcs7-signature": {
"source": "iana",
"extensions": ["p7s"]
},
"application/pkcs8": {
"source": "iana",
"extensions": ["p8"]
},
"application/pkix-attr-cert": {
"source": "iana",
"extensions": ["ac"]
},
"application/pkix-cert": {
"source": "iana",
"extensions": ["cer"]
},
"application/pkix-crl": {
"source": "iana",
"extensions": ["crl"]
},
"application/pkix-pkipath": {
"source": "iana",
"extensions": ["pkipath"]
},
"application/pkixcmp": {
"source": "iana",
"extensions": ["pki"]
},
"application/pls+xml": {
"source": "iana",
"extensions": ["pls"]
},
"application/poc-settings+xml": {
"source": "iana"
},
"application/postscript": {
"source": "iana",
"compressible": true,
"extensions": ["ai","eps","ps"]
},
"application/provenance+xml": {
"source": "iana"
},
"application/prs.alvestrand.titrax-sheet": {
"source": "iana"
},
"application/prs.cww": {
"source": "iana",
"extensions": ["cww"]
},
"application/prs.hpub+zip": {
"source": "iana"
},
"application/prs.nprend": {
"source": "iana"
},
"application/prs.plucker": {
"source": "iana"
},
"application/prs.rdf-xml-crypt": {
"source": "iana"
},
"application/prs.xsf+xml": {
"source": "iana"
},
"application/pskc+xml": {
"source": "iana",
"extensions": ["pskcxml"]
},
"application/qsig": {
"source": "iana"
},
"application/raptorfec": {
"source": "iana"
},
"application/rdap+json": {
"source": "iana",
"compressible": true
},
"application/rdf+xml": {
"source": "iana",
"compressible": true,
"extensions": ["rdf"]
},
"application/reginfo+xml": {
"source": "iana",
"extensions": ["rif"]
},
"application/relax-ng-compact-syntax": {
"source": "iana",
"extensions": ["rnc"]
},
"application/remote-printing": {
"source": "iana"
},
"application/reputon+json": {
"source": "iana",
"compressible": true
},
"application/resource-lists+xml": {
"source": "iana",
"extensions": ["rl"]
},
"application/resource-lists-diff+xml": {
"source": "iana",
"extensions": ["rld"]
},
"application/riscos": {
"source": "iana"
},
"application/rlmi+xml": {
"source": "iana"
},
"application/rls-services+xml": {
"source": "iana",
"extensions": ["rs"]
},
"application/rpki-ghostbusters": {
"source": "iana",
"extensions": ["gbr"]
},
"application/rpki-manifest": {
"source": "iana",
"extensions": ["mft"]
},
"application/rpki-roa": {
"source": "iana",
"extensions": ["roa"]
},
"application/rpki-updown": {
"source": "iana"
},
"application/rsd+xml": {
"source": "apache",
"extensions": ["rsd"]
},
"application/rss+xml": {
"source": "apache",
"compressible": true,
"extensions": ["rss"]
},
"application/rtf": {
"source": "iana",
"compressible": true,
"extensions": ["rtf"]
},
"application/rtploopback": {
"source": "iana"
},
"application/rtx": {
"source": "iana"
},
"application/samlassertion+xml": {
"source": "iana"
},
"application/samlmetadata+xml": {
"source": "iana"
},
"application/sbml+xml": {
"source": "iana",
"extensions": ["sbml"]
},
"application/scaip+xml": {
"source": "iana"
},
"application/scvp-cv-request": {
"source": "iana",
"extensions": ["scq"]
},
"application/scvp-cv-response": {
"source": "iana",
"extensions": ["scs"]
},
"application/scvp-vp-request": {
"source": "iana",
"extensions": ["spq"]
},
"application/scvp-vp-response": {
"source": "iana",
"extensions": ["spp"]
},
"application/sdp": {
"source": "iana",
"extensions": ["sdp"]
},
"application/sep+xml": {
"source": "iana"
},
"application/sep-exi": {
"source": "iana"
},
"application/session-info": {
"source": "iana"
},
"application/set-payment": {
"source": "iana"
},
"application/set-payment-initiation": {
"source": "iana",
"extensions": ["setpay"]
},
"application/set-registration": {
"source": "iana"
},
"application/set-registration-initiation": {
"source": "iana",
"extensions": ["setreg"]
},
"application/sgml": {
"source": "iana"
},
"application/sgml-open-catalog": {
"source": "iana"
},
"application/shf+xml": {
"source": "iana",
"extensions": ["shf"]
},
"application/sieve": {
"source": "iana"
},
"application/simple-filter+xml": {
"source": "iana"
},
"application/simple-message-summary": {
"source": "iana"
},
"application/simplesymbolcontainer": {
"source": "iana"
},
"application/slate": {
"source": "iana"
},
"application/smil": {
"source": "iana"
},
"application/smil+xml": {
"source": "iana",
"extensions": ["smi","smil"]
},
"application/smpte336m": {
"source": "iana"
},
"application/soap+fastinfoset": {
"source": "iana"
},
"application/soap+xml": {
"source": "iana",
"compressible": true
},
"application/sparql-query": {
"source": "iana",
"extensions": ["rq"]
},
"application/sparql-results+xml": {
"source": "iana",
"extensions": ["srx"]
},
"application/spirits-event+xml": {
"source": "iana"
},
"application/sql": {
"source": "iana"
},
"application/srgs": {
"source": "iana",
"extensions": ["gram"]
},
"application/srgs+xml": {
"source": "iana",
"extensions": ["grxml"]
},
"application/sru+xml": {
"source": "iana",
"extensions": ["sru"]
},
"application/ssdl+xml": {
"source": "apache",
"extensions": ["ssdl"]
},
"application/ssml+xml": {
"source": "iana",
"extensions": ["ssml"]
},
"application/tamp-apex-update": {
"source": "iana"
},
"application/tamp-apex-update-confirm": {
"source": "iana"
},
"application/tamp-community-update": {
"source": "iana"
},
"application/tamp-community-update-confirm": {
"source": "iana"
},
"application/tamp-error": {
"source": "iana"
},
"application/tamp-sequence-adjust": {
"source": "iana"
},
"application/tamp-sequence-adjust-confirm": {
"source": "iana"
},
"application/tamp-status-query": {
"source": "iana"
},
"application/tamp-status-response": {
"source": "iana"
},
"application/tamp-update": {
"source": "iana"
},
"application/tamp-update-confirm": {
"source": "iana"
},
"application/tar": {
"compressible": true
},
"application/tei+xml": {
"source": "iana",
"extensions": ["tei","teicorpus"]
},
"application/thraud+xml": {
"source": "iana",
"extensions": ["tfi"]
},
"application/timestamp-query": {
"source": "iana"
},
"application/timestamp-reply": {
"source": "iana"
},
"application/timestamped-data": {
"source": "iana",
"extensions": ["tsd"]
},
"application/ttml+xml": {
"source": "iana"
},
"application/tve-trigger": {
"source": "iana"
},
"application/ulpfec": {
"source": "iana"
},
"application/urc-grpsheet+xml": {
"source": "iana"
},
"application/urc-ressheet+xml": {
"source": "iana"
},
"application/urc-targetdesc+xml": {
"source": "iana"
},
"application/urc-uisocketdesc+xml": {
"source": "iana"
},
"application/vcard+json": {
"source": "iana",
"compressible": true
},
"application/vcard+xml": {
"source": "iana"
},
"application/vemmi": {
"source": "iana"
},
"application/vividence.scriptfile": {
"source": "apache"
},
"application/vnd.3gpp.bsf+xml": {
"source": "iana"
},
"application/vnd.3gpp.pic-bw-large": {
"source": "iana",
"extensions": ["plb"]
},
"application/vnd.3gpp.pic-bw-small": {
"source": "iana",
"extensions": ["psb"]
},
"application/vnd.3gpp.pic-bw-var": {
"source": "iana",
"extensions": ["pvb"]
},
"application/vnd.3gpp.sms": {
"source": "iana"
},
"application/vnd.3gpp2.bcmcsinfo+xml": {
"source": "iana"
},
"application/vnd.3gpp2.sms": {
"source": "iana"
},
"application/vnd.3gpp2.tcap": {
"source": "iana",
"extensions": ["tcap"]
},
"application/vnd.3m.post-it-notes": {
"source": "iana",
"extensions": ["pwn"]
},
"application/vnd.accpac.simply.aso": {
"source": "iana",
"extensions": ["aso"]
},
"application/vnd.accpac.simply.imp": {
"source": "iana",
"extensions": ["imp"]
},
"application/vnd.acucobol": {
"source": "iana",
"extensions": ["acu"]
},
"application/vnd.acucorp": {
"source": "iana",
"extensions": ["atc","acutc"]
},
"application/vnd.adobe.air-application-installer-package+zip": {
"source": "apache",
"extensions": ["air"]
},
"application/vnd.adobe.flash.movie": {
"source": "iana"
},
"application/vnd.adobe.formscentral.fcdt": {
"source": "iana",
"extensions": ["fcdt"]
},
"application/vnd.adobe.fxp": {
"source": "iana",
"extensions": ["fxp","fxpl"]
},
"application/vnd.adobe.partial-upload": {
"source": "iana"
},
"application/vnd.adobe.xdp+xml": {
"source": "iana",
"extensions": ["xdp"]
},
"application/vnd.adobe.xfdf": {
"source": "iana",
"extensions": ["xfdf"]
},
"application/vnd.aether.imp": {
"source": "iana"
},
"application/vnd.ah-barcode": {
"source": "iana"
},
"application/vnd.ahead.space": {
"source": "iana",
"extensions": ["ahead"]
},
"application/vnd.airzip.filesecure.azf": {
"source": "iana",
"extensions": ["azf"]
},
"application/vnd.airzip.filesecure.azs": {
"source": "iana",
"extensions": ["azs"]
},
"application/vnd.amazon.ebook": {
"source": "apache",
"extensions": ["azw"]
},
"application/vnd.americandynamics.acc": {
"source": "iana",
"extensions": ["acc"]
},
"application/vnd.amiga.ami": {
"source": "iana",
"extensions": ["ami"]
},
"application/vnd.amundsen.maze+xml": {
"source": "iana"
},
"application/vnd.android.package-archive": {
"source": "apache",
"compressible": false,
"extensions": ["apk"]
},
"application/vnd.anser-web-certificate-issue-initiation": {
"source": "iana",
"extensions": ["cii"]
},
"application/vnd.anser-web-funds-transfer-initiation": {
"source": "apache",
"extensions": ["fti"]
},
"application/vnd.antix.game-component": {
"source": "iana",
"extensions": ["atx"]
},
"application/vnd.apache.thrift.binary": {
"source": "iana"
},
"application/vnd.apache.thrift.compact": {
"source": "iana"
},
"application/vnd.apache.thrift.json": {
"source": "iana"
},
"application/vnd.api+json": {
"source": "iana",
"compressible": true
},
"application/vnd.apple.installer+xml": {
"source": "iana",
"extensions": ["mpkg"]
},
"application/vnd.apple.mpegurl": {
"source": "iana",
"extensions": ["m3u8"]
},
"application/vnd.arastra.swi": {
"source": "iana"
},
"application/vnd.aristanetworks.swi": {
"source": "iana",
"extensions": ["swi"]
},
"application/vnd.artsquare": {
"source": "iana"
},
"application/vnd.astraea-software.iota": {
"source": "iana",
"extensions": ["iota"]
},
"application/vnd.audiograph": {
"source": "iana",
"extensions": ["aep"]
},
"application/vnd.autopackage": {
"source": "iana"
},
"application/vnd.avistar+xml": {
"source": "iana"
},
"application/vnd.balsamiq.bmml+xml": {
"source": "iana"
},
"application/vnd.bekitzur-stech+json": {
"source": "iana",
"compressible": true
},
"application/vnd.blueice.multipass": {
"source": "iana",
"extensions": ["mpm"]
},
"application/vnd.bluetooth.ep.oob": {
"source": "iana"
},
"application/vnd.bluetooth.le.oob": {
"source": "iana"
},
"application/vnd.bmi": {
"source": "iana",
"extensions": ["bmi"]
},
"application/vnd.businessobjects": {
"source": "iana",
"extensions": ["rep"]
},
"application/vnd.cab-jscript": {
"source": "iana"
},
"application/vnd.canon-cpdl": {
"source": "iana"
},
"application/vnd.canon-lips": {
"source": "iana"
},
"application/vnd.cendio.thinlinc.clientconf": {
"source": "iana"
},
"application/vnd.century-systems.tcp_stream": {
"source": "iana"
},
"application/vnd.chemdraw+xml": {
"source": "iana",
"extensions": ["cdxml"]
},
"application/vnd.chipnuts.karaoke-mmd": {
"source": "iana",
"extensions": ["mmd"]
},
"application/vnd.cinderella": {
"source": "iana",
"extensions": ["cdy"]
},
"application/vnd.cirpack.isdn-ext": {
"source": "iana"
},
"application/vnd.citationstyles.style+xml": {
"source": "iana"
},
"application/vnd.claymore": {
"source": "iana",
"extensions": ["cla"]
},
"application/vnd.cloanto.rp9": {
"source": "iana",
"extensions": ["rp9"]
},
"application/vnd.clonk.c4group": {
"source": "iana",
"extensions": ["c4g","c4d","c4f","c4p","c4u"]
},
"application/vnd.cluetrust.cartomobile-config": {
"source": "iana",
"extensions": ["c11amc"]
},
"application/vnd.cluetrust.cartomobile-config-pkg": {
"source": "iana",
"extensions": ["c11amz"]
},
"application/vnd.coffeescript": {
"source": "iana"
},
"application/vnd.collection+json": {
"source": "iana",
"compressible": true
},
"application/vnd.collection.doc+json": {
"source": "iana",
"compressible": true
},
"application/vnd.collection.next+json": {
"source": "iana",
"compressible": true
},
"application/vnd.commerce-battelle": {
"source": "iana"
},
"application/vnd.commonspace": {
"source": "iana",
"extensions": ["csp"]
},
"application/vnd.contact.cmsg": {
"source": "iana",
"extensions": ["cdbcmsg"]
},
"application/vnd.cosmocaller": {
"source": "iana",
"extensions": ["cmc"]
},
"application/vnd.crick.clicker": {
"source": "iana",
"extensions": ["clkx"]
},
"application/vnd.crick.clicker.keyboard": {
"source": "iana",
"extensions": ["clkk"]
},
"application/vnd.crick.clicker.palette": {
"source": "iana",
"extensions": ["clkp"]
},
"application/vnd.crick.clicker.template": {
"source": "iana",
"extensions": ["clkt"]
},
"application/vnd.crick.clicker.wordbank": {
"source": "iana",
"extensions": ["clkw"]
},
"application/vnd.criticaltools.wbs+xml": {
"source": "iana",
"extensions": ["wbs"]
},
"application/vnd.ctc-posml": {
"source": "iana",
"extensions": ["pml"]
},
"application/vnd.ctct.ws+xml": {
"source": "iana"
},
"application/vnd.cups-pdf": {
"source": "iana"
},
"application/vnd.cups-postscript": {
"source": "iana"
},
"application/vnd.cups-ppd": {
"source": "iana",
"extensions": ["ppd"]
},
"application/vnd.cups-raster": {
"source": "iana"
},
"application/vnd.cups-raw": {
"source": "iana"
},
"application/vnd.curl": {
"source": "iana"
},
"application/vnd.curl.car": {
"source": "apache",
"extensions": ["car"]
},
"application/vnd.curl.pcurl": {
"source": "apache",
"extensions": ["pcurl"]
},
"application/vnd.cyan.dean.root+xml": {
"source": "iana"
},
"application/vnd.cybank": {
"source": "iana"
},
"application/vnd.dart": {
"source": "iana",
"compressible": true,
"extensions": ["dart"]
},
"application/vnd.data-vision.rdz": {
"source": "iana",
"extensions": ["rdz"]
},
"application/vnd.debian.binary-package": {
"source": "iana"
},
"application/vnd.dece.data": {
"source": "iana",
"extensions": ["uvf","uvvf","uvd","uvvd"]
},
"application/vnd.dece.ttml+xml": {
"source": "iana",
"extensions": ["uvt","uvvt"]
},
"application/vnd.dece.unspecified": {
"source": "iana",
"extensions": ["uvx","uvvx"]
},
"application/vnd.dece.zip": {
"source": "iana",
"extensions": ["uvz","uvvz"]
},
"application/vnd.denovo.fcselayout-link": {
"source": "iana",
"extensions": ["fe_launch"]
},
"application/vnd.desmume-movie": {
"source": "iana"
},
"application/vnd.dir-bi.plate-dl-nosuffix": {
"source": "iana"
},
"application/vnd.dm.delegation+xml": {
"source": "iana"
},
"application/vnd.dna": {
"source": "iana",
"extensions": ["dna"]
},
"application/vnd.document+json": {
"source": "iana",
"compressible": true
},
"application/vnd.dolby.mlp": {
"source": "apache",
"extensions": ["mlp"]
},
"application/vnd.dolby.mobile.1": {
"source": "iana"
},
"application/vnd.dolby.mobile.2": {
"source": "iana"
},
"application/vnd.doremir.scorecloud-binary-document": {
"source": "iana"
},
"application/vnd.dpgraph": {
"source": "iana",
"extensions": ["dpg"]
},
"application/vnd.dreamfactory": {
"source": "iana",
"extensions": ["dfac"]
},
"application/vnd.ds-keypoint": {
"source": "apache",
"extensions": ["kpxx"]
},
"application/vnd.dtg.local": {
"source": "iana"
},
"application/vnd.dtg.local.flash": {
"source": "iana"
},
"application/vnd.dtg.local.html": {
"source": "iana"
},
"application/vnd.dvb.ait": {
"source": "iana",
"extensions": ["ait"]
},
"application/vnd.dvb.dvbj": {
"source": "iana"
},
"application/vnd.dvb.esgcontainer": {
"source": "iana"
},
"application/vnd.dvb.ipdcdftnotifaccess": {
"source": "iana"
},
"application/vnd.dvb.ipdcesgaccess": {
"source": "iana"
},
"application/vnd.dvb.ipdcesgaccess2": {
"source": "iana"
},
"application/vnd.dvb.ipdcesgpdd": {
"source": "iana"
},
"application/vnd.dvb.ipdcroaming": {
"source": "iana"
},
"application/vnd.dvb.iptv.alfec-base": {
"source": "iana"
},
"application/vnd.dvb.iptv.alfec-enhancement": {
"source": "iana"
},
"application/vnd.dvb.notif-aggregate-root+xml": {
"source": "iana"
},
"application/vnd.dvb.notif-container+xml": {
"source": "iana"
},
"application/vnd.dvb.notif-generic+xml": {
"source": "iana"
},
"application/vnd.dvb.notif-ia-msglist+xml": {
"source": "iana"
},
"application/vnd.dvb.notif-ia-registration-request+xml": {
"source": "iana"
},
"application/vnd.dvb.notif-ia-registration-response+xml": {
"source": "iana"
},
"application/vnd.dvb.notif-init+xml": {
"source": "iana"
},
"application/vnd.dvb.pfr": {
"source": "iana"
},
"application/vnd.dvb.service": {
"source": "iana",
"extensions": ["svc"]
},
"application/vnd.dxr": {
"source": "iana"
},
"application/vnd.dynageo": {
"source": "iana",
"extensions": ["geo"]
},
"application/vnd.dzr": {
"source": "iana"
},
"application/vnd.easykaraoke.cdgdownload": {
"source": "iana"
},
"application/vnd.ecdis-update": {
"source": "iana"
},
"application/vnd.ecowin.chart": {
"source": "iana",
"extensions": ["mag"]
},
"application/vnd.ecowin.filerequest": {
"source": "iana"
},
"application/vnd.ecowin.fileupdate": {
"source": "iana"
},
"application/vnd.ecowin.series": {
"source": "iana"
},
"application/vnd.ecowin.seriesrequest": {
"source": "iana"
},
"application/vnd.ecowin.seriesupdate": {
"source": "iana"
},
"application/vnd.emclient.accessrequest+xml": {
"source": "iana"
},
"application/vnd.enliven": {
"source": "iana",
"extensions": ["nml"]
},
"application/vnd.enphase.envoy": {
"source": "iana"
},
"application/vnd.eprints.data+xml": {
"source": "iana"
},
"application/vnd.epson.esf": {
"source": "iana",
"extensions": ["esf"]
},
"application/vnd.epson.msf": {
"source": "iana",
"extensions": ["msf"]
},
"application/vnd.epson.quickanime": {
"source": "iana",
"extensions": ["qam"]
},
"application/vnd.epson.salt": {
"source": "iana",
"extensions": ["slt"]
},
"application/vnd.epson.ssf": {
"source": "iana",
"extensions": ["ssf"]
},
"application/vnd.ericsson.quickcall": {
"source": "iana"
},
"application/vnd.eszigno3+xml": {
"source": "iana",
"extensions": ["es3","et3"]
},
"application/vnd.etsi.aoc+xml": {
"source": "iana"
},
"application/vnd.etsi.asic-e+zip": {
"source": "iana"
},
"application/vnd.etsi.asic-s+zip": {
"source": "iana"
},
"application/vnd.etsi.cug+xml": {
"source": "iana"
},
"application/vnd.etsi.iptvcommand+xml": {
"source": "iana"
},
"application/vnd.etsi.iptvdiscovery+xml": {
"source": "iana"
},
"application/vnd.etsi.iptvprofile+xml": {
"source": "iana"
},
"application/vnd.etsi.iptvsad-bc+xml": {
"source": "iana"
},
"application/vnd.etsi.iptvsad-cod+xml": {
"source": "iana"
},
"application/vnd.etsi.iptvsad-npvr+xml": {
"source": "iana"
},
"application/vnd.etsi.iptvservice+xml": {
"source": "iana"
},
"application/vnd.etsi.iptvsync+xml": {
"source": "iana"
},
"application/vnd.etsi.iptvueprofile+xml": {
"source": "iana"
},
"application/vnd.etsi.mcid+xml": {
"source": "iana"
},
"application/vnd.etsi.mheg5": {
"source": "iana"
},
"application/vnd.etsi.overload-control-policy-dataset+xml": {
"source": "iana"
},
"application/vnd.etsi.pstn+xml": {
"source": "iana"
},
"application/vnd.etsi.sci+xml": {
"source": "iana"
},
"application/vnd.etsi.simservs+xml": {
"source": "iana"
},
"application/vnd.etsi.timestamp-token": {
"source": "iana"
},
"application/vnd.etsi.tsl+xml": {
"source": "iana"
},
"application/vnd.etsi.tsl.der": {
"source": "iana"
},
"application/vnd.eudora.data": {
"source": "iana"
},
"application/vnd.ezpix-album": {
"source": "iana",
"extensions": ["ez2"]
},
"application/vnd.ezpix-package": {
"source": "iana",
"extensions": ["ez3"]
},
"application/vnd.f-secure.mobile": {
"source": "iana"
},
"application/vnd.fastcopy-disk-image": {
"source": "iana"
},
"application/vnd.fdf": {
"source": "iana",
"extensions": ["fdf"]
},
"application/vnd.fdsn.mseed": {
"source": "iana",
"extensions": ["mseed"]
},
"application/vnd.fdsn.seed": {
"source": "iana",
"extensions": ["seed","dataless"]
},
"application/vnd.ffsns": {
"source": "iana"
},
"application/vnd.fints": {
"source": "iana"
},
"application/vnd.flographit": {
"source": "iana",
"extensions": ["gph"]
},
"application/vnd.fluxtime.clip": {
"source": "iana",
"extensions": ["ftc"]
},
"application/vnd.font-fontforge-sfd": {
"source": "iana"
},
"application/vnd.framemaker": {
"source": "iana",
"extensions": ["fm","frame","maker","book"]
},
"application/vnd.frogans.fnc": {
"source": "iana",
"extensions": ["fnc"]
},
"application/vnd.frogans.ltf": {
"source": "iana",
"extensions": ["ltf"]
},
"application/vnd.fsc.weblaunch": {
"source": "iana",
"extensions": ["fsc"]
},
"application/vnd.fujitsu.oasys": {
"source": "iana",
"extensions": ["oas"]
},
"application/vnd.fujitsu.oasys2": {
"source": "iana",
"extensions": ["oa2"]
},
"application/vnd.fujitsu.oasys3": {
"source": "iana",
"extensions": ["oa3"]
},
"application/vnd.fujitsu.oasysgp": {
"source": "iana",
"extensions": ["fg5"]
},
"application/vnd.fujitsu.oasysprs": {
"source": "iana",
"extensions": ["bh2"]
},
"application/vnd.fujixerox.art-ex": {
"source": "iana"
},
"application/vnd.fujixerox.art4": {
"source": "iana"
},
"application/vnd.fujixerox.ddd": {
"source": "iana",
"extensions": ["ddd"]
},
"application/vnd.fujixerox.docuworks": {
"source": "iana",
"extensions": ["xdw"]
},
"application/vnd.fujixerox.docuworks.binder": {
"source": "iana",
"extensions": ["xbd"]
},
"application/vnd.fujixerox.docuworks.container": {
"source": "iana"
},
"application/vnd.fujixerox.hbpl": {
"source": "iana"
},
"application/vnd.fut-misnet": {
"source": "iana"
},
"application/vnd.fuzzysheet": {
"source": "iana",
"extensions": ["fzs"]
},
"application/vnd.genomatix.tuxedo": {
"source": "iana",
"extensions": ["txd"]
},
"application/vnd.geo+json": {
"source": "iana",
"compressible": true
},
"application/vnd.geocube+xml": {
"source": "iana"
},
"application/vnd.geogebra.file": {
"source": "iana",
"extensions": ["ggb"]
},
"application/vnd.geogebra.tool": {
"source": "iana",
"extensions": ["ggt"]
},
"application/vnd.geometry-explorer": {
"source": "iana",
"extensions": ["gex","gre"]
},
"application/vnd.geonext": {
"source": "iana",
"extensions": ["gxt"]
},
"application/vnd.geoplan": {
"source": "iana",
"extensions": ["g2w"]
},
"application/vnd.geospace": {
"source": "iana",
"extensions": ["g3w"]
},
"application/vnd.gerber": {
"source": "iana"
},
"application/vnd.globalplatform.card-content-mgt": {
"source": "iana"
},
"application/vnd.globalplatform.card-content-mgt-response": {
"source": "iana"
},
"application/vnd.gmx": {
"source": "iana",
"extensions": ["gmx"]
},
"application/vnd.google-earth.kml+xml": {
"source": "iana",
"compressible": true,
"extensions": ["kml"]
},
"application/vnd.google-earth.kmz": {
"source": "iana",
"compressible": false,
"extensions": ["kmz"]
},
"application/vnd.gov.sk.e-form+xml": {
"source": "iana"
},
"application/vnd.gov.sk.e-form+zip": {
"source": "iana"
},
"application/vnd.gov.sk.xmldatacontainer+xml": {
"source": "iana"
},
"application/vnd.grafeq": {
"source": "iana",
"extensions": ["gqf","gqs"]
},
"application/vnd.gridmp": {
"source": "iana"
},
"application/vnd.groove-account": {
"source": "iana",
"extensions": ["gac"]
},
"application/vnd.groove-help": {
"source": "iana",
"extensions": ["ghf"]
},
"application/vnd.groove-identity-message": {
"source": "iana",
"extensions": ["gim"]
},
"application/vnd.groove-injector": {
"source": "iana",
"extensions": ["grv"]
},
"application/vnd.groove-tool-message": {
"source": "iana",
"extensions": ["gtm"]
},
"application/vnd.groove-tool-template": {
"source": "iana",
"extensions": ["tpl"]
},
"application/vnd.groove-vcard": {
"source": "iana",
"extensions": ["vcg"]
},
"application/vnd.hal+json": {
"source": "iana",
"compressible": true
},
"application/vnd.hal+xml": {
"source": "iana",
"extensions": ["hal"]
},
"application/vnd.handheld-entertainment+xml": {
"source": "iana",
"extensions": ["zmm"]
},
"application/vnd.hbci": {
"source": "iana",
"extensions": ["hbci"]
},
"application/vnd.hcl-bireports": {
"source": "iana"
},
"application/vnd.heroku+json": {
"source": "iana",
"compressible": true
},
"application/vnd.hhe.lesson-player": {
"source": "iana",
"extensions": ["les"]
},
"application/vnd.hp-hpgl": {
"source": "iana",
"extensions": ["hpgl"]
},
"application/vnd.hp-hpid": {
"source": "iana",
"extensions": ["hpid"]
},
"application/vnd.hp-hps": {
"source": "iana",
"extensions": ["hps"]
},
"application/vnd.hp-jlyt": {
"source": "iana",
"extensions": ["jlt"]
},
"application/vnd.hp-pcl": {
"source": "iana",
"extensions": ["pcl"]
},
"application/vnd.hp-pclxl": {
"source": "iana",
"extensions": ["pclxl"]
},
"application/vnd.httphone": {
"source": "iana"
},
"application/vnd.hydrostatix.sof-data": {
"source": "iana"
},
"application/vnd.hzn-3d-crossword": {
"source": "iana"
},
"application/vnd.ibm.afplinedata": {
"source": "iana"
},
"application/vnd.ibm.electronic-media": {
"source": "iana"
},
"application/vnd.ibm.minipay": {
"source": "iana",
"extensions": ["mpy"]
},
"application/vnd.ibm.modcap": {
"source": "iana",
"extensions": ["afp","listafp","list3820"]
},
"application/vnd.ibm.rights-management": {
"source": "iana",
"extensions": ["irm"]
},
"application/vnd.ibm.secure-container": {
"source": "iana",
"extensions": ["sc"]
},
"application/vnd.iccprofile": {
"source": "iana",
"extensions": ["icc","icm"]
},
"application/vnd.ieee.1905": {
"source": "iana"
},
"application/vnd.igloader": {
"source": "iana",
"extensions": ["igl"]
},
"application/vnd.immervision-ivp": {
"source": "iana",
"extensions": ["ivp"]
},
"application/vnd.immervision-ivu": {
"source": "iana",
"extensions": ["ivu"]
},
"application/vnd.ims.imsccv1p1": {
"source": "iana"
},
"application/vnd.ims.imsccv1p2": {
"source": "iana"
},
"application/vnd.ims.imsccv1p3": {
"source": "iana"
},
"application/vnd.ims.lis.v2.result+json": {
"source": "iana",
"compressible": true
},
"application/vnd.ims.lti.v2.toolconsumerprofile+json": {
"source": "iana",
"compressible": true
},
"application/vnd.ims.lti.v2.toolproxy+json": {
"source": "iana",
"compressible": true
},
"application/vnd.ims.lti.v2.toolproxy.id+json": {
"source": "iana",
"compressible": true
},
"application/vnd.ims.lti.v2.toolsettings+json": {
"source": "iana",
"compressible": true
},
"application/vnd.ims.lti.v2.toolsettings.simple+json": {
"source": "iana",
"compressible": true
},
"application/vnd.informedcontrol.rms+xml": {
"source": "iana"
},
"application/vnd.informix-visionary": {
"source": "iana"
},
"application/vnd.infotech.project": {
"source": "iana"
},
"application/vnd.infotech.project+xml": {
"source": "iana"
},
"application/vnd.innopath.wamp.notification": {
"source": "iana"
},
"application/vnd.insors.igm": {
"source": "iana",
"extensions": ["igm"]
},
"application/vnd.intercon.formnet": {
"source": "iana",
"extensions": ["xpw","xpx"]
},
"application/vnd.intergeo": {
"source": "iana",
"extensions": ["i2g"]
},
"application/vnd.intertrust.digibox": {
"source": "iana"
},
"application/vnd.intertrust.nncp": {
"source": "iana"
},
"application/vnd.intu.qbo": {
"source": "iana",
"extensions": ["qbo"]
},
"application/vnd.intu.qfx": {
"source": "iana",
"extensions": ["qfx"]
},
"application/vnd.iptc.g2.catalogitem+xml": {
"source": "iana"
},
"application/vnd.iptc.g2.conceptitem+xml": {
"source": "iana"
},
"application/vnd.iptc.g2.knowledgeitem+xml": {
"source": "iana"
},
"application/vnd.iptc.g2.newsitem+xml": {
"source": "iana"
},
"application/vnd.iptc.g2.newsmessage+xml": {
"source": "iana"
},
"application/vnd.iptc.g2.packageitem+xml": {
"source": "iana"
},
"application/vnd.iptc.g2.planningitem+xml": {
"source": "iana"
},
"application/vnd.ipunplugged.rcprofile": {
"source": "iana",
"extensions": ["rcprofile"]
},
"application/vnd.irepository.package+xml": {
"source": "iana",
"extensions": ["irp"]
},
"application/vnd.is-xpr": {
"source": "iana",
"extensions": ["xpr"]
},
"application/vnd.isac.fcs": {
"source": "iana",
"extensions": ["fcs"]
},
"application/vnd.jam": {
"source": "iana",
"extensions": ["jam"]
},
"application/vnd.japannet-directory-service": {
"source": "iana"
},
"application/vnd.japannet-jpnstore-wakeup": {
"source": "iana"
},
"application/vnd.japannet-payment-wakeup": {
"source": "iana"
},
"application/vnd.japannet-registration": {
"source": "iana"
},
"application/vnd.japannet-registration-wakeup": {
"source": "iana"
},
"application/vnd.japannet-setstore-wakeup": {
"source": "iana"
},
"application/vnd.japannet-verification": {
"source": "iana"
},
"application/vnd.japannet-verification-wakeup": {
"source": "iana"
},
"application/vnd.jcp.javame.midlet-rms": {
"source": "iana",
"extensions": ["rms"]
},
"application/vnd.jisp": {
"source": "iana",
"extensions": ["jisp"]
},
"application/vnd.joost.joda-archive": {
"source": "iana",
"extensions": ["joda"]
},
"application/vnd.jsk.isdn-ngn": {
"source": "iana"
},
"application/vnd.kahootz": {
"source": "iana",
"extensions": ["ktz","ktr"]
},
"application/vnd.kde.karbon": {
"source": "iana",
"extensions": ["karbon"]
},
"application/vnd.kde.kchart": {
"source": "iana",
"extensions": ["chrt"]
},
"application/vnd.kde.kformula": {
"source": "iana",
"extensions": ["kfo"]
},
"application/vnd.kde.kivio": {
"source": "iana",
"extensions": ["flw"]
},
"application/vnd.kde.kontour": {
"source": "iana",
"extensions": ["kon"]
},
"application/vnd.kde.kpresenter": {
"source": "iana",
"extensions": ["kpr","kpt"]
},
"application/vnd.kde.kspread": {
"source": "iana",
"extensions": ["ksp"]
},
"application/vnd.kde.kword": {
"source": "iana",
"extensions": ["kwd","kwt"]
},
"application/vnd.kenameaapp": {
"source": "iana",
"extensions": ["htke"]
},
"application/vnd.kidspiration": {
"source": "iana",
"extensions": ["kia"]
},
"application/vnd.kinar": {
"source": "iana",
"extensions": ["kne","knp"]
},
"application/vnd.koan": {
"source": "iana",
"extensions": ["skp","skd","skt","skm"]
},
"application/vnd.kodak-descriptor": {
"source": "iana",
"extensions": ["sse"]
},
"application/vnd.las.las+xml": {
"source": "iana",
"extensions": ["lasxml"]
},
"application/vnd.liberty-request+xml": {
"source": "iana"
},
"application/vnd.llamagraphics.life-balance.desktop": {
"source": "iana",
"extensions": ["lbd"]
},
"application/vnd.llamagraphics.life-balance.exchange+xml": {
"source": "iana",
"extensions": ["lbe"]
},
"application/vnd.lotus-1-2-3": {
"source": "iana",
"extensions": ["123"]
},
"application/vnd.lotus-approach": {
"source": "iana",
"extensions": ["apr"]
},
"application/vnd.lotus-freelance": {
"source": "iana",
"extensions": ["pre"]
},
"application/vnd.lotus-notes": {
"source": "iana",
"extensions": ["nsf"]
},
"application/vnd.lotus-organizer": {
"source": "iana",
"extensions": ["org"]
},
"application/vnd.lotus-screencam": {
"source": "iana",
"extensions": ["scm"]
},
"application/vnd.lotus-wordpro": {
"source": "iana",
"extensions": ["lwp"]
},
"application/vnd.macports.portpkg": {
"source": "iana",
"extensions": ["portpkg"]
},
"application/vnd.marlin.drm.actiontoken+xml": {
"source": "iana"
},
"application/vnd.marlin.drm.conftoken+xml": {
"source": "iana"
},
"application/vnd.marlin.drm.license+xml": {
"source": "iana"
},
"application/vnd.marlin.drm.mdcf": {
"source": "iana"
},
"application/vnd.mason+json": {
"source": "iana",
"compressible": true
},
"application/vnd.maxmind.maxmind-db": {
"source": "iana"
},
"application/vnd.mcd": {
"source": "iana",
"extensions": ["mcd"]
},
"application/vnd.medcalcdata": {
"source": "iana",
"extensions": ["mc1"]
},
"application/vnd.mediastation.cdkey": {
"source": "iana",
"extensions": ["cdkey"]
},
"application/vnd.meridian-slingshot": {
"source": "iana"
},
"application/vnd.mfer": {
"source": "iana",
"extensions": ["mwf"]
},
"application/vnd.mfmp": {
"source": "iana",
"extensions": ["mfm"]
},
"application/vnd.micrografx.flo": {
"source": "iana",
"extensions": ["flo"]
},
"application/vnd.micrografx.igx": {
"source": "iana",
"extensions": ["igx"]
},
"application/vnd.miele+json": {
"source": "iana",
"compressible": true
},
"application/vnd.mif": {
"source": "iana",
"extensions": ["mif"]
},
"application/vnd.minisoft-hp3000-save": {
"source": "iana"
},
"application/vnd.mitsubishi.misty-guard.trustweb": {
"source": "iana"
},
"application/vnd.mobius.daf": {
"source": "iana",
"extensions": ["daf"]
},
"application/vnd.mobius.dis": {
"source": "iana",
"extensions": ["dis"]
},
"application/vnd.mobius.mbk": {
"source": "iana",
"extensions": ["mbk"]
},
"application/vnd.mobius.mqy": {
"source": "iana",
"extensions": ["mqy"]
},
"application/vnd.mobius.msl": {
"source": "iana",
"extensions": ["msl"]
},
"application/vnd.mobius.plc": {
"source": "iana",
"extensions": ["plc"]
},
"application/vnd.mobius.txf": {
"source": "iana",
"extensions": ["txf"]
},
"application/vnd.mophun.application": {
"source": "iana",
"extensions": ["mpn"]
},
"application/vnd.mophun.certificate": {
"source": "iana",
"extensions": ["mpc"]
},
"application/vnd.motorola.flexsuite": {
"source": "iana"
},
"application/vnd.motorola.flexsuite.adsi": {
"source": "iana"
},
"application/vnd.motorola.flexsuite.fis": {
"source": "iana"
},
"application/vnd.motorola.flexsuite.gotap": {
"source": "iana"
},
"application/vnd.motorola.flexsuite.kmr": {
"source": "iana"
},
"application/vnd.motorola.flexsuite.ttc": {
"source": "iana"
},
"application/vnd.motorola.flexsuite.wem": {
"source": "iana"
},
"application/vnd.motorola.iprm": {
"source": "iana"
},
"application/vnd.mozilla.xul+xml": {
"source": "iana",
"compressible": true,
"extensions": ["xul"]
},
"application/vnd.ms-3mfdocument": {
"source": "iana"
},
"application/vnd.ms-artgalry": {
"source": "iana",
"extensions": ["cil"]
},
"application/vnd.ms-asf": {
"source": "iana"
},
"application/vnd.ms-cab-compressed": {
"source": "iana",
"extensions": ["cab"]
},
"application/vnd.ms-color.iccprofile": {
"source": "apache"
},
"application/vnd.ms-excel": {
"source": "iana",
"compressible": false,
"extensions": ["xls","xlm","xla","xlc","xlt","xlw"]
},
"application/vnd.ms-excel.addin.macroenabled.12": {
"source": "iana",
"extensions": ["xlam"]
},
"application/vnd.ms-excel.sheet.binary.macroenabled.12": {
"source": "iana",
"extensions": ["xlsb"]
},
"application/vnd.ms-excel.sheet.macroenabled.12": {
"source": "iana",
"extensions": ["xlsm"]
},
"application/vnd.ms-excel.template.macroenabled.12": {
"source": "iana",
"extensions": ["xltm"]
},
"application/vnd.ms-fontobject": {
"source": "iana",
"compressible": true,
"extensions": ["eot"]
},
"application/vnd.ms-htmlhelp": {
"source": "iana",
"extensions": ["chm"]
},
"application/vnd.ms-ims": {
"source": "iana",
"extensions": ["ims"]
},
"application/vnd.ms-lrm": {
"source": "iana",
"extensions": ["lrm"]
},
"application/vnd.ms-office.activex+xml": {
"source": "iana"
},
"application/vnd.ms-officetheme": {
"source": "iana",
"extensions": ["thmx"]
},
"application/vnd.ms-opentype": {
"source": "apache",
"compressible": true
},
"application/vnd.ms-package.obfuscated-opentype": {
"source": "apache"
},
"application/vnd.ms-pki.seccat": {
"source": "apache",
"extensions": ["cat"]
},
"application/vnd.ms-pki.stl": {
"source": "apache",
"extensions": ["stl"]
},
"application/vnd.ms-playready.initiator+xml": {
"source": "iana"
},
"application/vnd.ms-powerpoint": {
"source": "iana",
"compressible": false,
"extensions": ["ppt","pps","pot"]
},
"application/vnd.ms-powerpoint.addin.macroenabled.12": {
"source": "iana",
"extensions": ["ppam"]
},
"application/vnd.ms-powerpoint.presentation.macroenabled.12": {
"source": "iana",
"extensions": ["pptm"]
},
"application/vnd.ms-powerpoint.slide.macroenabled.12": {
"source": "iana",
"extensions": ["sldm"]
},
"application/vnd.ms-powerpoint.slideshow.macroenabled.12": {
"source": "iana",
"extensions": ["ppsm"]
},
"application/vnd.ms-powerpoint.template.macroenabled.12": {
"source": "iana",
"extensions": ["potm"]
},
"application/vnd.ms-printing.printticket+xml": {
"source": "apache"
},
"application/vnd.ms-project": {
"source": "iana",
"extensions": ["mpp","mpt"]
},
"application/vnd.ms-tnef": {
"source": "iana"
},
"application/vnd.ms-windows.printerpairing": {
"source": "iana"
},
"application/vnd.ms-wmdrm.lic-chlg-req": {
"source": "iana"
},
"application/vnd.ms-wmdrm.lic-resp": {
"source": "iana"
},
"application/vnd.ms-wmdrm.meter-chlg-req": {
"source": "iana"
},
"applicat
View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

View raw

(Sorry about that, but we can’t show files that are this big right now.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment