Skip to content

Commit 36514ff

Browse files
committed
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.
1 parent 4bef758 commit 36514ff

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

lib/swagger.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,14 +1289,25 @@ JQueryHttpClient.prototype.execute = function(obj) {
12891289

12901290
obj.data = obj.body;
12911291
obj.complete = function(response, textStatus, opts) {
1292-
headers = {};
1293-
headerArray = response.getAllResponseHeaders().split(":");
1294-
1295-
for(var i = 0; i < headerArray.length / 2; i++)
1296-
headers[headerArray[i] = headerArray[i+1]];
1292+
var headers = {},
1293+
headerArray = response.getAllResponseHeaders().split("\n");
1294+
1295+
for(var i = 0; i < headerArray.length; i++) {
1296+
var toSplit = headerArray[i].trim();
1297+
if(toSplit.length === 0)
1298+
continue;
1299+
var separator = toSplit.indexOf(":");
1300+
if(separator === -1) {
1301+
// Name but no value in the header
1302+
headers[toSplit] = null;
1303+
continue;
1304+
}
1305+
var name = toSplit.substring(0, separator).trim(),
1306+
value = toSplit.substring(separator + 1).trim();
1307+
headers[name] = value;
1308+
}
12971309

1298-
out = {
1299-
headers: headers,
1310+
var out = {
13001311
url: request.url,
13011312
method: request.method,
13021313
status: response.status,

0 commit comments

Comments
 (0)