Allow header object instead of just content type in server responses
This commit is contained in:
parent
05843bb093
commit
81ab8f7b20
1 changed files with 12 additions and 5 deletions
|
@ -333,7 +333,7 @@ Zotero.Server.DataListener.prototype._bodyData = function() {
|
|||
/**
|
||||
* Generates the response to an HTTP request
|
||||
*/
|
||||
Zotero.Server.DataListener.prototype._generateResponse = function(status, contentType, body) {
|
||||
Zotero.Server.DataListener.prototype._generateResponse = function (status, contentTypeOrHeaders, body) {
|
||||
var response = "HTTP/1.0 "+status+" "+Zotero.Server.responseCodes[status]+"\r\n";
|
||||
|
||||
// Translation server
|
||||
|
@ -363,8 +363,15 @@ Zotero.Server.DataListener.prototype._generateResponse = function(status, conten
|
|||
}
|
||||
}
|
||||
|
||||
if(contentType) {
|
||||
response += "Content-Type: "+contentType+"\r\n";
|
||||
if (contentTypeOrHeaders) {
|
||||
if (typeof contentTypeOrHeaders == 'string') {
|
||||
contentTypeOrHeaders = {
|
||||
'Content-Type': contentTypeOrHeaders
|
||||
};
|
||||
}
|
||||
for (let header in contentTypeOrHeaders) {
|
||||
response += `${header}: ${contentTypeOrHeaders[header]}\r\n`;
|
||||
}
|
||||
}
|
||||
|
||||
if(body) {
|
||||
|
@ -439,9 +446,9 @@ Zotero.Server.DataListener.prototype._processEndpoint = Zotero.Promise.coroutine
|
|||
}
|
||||
|
||||
// set up response callback
|
||||
var sendResponseCallback = function (code, contentType, arg, options) {
|
||||
var sendResponseCallback = function (code, contentTypeOrHeaders, arg, options) {
|
||||
this._requestFinished(
|
||||
this._generateResponse(code, contentType, arg),
|
||||
this._generateResponse(code, contentTypeOrHeaders, arg),
|
||||
options
|
||||
);
|
||||
}.bind(this);
|
||||
|
|
Loading…
Add table
Reference in a new issue