Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit dfa2550

Browse files
committed
Allow streaming of non UTF-8 data in the GUIServlet
This fixes a bug when the gui was used with the bootstrap launcher running on windows. Then specific files were always failing with a 500 server error. One of these files were e.g. /vendor.js. By not converting all bytes to a string and directly returning them this issue is fixed for me.
1 parent 1506814 commit dfa2550

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/main/scala/org/codeoverflow/chatoverflow/ui/web/GUIServlet.scala

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.codeoverflow.chatoverflow.ui.web
22

3-
import java.io.File
3+
import java.io.{BufferedInputStream, File}
44
import java.net.URI
55
import java.util.jar.JarFile
66

@@ -9,8 +9,6 @@ import org.eclipse.jetty.http.MimeTypes
99
import org.eclipse.jetty.util.Loader
1010
import org.scalatra.{ActionResult, ScalatraServlet}
1111

12-
import scala.io.Source
13-
1412
/**
1513
* A servlet to serve the GUI files of the chatoverflow-gui dir from the classpath.
1614
* This directory is provided if the gui jar is added on the classpath.
@@ -51,7 +49,12 @@ class GUIServlet extends ScalatraServlet with WithLogger {
5149
ActionResult(404, s"Requested file '$path' couldn't be found in the GUI jar!", Map())
5250
} else {
5351
contentType = MimeTypes.getDefaultMimeByExtension(entry.getName)
54-
Source.fromInputStream(jarFile.getInputStream(entry)).mkString
52+
val is = new BufferedInputStream(jarFile.getInputStream(entry))
53+
val os = response.getOutputStream
54+
55+
Stream.continually(is.read)
56+
.takeWhile(_ != -1)
57+
.foreach(os.write)
5558
}
5659

5760
response.setHeader("Cache-Control", "no-cache,no-store")

0 commit comments

Comments
 (0)