Skip to content

Commit 829a22c

Browse files
add-dynamic-filename-in-reponse (#5)
1 parent 28dc619 commit 829a22c

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/templates/core/fetch/getResponseBody.hbs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
async function getResponseBody(response: Response): Promise<any> {
22
try {
33
const contentType = response.headers.get('Content-Type');
4+
const contentDisposition = response.headers.get('Content-Disposition');
5+
46
if (contentType) {
57

68
const jsonTypes = ['application/json', 'application/problem+json']
@@ -12,9 +14,15 @@ async function getResponseBody(response: Response): Promise<any> {
1214

1315
if (isJSON) {
1416
return await response.json();
15-
} else if (isBlob) {
16-
return await response.arrayBuffer();
17-
} else {
17+
}else if (isBlob) {
18+
const arrayBuffer = await response.arrayBuffer();
19+
20+
if(contentDisposition) {
21+
return [contentDisposition, arrayBuffer];
22+
} else {
23+
return arrayBuffer;
24+
}
25+
} else {
1826
return await response.text();
1927
}
2028
}

0 commit comments

Comments
 (0)