summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorHenri Sara <hesara@vaadin.com>2013-04-25 11:00:28 +0300
committerHenri Sara <hesara@vaadin.com>2013-04-25 11:00:28 +0300
commit20e9c8e24ff1e957a35ecc9527071af82c078328 (patch)
tree8fcea6851376b6528aa40f349bab5499805217f6 /server
parentc1cf0cb575703307efb88c90f35d6e3c80e44423 (diff)
downloadvaadin-framework-20e9c8e24ff1e957a35ecc9527071af82c078328.tar.gz
vaadin-framework-20e9c8e24ff1e957a35ecc9527071af82c078328.zip
Add content length header for static resources (#11699)
Change-Id: Ie307198a05e5c4f1b8bd74ec17185b9086ff0577
Diffstat (limited to 'server')
-rw-r--r--server/src/com/vaadin/server/VaadinServlet.java32
1 files changed, 25 insertions, 7 deletions
diff --git a/server/src/com/vaadin/server/VaadinServlet.java b/server/src/com/vaadin/server/VaadinServlet.java
index 4fde870f74..35d5fd7cc1 100644
--- a/server/src/com/vaadin/server/VaadinServlet.java
+++ b/server/src/com/vaadin/server/VaadinServlet.java
@@ -896,14 +896,32 @@ public class VaadinServlet extends HttpServlet implements Constants {
protected void writeStaticResourceResponse(HttpServletRequest request,
HttpServletResponse response, URL resourceUrl) throws IOException {
// Write the resource to the client.
- final OutputStream os = response.getOutputStream();
- final byte buffer[] = new byte[DEFAULT_BUFFER_SIZE];
- int bytes;
- InputStream is = resourceUrl.openStream();
- while ((bytes = is.read(buffer)) >= 0) {
- os.write(buffer, 0, bytes);
+ URLConnection connection = resourceUrl.openConnection();
+ try {
+ int length = connection.getContentLength();
+ if (length >= 0) {
+ response.setContentLength(length);
+ }
+ } catch (Throwable e) {
+ // This can be ignored, content length header is not required.
+ // Need to close the input stream because of
+ // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4257700 to
+ // prevent it from hanging, but that is done below.
+ }
+
+ InputStream is = connection.getInputStream();
+ try {
+ final OutputStream os = response.getOutputStream();
+ final byte buffer[] = new byte[DEFAULT_BUFFER_SIZE];
+ int bytes;
+ while ((bytes = is.read(buffer)) >= 0) {
+ os.write(buffer, 0, bytes);
+ }
+ } finally {
+ if (is != null) {
+ is.close();
+ }
}
- is.close();
}
private URL findResourceURL(String filename, ServletContext sc)