Comparing version 0.0.46 to 0.0.47
@@ -20,3 +20,14 @@ | ||
function sendResponse (response, status, data, mime_type, responseFilePath) { | ||
if (status && status.success===false){ | ||
// warn if headers have been sent already | ||
if (response.headerSent === true){ | ||
// this seems to happen with the FTP module | ||
console.error('Error: sendResponse could not set headers because they have been sent already.', status); | ||
} | ||
// warn and stop if response has been sent already | ||
if (response.finished === true){ | ||
// this seems to happen with the FTP module | ||
console.error('Error: sendResponse could not send response because it has been sent already.', status); | ||
return; | ||
} | ||
if (status && status.success === false){ | ||
var code; | ||
@@ -34,7 +45,12 @@ if (status.code) code = status.code; | ||
// mime type | ||
response.setHeader('Content-Type', mime_type); | ||
if(response.headerSent !== true) { | ||
response.setHeader('Content-Type', mime_type); | ||
} | ||
} | ||
else if (data){ | ||
// default mime type is json (only when the data is not a file, because files have their own content type) | ||
response.setHeader('Content-Type', 'application/json; charset=utf8'); | ||
if(response.headerSent !== true) { | ||
console.log('aaa'); | ||
response.setHeader('Content-Type', 'application/json; charset=utf8'); | ||
} | ||
data = JSON.stringify(data); | ||
@@ -41,0 +57,0 @@ } |
{ | ||
"name": "unifile", | ||
"description": "Express middleware to provide a common API for cloud storage services. ", | ||
"version": "0.0.46", | ||
"version": "0.0.47", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "Alex Hoyau aka lexoyo" |
@@ -182,2 +182,3 @@ #Unifile, unified access to cloud storage services. | ||
* doc: https://www.dreamfactory.com/developers/live_API | ||
* mock, doc et tests: http://apiblueprint.org/ | ||
* https://npmjs.org/package/social-cms-backend | ||
@@ -184,0 +185,0 @@ * tests http://stackoverflow.com/questions/11520170/unit-testing-oauth-js-with-mocha |
103024
2387
197