授权文件传输服务中间件.
(next http.Handler)
| 89 | |
| 90 | // 授权文件传输服务中间件. |
| 91 | func AuthorizeShareFileMiddleware(next http.Handler) http.Handler { |
| 92 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 93 | user := strings.Split(r.RemoteAddr, ":")[0] + "+" + r.Header.Get("User-Agent") |
| 94 | if AuthorizeUser(user) { |
| 95 | http.Redirect(w, r, "/login/", http.StatusMovedPermanently) |
| 96 | return |
| 97 | } |
| 98 | next.ServeHTTP(w, r) |
| 99 | }) |
| 100 | } |
| 101 | |
| 102 | |
| 103 | // 禁止 API 使用 ".." 或绝对路径越界访问共享文件的夹祖父目录. |
no test coverage detected