mirror of
https://github.com/mgerb/mywebsite
synced 2026-01-12 02:42:48 +00:00
updated bunch of file paths and changed the way posts are loaded
This commit is contained in:
96
node_modules/body-parser/lib/read.js
generated
vendored
96
node_modules/body-parser/lib/read.js
generated
vendored
@@ -4,10 +4,14 @@
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
* @private
|
||||
*/
|
||||
|
||||
var createError = require('http-errors')
|
||||
var getBody = require('raw-body')
|
||||
var iconv = require('iconv-lite')
|
||||
var onFinished = require('on-finished')
|
||||
@@ -33,45 +37,52 @@ module.exports = read
|
||||
|
||||
function read(req, res, next, parse, debug, options) {
|
||||
var length
|
||||
var opts = options || {}
|
||||
var stream
|
||||
|
||||
// flag as parsed
|
||||
req._body = true
|
||||
|
||||
var opts = options || {}
|
||||
|
||||
try {
|
||||
stream = contentstream(req, debug, opts.inflate)
|
||||
length = stream.length
|
||||
delete stream.length
|
||||
} catch (err) {
|
||||
return next(err)
|
||||
}
|
||||
|
||||
opts.length = length
|
||||
|
||||
// read options
|
||||
var encoding = opts.encoding !== null
|
||||
? opts.encoding || 'utf-8'
|
||||
: null
|
||||
var verify = opts.verify
|
||||
|
||||
try {
|
||||
// get the content stream
|
||||
stream = contentstream(req, debug, opts.inflate)
|
||||
length = stream.length
|
||||
stream.length = undefined
|
||||
} catch (err) {
|
||||
return next(err)
|
||||
}
|
||||
|
||||
// set raw-body options
|
||||
opts.length = length
|
||||
opts.encoding = verify
|
||||
? null
|
||||
: encoding
|
||||
|
||||
// assert charset is supported
|
||||
if (opts.encoding === null && encoding !== null && !iconv.encodingExists(encoding)) {
|
||||
return next(createError(415, 'unsupported charset "' + encoding.toUpperCase() + '"', {
|
||||
charset: encoding.toLowerCase()
|
||||
}))
|
||||
}
|
||||
|
||||
// read body
|
||||
debug('read body')
|
||||
getBody(stream, opts, function (err, body) {
|
||||
if (err) {
|
||||
if (!err.status) {
|
||||
err.status = 400
|
||||
}
|
||||
// default to 400
|
||||
setErrorStatus(err, 400)
|
||||
|
||||
// echo back charset
|
||||
if (err.type === 'encoding.unsupported') {
|
||||
err = new Error('unsupported charset "' + encoding.toUpperCase() + '"')
|
||||
err.charset = encoding.toLowerCase()
|
||||
err.status = 415
|
||||
err = createError(415, 'unsupported charset "' + encoding.toUpperCase() + '"', {
|
||||
charset: encoding.toLowerCase()
|
||||
})
|
||||
}
|
||||
|
||||
// read off entire request
|
||||
@@ -88,24 +99,31 @@ function read(req, res, next, parse, debug, options) {
|
||||
debug('verify body')
|
||||
verify(req, res, body, encoding)
|
||||
} catch (err) {
|
||||
if (!err.status) err.status = 403
|
||||
return next(err)
|
||||
// default to 403
|
||||
setErrorStatus(err, 403)
|
||||
next(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// parse
|
||||
var str
|
||||
try {
|
||||
debug('parse body')
|
||||
body = typeof body !== 'string' && encoding !== null
|
||||
str = typeof body !== 'string' && encoding !== null
|
||||
? iconv.decode(body, encoding)
|
||||
: body
|
||||
req.body = parse(body)
|
||||
req.body = parse(str)
|
||||
} catch (err) {
|
||||
if (!err.status) {
|
||||
err.body = body
|
||||
err.status = 400
|
||||
}
|
||||
return next(err)
|
||||
err.body = str === undefined
|
||||
? body
|
||||
: str
|
||||
|
||||
// default to 400
|
||||
setErrorStatus(err, 400)
|
||||
|
||||
next(err)
|
||||
return
|
||||
}
|
||||
|
||||
next()
|
||||
@@ -124,16 +142,13 @@ function read(req, res, next, parse, debug, options) {
|
||||
|
||||
function contentstream(req, debug, inflate) {
|
||||
var encoding = (req.headers['content-encoding'] || 'identity').toLowerCase()
|
||||
var err
|
||||
var length = req.headers['content-length']
|
||||
var stream
|
||||
|
||||
debug('content-encoding "%s"', encoding)
|
||||
|
||||
if (inflate === false && encoding !== 'identity') {
|
||||
err = new Error('content encoding unsupported')
|
||||
err.status = 415
|
||||
throw err
|
||||
throw createError(415, 'content encoding unsupported')
|
||||
}
|
||||
|
||||
switch (encoding) {
|
||||
@@ -152,11 +167,22 @@ function contentstream(req, debug, inflate) {
|
||||
stream.length = length
|
||||
break
|
||||
default:
|
||||
err = new Error('unsupported content encoding "' + encoding + '"')
|
||||
err.encoding = encoding
|
||||
err.status = 415
|
||||
throw err
|
||||
throw createError(415, 'unsupported content encoding "' + encoding + '"', {
|
||||
encoding: encoding
|
||||
})
|
||||
}
|
||||
|
||||
return stream
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a status on an error object, if ones does not exist
|
||||
* @private
|
||||
*/
|
||||
|
||||
function setErrorStatus(error, status) {
|
||||
if (!error.status && !error.statusCode) {
|
||||
error.status = status
|
||||
error.statusCode = status
|
||||
}
|
||||
}
|
||||
|
||||
35
node_modules/body-parser/lib/types/json.js
generated
vendored
35
node_modules/body-parser/lib/types/json.js
generated
vendored
@@ -5,12 +5,16 @@
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
* @private
|
||||
*/
|
||||
|
||||
var bytes = require('bytes')
|
||||
var contentType = require('content-type')
|
||||
var createError = require('http-errors')
|
||||
var debug = require('debug')('body-parser:json')
|
||||
var read = require('../read')
|
||||
var typeis = require('type-is')
|
||||
@@ -40,20 +44,20 @@ var firstcharRegExp = /^[\x20\x09\x0a\x0d]*(.)/
|
||||
*
|
||||
* @param {object} [options]
|
||||
* @return {function}
|
||||
* @api public
|
||||
* @public
|
||||
*/
|
||||
|
||||
function json(options) {
|
||||
options = options || {}
|
||||
var opts = options || {}
|
||||
|
||||
var limit = typeof options.limit !== 'number'
|
||||
? bytes(options.limit || '100kb')
|
||||
: options.limit
|
||||
var inflate = options.inflate !== false
|
||||
var reviver = options.reviver
|
||||
var strict = options.strict !== false
|
||||
var type = options.type || 'json'
|
||||
var verify = options.verify || false
|
||||
var limit = typeof opts.limit !== 'number'
|
||||
? bytes.parse(opts.limit || '100kb')
|
||||
: opts.limit
|
||||
var inflate = opts.inflate !== false
|
||||
var reviver = opts.reviver
|
||||
var strict = opts.strict !== false
|
||||
var type = opts.type || 'application/json'
|
||||
var verify = opts.verify || false
|
||||
|
||||
if (verify !== false && typeof verify !== 'function') {
|
||||
throw new TypeError('option verify must be function')
|
||||
@@ -76,7 +80,7 @@ function json(options) {
|
||||
|
||||
if (first !== '{' && first !== '[') {
|
||||
debug('strict violation')
|
||||
throw new Error('invalid json')
|
||||
throw new SyntaxError('Unexpected token ' + first)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,10 +110,11 @@ function json(options) {
|
||||
// assert charset per RFC 7159 sec 8.1
|
||||
var charset = getCharset(req) || 'utf-8'
|
||||
if (charset.substr(0, 4) !== 'utf-') {
|
||||
var err = new Error('unsupported charset "' + charset.toUpperCase() + '"')
|
||||
err.charset = charset
|
||||
err.status = 415
|
||||
return debug('invalid charset'), next(err)
|
||||
debug('invalid charset')
|
||||
next(createError(415, 'unsupported charset "' + charset.toUpperCase() + '"', {
|
||||
charset: charset
|
||||
}))
|
||||
return
|
||||
}
|
||||
|
||||
// read
|
||||
|
||||
16
node_modules/body-parser/lib/types/raw.js
generated
vendored
16
node_modules/body-parser/lib/types/raw.js
generated
vendored
@@ -4,6 +4,8 @@
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
@@ -28,14 +30,14 @@ module.exports = raw
|
||||
*/
|
||||
|
||||
function raw(options) {
|
||||
options = options || {};
|
||||
var opts = options || {};
|
||||
|
||||
var inflate = options.inflate !== false
|
||||
var limit = typeof options.limit !== 'number'
|
||||
? bytes(options.limit || '100kb')
|
||||
: options.limit
|
||||
var type = options.type || 'application/octet-stream'
|
||||
var verify = options.verify || false
|
||||
var inflate = opts.inflate !== false
|
||||
var limit = typeof opts.limit !== 'number'
|
||||
? bytes.parse(opts.limit || '100kb')
|
||||
: opts.limit
|
||||
var type = opts.type || 'application/octet-stream'
|
||||
var verify = opts.verify || false
|
||||
|
||||
if (verify !== false && typeof verify !== 'function') {
|
||||
throw new TypeError('option verify must be function')
|
||||
|
||||
18
node_modules/body-parser/lib/types/text.js
generated
vendored
18
node_modules/body-parser/lib/types/text.js
generated
vendored
@@ -4,6 +4,8 @@
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
@@ -29,15 +31,15 @@ module.exports = text
|
||||
*/
|
||||
|
||||
function text(options) {
|
||||
options = options || {};
|
||||
var opts = options || {}
|
||||
|
||||
var defaultCharset = options.defaultCharset || 'utf-8'
|
||||
var inflate = options.inflate !== false
|
||||
var limit = typeof options.limit !== 'number'
|
||||
? bytes(options.limit || '100kb')
|
||||
: options.limit
|
||||
var type = options.type || 'text/plain'
|
||||
var verify = options.verify || false
|
||||
var defaultCharset = opts.defaultCharset || 'utf-8'
|
||||
var inflate = opts.inflate !== false
|
||||
var limit = typeof opts.limit !== 'number'
|
||||
? bytes.parse(opts.limit || '100kb')
|
||||
: opts.limit
|
||||
var type = opts.type || 'text/plain'
|
||||
var verify = opts.verify || false
|
||||
|
||||
if (verify !== false && typeof verify !== 'function') {
|
||||
throw new TypeError('option verify must be function')
|
||||
|
||||
64
node_modules/body-parser/lib/types/urlencoded.js
generated
vendored
64
node_modules/body-parser/lib/types/urlencoded.js
generated
vendored
@@ -5,12 +5,16 @@
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
* @private
|
||||
*/
|
||||
|
||||
var bytes = require('bytes')
|
||||
var contentType = require('content-type')
|
||||
var createError = require('http-errors')
|
||||
var debug = require('debug')('body-parser:urlencoded')
|
||||
var deprecate = require('depd')('body-parser')
|
||||
var read = require('../read')
|
||||
@@ -33,24 +37,24 @@ var parsers = Object.create(null)
|
||||
*
|
||||
* @param {object} [options]
|
||||
* @return {function}
|
||||
* @api public
|
||||
* @public
|
||||
*/
|
||||
|
||||
function urlencoded(options){
|
||||
options = options || {};
|
||||
function urlencoded(options) {
|
||||
var opts = options || {}
|
||||
|
||||
// notice because option default will flip in next major
|
||||
if (options.extended === undefined) {
|
||||
if (opts.extended === undefined) {
|
||||
deprecate('undefined extended: provide extended option')
|
||||
}
|
||||
|
||||
var extended = options.extended !== false
|
||||
var inflate = options.inflate !== false
|
||||
var limit = typeof options.limit !== 'number'
|
||||
? bytes(options.limit || '100kb')
|
||||
: options.limit
|
||||
var type = options.type || 'urlencoded'
|
||||
var verify = options.verify || false
|
||||
var extended = opts.extended !== false
|
||||
var inflate = opts.inflate !== false
|
||||
var limit = typeof opts.limit !== 'number'
|
||||
? bytes.parse(opts.limit || '100kb')
|
||||
: opts.limit
|
||||
var type = opts.type || 'application/x-www-form-urlencoded'
|
||||
var verify = opts.verify || false
|
||||
|
||||
if (verify !== false && typeof verify !== 'function') {
|
||||
throw new TypeError('option verify must be function')
|
||||
@@ -58,8 +62,8 @@ function urlencoded(options){
|
||||
|
||||
// create the appropriate query parser
|
||||
var queryparse = extended
|
||||
? extendedparser(options)
|
||||
: simpleparser(options)
|
||||
? extendedparser(opts)
|
||||
: simpleparser(opts)
|
||||
|
||||
// create the appropriate type checking function
|
||||
var shouldParse = typeof type !== 'function'
|
||||
@@ -94,10 +98,11 @@ function urlencoded(options){
|
||||
// assert charset
|
||||
var charset = getCharset(req) || 'utf-8'
|
||||
if (charset !== 'utf-8') {
|
||||
var err = new Error('unsupported charset "' + charset.toUpperCase() + '"')
|
||||
err.charset = charset
|
||||
err.status = 415
|
||||
return debug('invalid charset'), next(err)
|
||||
debug('invalid charset')
|
||||
next(createError(415, 'unsupported charset "' + charset.toUpperCase() + '"', {
|
||||
charset: charset
|
||||
}))
|
||||
return
|
||||
}
|
||||
|
||||
// read
|
||||
@@ -135,16 +140,15 @@ function extendedparser(options) {
|
||||
var paramCount = parameterCount(body, parameterLimit)
|
||||
|
||||
if (paramCount === undefined) {
|
||||
var err = new Error('too many parameters')
|
||||
err.status = 413
|
||||
debug('too many parameters')
|
||||
throw err
|
||||
throw createError(413, 'too many parameters')
|
||||
}
|
||||
|
||||
var arrayLimit = Math.max(100, paramCount)
|
||||
|
||||
debug('parse extended urlencoding')
|
||||
return parse(body, {
|
||||
allowPrototypes: true,
|
||||
arrayLimit: arrayLimit,
|
||||
depth: Infinity,
|
||||
parameterLimit: parameterLimit
|
||||
@@ -202,12 +206,22 @@ function parameterCount(body, limit) {
|
||||
function parser(name) {
|
||||
var mod = parsers[name]
|
||||
|
||||
if (mod) {
|
||||
if (mod !== undefined) {
|
||||
return mod.parse
|
||||
}
|
||||
|
||||
// load module
|
||||
mod = parsers[name] = require(name)
|
||||
// this uses a switch for static require analysis
|
||||
switch (name) {
|
||||
case 'qs':
|
||||
mod = require('qs')
|
||||
break
|
||||
case 'querystring':
|
||||
mod = require('querystring')
|
||||
break
|
||||
}
|
||||
|
||||
// store to prevent invoking require()
|
||||
parsers[name] = mod
|
||||
|
||||
return mod.parse
|
||||
}
|
||||
@@ -236,10 +250,8 @@ function simpleparser(options) {
|
||||
var paramCount = parameterCount(body, parameterLimit)
|
||||
|
||||
if (paramCount === undefined) {
|
||||
var err = new Error('too many parameters')
|
||||
err.status = 413
|
||||
debug('too many parameters')
|
||||
throw err
|
||||
throw createError(413, 'too many parameters')
|
||||
}
|
||||
|
||||
debug('parse urlencoding')
|
||||
|
||||
Reference in New Issue
Block a user