v0.2.0.pre1
Pre-release
Pre-release
使用http.ReadRequest读请求,添加并使用ResponseWriter响应,完善超时机制,添加Server.NewListener,修改部分命名,优化程序
go get github.com/bddjr/[email protected]
// Check Host header
srv.HttpOnHttpsPortErrorHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
r.URL.Host = r.Host
switch r.URL.Hostname() {
case "localhost":
http.Redirect(w, r, "https://"+r.Host+r.URL.RequestURI(), http.StatusFound)
case "www.localhost", "127.0.0.1":
s := "https://localhost"
if port := r.URL.Port(); port != "" {
s += ":" + port
}
s += r.URL.RequestURI()
http.Redirect(w, r, s, http.StatusFound)
default:
w.WriteHeader(421)
}
})