Fix Issue #1991 filename parameter in content disposition response header

This commit is contained in:
davehagler00
2016-02-24 17:17:31 -05:00
parent 0d0864f310
commit 5809c87cb6

View File

@@ -718,6 +718,15 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
var fileName = response.url.substr(response.url.lastIndexOf('/') + 1); var fileName = response.url.substr(response.url.lastIndexOf('/') + 1);
var download = [type, fileName, href].join(':'); var download = [type, fileName, href].join(':');
// Use filename from response header
var disposition = headers['content-disposition'] || headers['Content-Disposition'];
if(typeof disposition !== 'undefined') {
var responseFilename = /filename=([^;]*);?/.exec(disposition);
if(responseFilename != null && responseFilename.length > 1) {
download = responseFilename[1];
}
}
a.setAttribute('href', href); a.setAttribute('href', href);
a.setAttribute('download', download); a.setAttribute('download', download);
a.innerText = 'Download ' + fileName; a.innerText = 'Download ' + fileName;