go - FileServer 处理程序是否仅服务于您指定目录中的内容?

标签 go handler fileserver

例如,用户可以将您的 url 与 linux 命令一起放在文件夹/目录中吗?

假设我的服务器包括:

bin/
    serverfile.go
    ...
public/
    index.html
    style.css

“www.example.com/../bin/etc”

与 serverfile.go 组成:

 pacakage main
 import "net/http"

 func main() {
     htttp.ListenAndServe(":8000", http.FileServer(http.Dir("public")))
 }

最佳答案

http.FileServer 禁止突破您指定的根目录。

相比之下,您可以使用 http.ServeFile 构建自己的文件服务器,这可能是一项危险的任务。

另见 Golang. What to use? http.ServeFile(..) or http.FileServer(..)?

关于go - FileServer 处理程序是否仅服务于您指定目录中的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44913349/

相关文章:

android - 从服务访问 UI 线程处理程序

java - 具有动态 ID 和名称字段的表单

java - Android Studio 错误 : Can't create handler inside thread that has not called Looper. 准备()

java - 从嵌入式 Jetty 中的备用路径提供静态文件

go - 我们如何确定 "last"工作进程/线程在 Go 中何时完成?

go - 我不明白代码 : result = quote123(func(x int) string { return fmt. Sprintf ("%b", x) })

php - 为什么使用 PHP 上传到 FTP 服务器的图像会损坏?

events - 有 connect.static 的事件吗?

go - Go中下划线(空白标识符)的含义

ubuntu - ubuntu 17.10下Go安装tensorflow报错