Skip to content

Commit a008b69

Browse files
fix: add attachment name in download endpoint (#147)
Signed-off-by: Joris Mancini <joris.mancini_externe@rte-france.com>
1 parent c43eb13 commit a008b69

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/main/java/com/powsybl/caseserver/Utils.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
package com.powsybl.caseserver;
88

99
import com.powsybl.commons.datasource.DataSourceUtil;
10+
import org.springframework.http.ContentDisposition;
1011
import org.springframework.http.HttpHeaders;
1112

1213
import java.util.List;
@@ -61,6 +62,9 @@ public static HttpHeaders buildHeaders(String name, Boolean isUploadedAsPlainFil
6162
if (Boolean.TRUE.equals(isUploadedAsPlainFile)) {
6263
headers.add(HttpHeaders.CONTENT_ENCODING, GZIP_ENCODING);
6364
}
65+
headers.setContentDisposition(
66+
ContentDisposition.attachment().filename(name).build()
67+
);
6468
return headers;
6569
}
6670
}

src/test/java/com/powsybl/caseserver/service/CaseControllerTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,11 @@
5050

5151
import static com.powsybl.caseserver.Utils.ZIP_EXTENSION;
5252
import static com.powsybl.caseserver.service.CaseService.DELIMITER;
53-
import static org.hamcrest.Matchers.hasSize;
54-
import static org.hamcrest.Matchers.startsWith;
53+
import static org.hamcrest.Matchers.*;
5554
import static org.junit.Assert.assertEquals;
5655
import static org.junit.jupiter.api.Assertions.*;
5756
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
58-
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
59-
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
57+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
6058

6159
/**
6260
* @author Abdelsalem Hedhili <abdelsalem.hedhili at rte-france.com>
@@ -272,6 +270,7 @@ void test() throws Exception {
272270
byte[] expectedGzippedBytes = byteArrayOutputStream.toByteArray();
273271
mvc.perform(get(GET_CASE_URL, firstCaseUuid))
274272
.andExpect(status().isOk())
273+
.andExpect(header().string("Content-Disposition", "attachment; filename=\"" + TEST_CASE + "\""))
275274
.andExpect(content().bytes(expectedGzippedBytes))
276275
.andReturn();
277276
}
@@ -280,6 +279,7 @@ void test() throws Exception {
280279
mvc.perform(get(GET_CASE_URL, gzipCaseUuid))
281280
.andExpect(status().isOk())
282281
.andExpect(content().bytes(getClass().getResourceAsStream("/" + TEST_GZIP_CASE).readAllBytes()))
282+
.andExpect(header().string("Content-Disposition", "attachment; filename=\"" + TEST_GZIP_CASE + "\""))
283283
.andReturn();
284284
assertNotNull(outputDestination.receive(1000, caseImportDestination));
285285

0 commit comments

Comments
 (0)