Fix handling for jQuery response headers
Fixes the way response headers are parsed when using the jQuery client. Enables the response headers to be properly viewed in the UI. Previous logic consistently returned an empty set of headers. Includes minor changes to allow the use of JS strict mode, at least for this function.
This commit is contained in:
@@ -1290,14 +1290,25 @@ JQueryHttpClient.prototype.execute = function(obj) {
|
|||||||
|
|
||||||
obj.data = obj.body;
|
obj.data = obj.body;
|
||||||
obj.complete = function(response, textStatus, opts) {
|
obj.complete = function(response, textStatus, opts) {
|
||||||
headers = {};
|
var headers = {},
|
||||||
headerArray = response.getAllResponseHeaders().split(":");
|
headerArray = response.getAllResponseHeaders().split("\n");
|
||||||
|
|
||||||
for(var i = 0; i < headerArray.length / 2; i++)
|
for(var i = 0; i < headerArray.length; i++) {
|
||||||
headers[headerArray[i] = headerArray[i+1]];
|
var toSplit = headerArray[i].trim();
|
||||||
|
if(toSplit.length === 0)
|
||||||
|
continue;
|
||||||
|
var separator = toSplit.indexOf(":");
|
||||||
|
if(separator === -1) {
|
||||||
|
// Name but no value in the header
|
||||||
|
headers[toSplit] = null;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
var name = toSplit.substring(0, separator).trim(),
|
||||||
|
value = toSplit.substring(separator + 1).trim();
|
||||||
|
headers[name] = value;
|
||||||
|
}
|
||||||
|
|
||||||
out = {
|
var out = {
|
||||||
headers: headers,
|
|
||||||
url: request.url,
|
url: request.url,
|
||||||
method: request.method,
|
method: request.method,
|
||||||
status: response.status,
|
status: response.status,
|
||||||
|
|||||||
Reference in New Issue
Block a user