8000 feat!: add setContentLengthLong to VaadinResponse (#21445) · vaadin/flow@9dae733 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 9dae733

Browse files
authored
feat!: add setContentLengthLong to VaadinResponse (#21445)
Add the setContentLengthLong method to VaadinResponse.
1 parent c7c4645 commit 9dae733

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

flow-server/src/main/java/com/vaadin/flow/server/VaadinResponse.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,16 @@ public interface VaadinResponse {
171171
*/
172172
void setContentLength(int len);
173173

174+
/**
175+
* Sets the length of the content body in the response In HTTP servlets,
176+
* this method sets the HTTP Content-Length header.
177+
*
178+
* @param len
179+
* a long specifying the length of the content being returned to
180+
* the client
181+
*/
182+
void setContentLengthLong(long len);
183+
174184
/**
175185
* Sets all conceivable headers that might prevent a response from being
176186
* stored in any caches.

flow-server/src/main/java/com/vaadin/flow/server/streams/FileDownloadHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void handleDownloadRequest(DownloadEvent downloadEvent) {
7575
throw new UncheckedIOException(ioe);
7676
}
7777
response.setContentType(downloadEvent.getContentType());
78-
response.setContentLength(Math.toIntExact(file.length()));
78+
response.setContentLengthLong(file.length());
7979
}
8080

8181
@Override

flow-server/src/test/java/com/vaadin/flow/server/streams/FileDownloadHandlerTest.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import com.vaadin.flow.server.VaadinRequest;
3939
import com.vaadin.flow.server.VaadinResponse;
4040
import com.vaadin.flow.server.VaadinSession;
41+
import com.vaadin.flow.server.frontend.FrontendUtils;
4142

4243
public class FileDownloadHandlerTest {
4344

@@ -127,7 +128,7 @@ public void onError(TransferContext context,
127128
transferredBytesRecords.stream().mapToLong(Long::longValue)
128129
.toArray());
129130
Mockito.verify(response).setContentType("application/octet-stream");
130-
Mockito.verify(response).setContentLength(165000);
131+
Mockito.verify(response).setContentLengthLong(165000);
131132
}
132133

133134
@Test
@@ -158,8 +159,11 @@ public void onComplete(TransferContext context,
158159
public void onError(TransferContext context,
159160
IOException reason) {
160161
invocations.add("onError");
161-
Assert.assertEquals(
162-
"non-existing-file (No such file or directory)",
162+
String expectedMessage = "non-existing-file (No such file or directory)";
163+
if (FrontendUtils.isWindows()) {
164+
expectedMessage = "non-existing-file (The system cannot find the file specified)";
165+
}
166+
Assert.assertEquals(expectedMessage,
163167
reason.getMessage());
164168
}
165169
});

0 commit comments

Comments
 (0)
0