Yes, sending a 242KB file. I have spray routing configured to not chunk this sized file:
spray.routing {
file-chunking-threshold-size = 512k
}
yet getFromFile still attempts chunking and I get the error mentioned in this thread.
Strangely, getFromResource correctly observes this setting and does not even attempt to chunk it. Looking at the two methods, I don’t see any glaring differences:
def getFromFile(file: File, contentType: ContentType)
(implicit settings: RoutingSettings, refFactory: ActorRefFactory): Route =
get {
detach() {
if (file.isFile && file.canRead) {
autoChunked.apply {
conditionalFor(file.length, file.lastModified).apply {
withRangeSupport() {
complete(HttpEntity(contentType, HttpData(file)))
}
}
}
} else reject
}
}
def getFromResource(resourceName: String, contentType: ContentType)
(implicit refFactory: ActorRefFactory): Route =
if (!resourceName.endsWith("/"))
get {
detach() {
val theClassLoader = actorSystem(refFactory).dynamicAccess.classLoader
theClassLoader.getResource(resourceName) match {
case null ⇒ reject
case url ⇒
val (length, lastModified) = {
val conn = url.openConnection()
try {
conn.setUseCaches(false) // otherwise the JDK will keep the JAR file open when we close!
val len = conn.getContentLength
val lm = conn.getLastModified
len -> lm
} finally { conn.getInputStream.close() }
}
implicit val bufferMarshaller = BasicMarshallers.byteArrayMarshaller(contentType)
autoChunked.apply { // TODO: add implicit RoutingSettings to method and use here
conditionalFor(length, lastModified).apply {
withRangeSupport() {
complete {
// readAllBytes closes the InputStream when done, which ends up closing the JAR file
// if caching has been disabled on the connection
val is = url.openStream()
try { FileUtils.readAllBytes(is) }
finally { is.close() }
}
}
}
}
}
}
}
else reject // don't serve the content of resource "directories"
--
You received this message because you are subscribed to a topic in the Google Groups "spray.io User List" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/spray-user/ktEUtjs9Nks/unsubscribe.
To unsubscribe from this group and all its topics, send an email to spray-user+...@googlegroups.com.
Visit this group at http://groups.google.com/group/spray-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/spray-user/CAKF7HnfuXa8Bv%2B4nbR20JfFHLHgDK3_p1R0rt_J%3DMZ7%3DYrwXQQ%40mail.gmail.com.
To unsubscribe from this group and all its topics, send an email to spray-user+unsubscribe@googlegroups.com.
To unsubscribe from this group and all its topics, send an email to spray-user+...@googlegroups.com.