0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-03-11 02:12:21 -05:00

Refactored content-disposition header handling in API v2 (#10374)

closes https://github.com/TryGhost/Ghost/issues/10331

- Left only a filename part to be handled by controller configuration, the rest was extracted to more generic headers layer
This commit is contained in:
Naz Gargol 2019-01-14 18:05:16 +00:00 committed by GitHub
parent ceeb78b85b
commit 48d6e7298a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 8 deletions

View file

@ -18,14 +18,14 @@ const disposition = {
}
return {
'Content-Disposition': value,
'Content-Disposition': `Attachment; filename="${value}"`,
'Content-Type': 'text/csv'
};
},
json(result, options = {}) {
return {
'Content-Disposition': options.value,
'Content-Disposition': `Attachment; filename="${options.value}"`,
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(JSON.stringify(result))
};
@ -33,7 +33,7 @@ const disposition = {
yaml(result, options = {}) {
return {
'Content-Disposition': options.value,
'Content-Disposition': `Attachment; filename="${options.value}"`,
'Content-Type': 'application/yaml',
'Content-Length': Buffer.byteLength(JSON.stringify(result))
};

View file

@ -177,7 +177,7 @@ module.exports = {
headers: {
disposition: {
type: 'yaml',
value: 'Attachment; filename="routes.yaml"'
value: 'routes.yaml'
}
},
response: {

View file

@ -143,7 +143,7 @@ const subscribers = {
type: 'csv',
value() {
const datetime = (new Date()).toJSON().substring(0, 10);
return `Attachment; filename="subscribers.${datetime}.csv"`;
return `subscribers.${datetime}.csv`;
}
}
},

View file

@ -13,7 +13,7 @@ describe('Unit: api/shared/headers', function () {
return shared.headers.get({}, {disposition: {type: 'json', value: 'value'}})
.then(result => {
result.should.eql({
'Content-Disposition': 'value',
'Content-Disposition': 'Attachment; filename=\"value\"',
'Content-Type': 'application/json',
'Content-Length': 2
});
@ -24,7 +24,7 @@ describe('Unit: api/shared/headers', function () {
return shared.headers.get({}, {disposition: {type: 'csv', value: 'my.csv'}})
.then(result => {
result.should.eql({
'Content-Disposition': 'my.csv',
'Content-Disposition': 'Attachment; filename=\"my.csv\"',
'Content-Type': 'text/csv'
});
});
@ -34,7 +34,7 @@ describe('Unit: api/shared/headers', function () {
return shared.headers.get('yaml file', {disposition: {type: 'yaml', value: 'my.yaml'}})
.then(result => {
result.should.eql({
'Content-Disposition': 'my.yaml',
'Content-Disposition': 'Attachment; filename=\"my.yaml\"',
'Content-Type': 'application/yaml',
'Content-Length': 11
});