Skip to content

Commit d673d5d

Browse files
committed
Merge pull request #479 from tillig/patch-2
Fix handling for jQuery response headers
2 parents 1b89ab4 + 8ad843f commit d673d5d

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
@@ -1290,14 +1290,25 @@ JQueryHttpClient.prototype.execute = function(obj) {
12901290

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

1299-
out = {
1300-
headers: headers,
1311+
var out = {
13011312
url: request.url,
13021313
method: request.method,
13031314
status: response.status,

0 commit comments

Comments
 (0)