Permalink
Browse files

consolidate util calls

  • Loading branch information...
jeremydaly committed May 16, 2018
1 parent c40d26c commit c8a8c2e21fd917c077f78ea33edd1faa6bf19b47
Showing with 10 additions and 9 deletions.
  1. +10 −9 lib/response.js
@@ -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
@@ -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
}

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

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

this.location(path)
.status(statusCode)
@@ -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 : ''
@@ -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)
}
@@ -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
}

0 comments on commit c8a8c2e

Please sign in to comment.