MCPcopy
hub / github.com/gofiber/fiber / Scheme

Method Scheme

req.go:905–942  ·  view source on GitHub ↗

Scheme contains the request protocol string: http or https for TLS requests. Please use Config.TrustProxy to prevent header spoofing if your app is behind a proxy.

()

Source from the content-addressed store, hash-verified

903// Scheme contains the request protocol string: http or https for TLS requests.
904// Please use Config.TrustProxy to prevent header spoofing if your app is behind a proxy.
905func (r *DefaultReq) Scheme() string {
906 ctx := r.c.fasthttp
907 if ctx.IsTLS() {
908 return schemeHTTPS
909 }
910 if !r.IsProxyTrusted() {
911 return schemeHTTP
912 }
913
914 app := r.c.app
915 scheme := schemeHTTP
916 const lenXHeaderName = 12
917 for key, val := range ctx.Request.Header.All() {
918 if len(key) < lenXHeaderName {
919 continue // Neither "X-Forwarded-" nor "X-Url-Scheme"
920 }
921 switch {
922 case utils.EqualFold(key[:len(xForwardedPrefix)], xForwardedPrefix):
923 if utils.EqualFold(key, xForwardedProtoBytes) ||
924 utils.EqualFold(key, xForwardedProtocolBytes) {
925 v := app.toString(val)
926 if before, _, found := strings.Cut(v, ","); found {
927 scheme = utils.TrimSpace(before)
928 } else {
929 scheme = utils.TrimSpace(v)
930 }
931 } else if utils.EqualFold(key, xForwardedSslBytes) && utils.EqualFold(val, onBytes) {
932 scheme = schemeHTTPS
933 }
934
935 case utils.EqualFold(key, xURLSchemeBytes):
936 scheme = utils.TrimSpace(app.toString(val))
937 default:
938 continue
939 }
940 }
941 return utilsstrings.ToLower(utils.TrimSpace(scheme))
942}
943
944// Protocol returns the HTTP protocol of request: HTTP/1.1 and HTTP/2.
945func (r *DefaultReq) Protocol() string {

Callers

nothing calls this directly

Calls 3

IsProxyTrustedMethod · 0.95
toStringMethod · 0.80
AllMethod · 0.65

Tested by

no test coverage detected