接收请求时保留URL路径中多于的斜杠(/)

This commit is contained in:
GoEdgeLab
2021-11-10 10:25:02 +08:00
parent 4ac581bf92
commit d69e4e8fc4

View File

@@ -37,18 +37,13 @@ type HTTPListener struct {
} }
func (this *HTTPListener) Serve() error { func (this *HTTPListener) Serve() error {
handler := http.NewServeMux()
handler.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
this.handleHTTP(writer, request)
})
this.addr = this.Group.Addr() this.addr = this.Group.Addr()
this.isHTTP = this.Group.IsHTTP() this.isHTTP = this.Group.IsHTTP()
this.isHTTPS = this.Group.IsHTTPS() this.isHTTPS = this.Group.IsHTTPS()
this.httpServer = &http.Server{ this.httpServer = &http.Server{
Addr: this.addr, Addr: this.addr,
Handler: handler, Handler: this,
ReadHeaderTimeout: 2 * time.Second, // TODO 改成可以配置 ReadHeaderTimeout: 2 * time.Second, // TODO 改成可以配置
IdleTimeout: 2 * time.Minute, // TODO 改成可以配置 IdleTimeout: 2 * time.Minute, // TODO 改成可以配置
ErrorLog: httpErrorLogger, ErrorLog: httpErrorLogger,
@@ -118,8 +113,8 @@ func (this *HTTPListener) Reload(group *serverconfigs.ServerAddressGroup) {
this.Reset() this.Reset()
} }
// 处理HTTP请求 // ServerHTTP 处理HTTP请求
func (this *HTTPListener) handleHTTP(rawWriter http.ResponseWriter, rawReq *http.Request) { func (this *HTTPListener) ServeHTTP(rawWriter http.ResponseWriter, rawReq *http.Request) {
// 域名 // 域名
reqHost := rawReq.Host reqHost := rawReq.Host