I'm developing an app where I want to limit the access to assets. I have created additional folder
secret/
which holds the data. Then I created route
/media/secret/*file controllers.Media.file(file)
and controller Media
public class Media extends Controller
{
@Authenticate
public Result file(String file)
{
String path = /home/foo/secretpath/
File f = new File(path, file);
if(!f.exists())
{
return notFound();
}
return ok(f, true);
}
This kinda works, only problem is there is no Etag or cache control. Checking the Assets.scala implementation (https://github.com/playframework/playframework/blob/master/framework/src/play/src/main/scala/play/api/controllers/Assets.scala) everything is already developed here. My question is
- Should I write additional code to implement Etag and Cache-Control? If yes, how? I cannot read scala
- If there is a way to use Assets class, how to make it work? Returning Action will not trigger @Authenticate so I can validate if its ok or not.