【问题标题】:.htaccess equivalent in KTORKTOR 中的 .htaccess 等效项
【发布时间】:2018-06-25 02:26:21
【问题描述】:

为了允许在我的网站的元素中播放视频,但不允许通过直接链接播放,我在包含源视频的子目录中创建了 .htaccess,仅此而已。使用以下代码:

RewriteEngine On
RewriteCond %{REQUEST_URI} \.(mp4|mp3|avi)$ [NC]
RewriteCond %{HTTP_REFERER} !^http://sample.com/.*$ [NC]
RewriteRule ^.* - [F,L]

我需要对ktor服务器做同样的事情,但不知道怎么做?

任何帮助。谢谢。

【问题讨论】:

    标签: ktor


    【解决方案1】:

    我认为最好的方法是在应用程序中添加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()
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-13
      • 2010-09-20
      • 2011-12-27
      • 1970-01-01
      • 2016-07-13
      • 1970-01-01
      • 1970-01-01
      • 2013-12-16
      相关资源
      最近更新 更多