in server/src/main/scala/com/twitter/server/handler/ResourceHandler.scala [38:63]
def apply(req: Request): Future[Response] = {
val uri = Uri.fromRequest(req)
val path = uri.path.stripPrefix(baseRequestPath)
if (path.contains(".."))
return newResponse(
status = Status.BadRequest,
contentType = "text/plain;charset=UTF-8",
content = Buf.Utf8("Invalid path!")
)
resourceResolver
.lift(path)
.map { is =>
val (charset, mime) = meta(path)
val source = Source.fromInputStream(is, charset.toString).withClose(() => is.close())
FuturePool.unboundedPool {
val bytes = source.mkString.getBytes(charset)
source.close()
newResponse(contentType = mime, content = Buf.ByteArray.Owned(bytes))
}.flatten
}
.getOrElse {
new404("resource not found")
}
}