This commit is contained in:
John Guo
2022-03-10 09:23:01 +08:00
3 changed files with 18 additions and 6 deletions

View File

@ -19,6 +19,7 @@ import (
"github.com/gogf/gf/v2/os/gtime"
"github.com/gogf/gf/v2/os/gview"
"github.com/gogf/gf/v2/text/gregex"
"github.com/gogf/gf/v2/text/gstr"
"github.com/gogf/gf/v2/util/guid"
)
@ -224,8 +225,12 @@ func (r *Request) GetRemoteIp() string {
// GetUrl returns current URL of this request.
func (r *Request) GetUrl() string {
scheme := "http"
if r.TLS != nil {
var (
scheme = "http"
proto = r.Header.Get("X-Forwarded-Proto")
)
if r.TLS != nil || gstr.Equal(proto, "https") {
scheme = "https"
}
return fmt.Sprintf(`%s://%s%s`, scheme, r.Host, r.URL.String())

View File

@ -18,8 +18,12 @@ func (s *Server) handleAccessLog(r *Request) {
if !s.IsAccessLogEnabled() {
return
}
scheme := "http"
if r.TLS != nil {
var (
scheme = "http"
proto = r.Header.Get("X-Forwarded-Proto")
)
if r.TLS != nil || gstr.Equal(proto, "https") {
scheme = "https"
}
s.Logger().File(s.config.AccessLogPattern).
@ -43,9 +47,10 @@ func (s *Server) handleErrorLog(err error, r *Request) {
code = gerror.Code(err)
scheme = "http"
codeDetail = code.Detail()
proto = r.Header.Get("X-Forwarded-Proto")
codeDetailStr string
)
if r.TLS != nil {
if r.TLS != nil || gstr.Equal(proto, "https") {
scheme = "https"
}
if codeDetail != nil {

View File

@ -7,6 +7,8 @@
package ghttp
import (
"fmt"
"github.com/gogf/gf/v2/text/gstr"
)
@ -45,7 +47,7 @@ func (s *Server) swaggerUI(r *Request) {
if r.StaticFile != nil && r.StaticFile.File != nil && r.StaticFile.IsDir {
content := gstr.ReplaceByMap(swaggerUITemplate, map[string]string{
swaggerUIDocURLPlaceHolder: s.config.OpenApiPath,
swaggerUIDocNamePlaceHolder: gstr.TrimRight(r.GetUrl(), "/") + "/" + swaggerUIDocName,
swaggerUIDocNamePlaceHolder: gstr.TrimRight(fmt.Sprintf(`//%s%s`, r.Host, r.Server.config.SwaggerPath), "/") + "/" + swaggerUIDocName,
})
r.Response.Write(content)
r.ExitAll()