Skip to content

Commit

Permalink
consolidate util calls
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydaly committed May 16, 2018
1 parent c40d26c commit c8a8c2e
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions lib/response.js
Expand Up @@ -6,10 +6,11 @@
* @license MIT
*/

const escapeHtml = require('./utils.js').escapeHtml
const encodeUrl = require('./utils.js').encodeUrl
const encodeBody = require('./utils.js').encodeBody
const mimeLookup = require('./utils.js').mimeLookup
const UTILS = require('./utils.js')
// const escapeHtml = require('./utils.js').escapeHtml
// const encodeUrl = require('./utils.js').encodeUrl
// const encodeBody = require('./utils.js').encodeBody
// const mimeLookup = require('./utils.js').mimeLookup

const fs = require('fs') // Require Node.js file system
const path = require('path') // Require Node.js path
Expand Down Expand Up @@ -91,7 +92,7 @@ class RESPONSE {

// Convenience method for setting Location header
location(path) {
this.header('Location',encodeUrl(path))
this.header('Location',UTILS.encodeUrl(path))
return this
}

Expand All @@ -109,7 +110,7 @@ class RESPONSE {
}
}

let url = escapeHtml(path)
let url = UTILS.escapeHtml(path)

this.location(path)
.status(statusCode)
Expand All @@ -123,7 +124,7 @@ class RESPONSE {

// Set the name and value of the cookie
let cookieString = (typeof name !== 'String' ? name.toString() : name)
+ '=' + encodeURIComponent(encodeBody(value))
+ '=' + encodeURIComponent(UTILS.encodeBody(value))

// domain (String): Domain name for the cookie
cookieString += opts.domain ? '; Domain=' + opts.domain : ''
Expand Down Expand Up @@ -316,7 +317,7 @@ class RESPONSE {

// Convenience method for setting type
type(type) {
let mimeType = mimeLookup(type,this.app._mimeTypes)
let mimeType = UTILS.mimeLookup(type,this.app._mimeTypes)
if (mimeType) {
this.header('Content-Type',mimeType)
}
Expand Down Expand Up @@ -359,7 +360,7 @@ class RESPONSE {
const response = {
headers: this._headers,
statusCode: this._statusCode,
body: this.app.request && this.app.request.method === 'HEAD' ? '' : encodeBody(body),
body: this.app.request && this.app.request.method === 'HEAD' ? '' : UTILS.encodeBody(body),
isBase64Encoded: this._isBase64
}

Expand Down

0 comments on commit c8a8c2e

Please sign in to comment.