Merge pull request #1993 from davehagler/master

Fix Issue #1991 filename parameter in content disposition response he…
This commit is contained in:
Tony Tam
2016-02-25 09:10:29 -08:00

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;