go - 我如何处理 golang http 服务器中的意外错误
问题描述
这是 golang 中的简单 http 服务器。
package main
import (
"fmt"
"net/http"
)
func main() {
http.HandleFunc("/", func (w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Welcome to my website!")
})
fs := http.FileServer(http.Dir("static/"))
http.Handle("/static/", http.StripPrefix("/static/", fs))
http.ListenAndServe(":80", nil)
}
我的问题是这个,为什么当我%
输入 url 时。Go服务器导致400 Bad Request
错误
例子:
http://localhost:80/anythink%
当有人在 go http 服务器中请求这样的错误链接时,会导致安全信息泄露。如果足够聪明地检测服务器端类型。主要问题是如何处理此错误