优化HTTP2、HTTP跳转

This commit is contained in:
刘祥超
2023-04-07 15:09:06 +08:00
parent 6da9cb6dcf
commit 7db0c8cf62
2 changed files with 11 additions and 9 deletions

View File

@@ -208,3 +208,13 @@ func httpAcceptEncoding(acceptEncodings string, encoding string) bool {
} }
return false return false
} }
// 跳转到某个URL
func httpRedirect(writer http.ResponseWriter, req *http.Request, url string, code int) {
if len(writer.Header().Get("Content-Type")) == 0 {
// 设置Content-Type是为了让页面不输出链接
writer.Header().Set("Content-Type", "text/html; charset=utf-8")
}
http.Redirect(writer, req, url, code)
}

View File

@@ -4,9 +4,7 @@ import (
"context" "context"
"crypto/tls" "crypto/tls"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/TeaOSLab/EdgeNode/internal/remotelogs"
"github.com/iwind/TeaGo/Tea" "github.com/iwind/TeaGo/Tea"
"golang.org/x/net/http2"
"io" "io"
"log" "log"
"net" "net"
@@ -84,13 +82,7 @@ func (this *HTTPListener) Serve() error {
if this.isHTTPS { if this.isHTTPS {
this.httpServer.TLSConfig = this.buildTLSConfig() this.httpServer.TLSConfig = this.buildTLSConfig()
// support http/2 err := this.httpServer.ServeTLS(this.Listener, "", "")
err := http2.ConfigureServer(this.httpServer, nil)
if err != nil {
remotelogs.Error("HTTP_LISTENER", "configure http2 error: "+err.Error())
}
err = this.httpServer.ServeTLS(this.Listener, "", "")
if err != nil && err != http.ErrServerClosed { if err != nil && err != http.ErrServerClosed {
return err return err
} }