mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
Merge pull request #1657 from houseme/fix-1655
fix: server access logs contain the protocol used between the server …
This commit is contained in:
@ -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())
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -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.URL.String()), "/") + "/" + swaggerUIDocName,
|
||||
})
|
||||
r.Response.Write(content)
|
||||
r.ExitAll()
|
||||
|
||||
Reference in New Issue
Block a user