KTOR 中的 .htaccess 等价物
.htaccess equivalent in KTOR
为了允许在我网站的元素中播放视频,但不允许通过直接播放 link,我在包含源视频的子目录中创建了 .htaccess,仅此而已。使用以下代码:
RewriteEngine On
RewriteCond %{REQUEST_URI} \.(mp4|mp3|avi)$ [NC]
RewriteCond %{HTTP_REFERER} !^http://sample.com/.*$ [NC]
RewriteRule ^.* - [F,L]
我需要对 ktor 服务器执行相同的操作,但不知道如何操作?
任何帮助。谢谢。
我认为最好的方法是在应用程序中添加一个 interceptor
并直接应用这些规则:
intercept(ApplicationCallPipeline.Infrastructure) {
// If call matches conditions
if (call.request.path().endsWith(".mp4") && call.request.headers["Referrer"] != "http://sample.com/video.html") {
// respond with 400 Bad Request
call.respond(HttpStatusCode.BadRequest)
// and stop processing further
finish()
}
}
为了允许在我网站的元素中播放视频,但不允许通过直接播放 link,我在包含源视频的子目录中创建了 .htaccess,仅此而已。使用以下代码:
RewriteEngine On
RewriteCond %{REQUEST_URI} \.(mp4|mp3|avi)$ [NC]
RewriteCond %{HTTP_REFERER} !^http://sample.com/.*$ [NC]
RewriteRule ^.* - [F,L]
我需要对 ktor 服务器执行相同的操作,但不知道如何操作?
任何帮助。谢谢。
我认为最好的方法是在应用程序中添加一个 interceptor
并直接应用这些规则:
intercept(ApplicationCallPipeline.Infrastructure) {
// If call matches conditions
if (call.request.path().endsWith(".mp4") && call.request.headers["Referrer"] != "http://sample.com/video.html") {
// respond with 400 Bad Request
call.respond(HttpStatusCode.BadRequest)
// and stop processing further
finish()
}
}