MCPcopy Index your code
hub / github.com/GoEdgeLab/EdgeNode / doRoot

Method doRoot

internal/nodes/http_request_root.go:44–420  ·  view source on GitHub ↗

调用本地静态资源 如果返回true,则终止请求

()

Source from the content-addressed store, hash-verified

42// 调用本地静态资源
43// 如果返回true,则终止请求
44func (this *HTTPRequest) doRoot() (isBreak bool) {
45 if this.web.Root == nil || !this.web.Root.IsOn {
46 return
47 }
48
49 if len(this.uri) == 0 {
50 this.write404()
51 return true
52 }
53
54 var rootDir = this.web.Root.Dir
55 if this.web.Root.HasVariables() {
56 rootDir = this.Format(rootDir)
57 }
58 if !filepath.IsAbs(rootDir) {
59 rootDir = Tea.Root + Tea.DS + rootDir
60 }
61
62 var requestPath = this.uri
63
64 var questionMarkIndex = strings.Index(this.uri, "?")
65 if questionMarkIndex > -1 {
66 requestPath = this.uri[:questionMarkIndex]
67 }
68
69 // except hidden files
70 if this.web.Root.ExceptHiddenFiles &&
71 (strings.Contains(requestPath, "/.") || strings.Contains(requestPath, "\\.")) {
72 this.write404()
73 return true
74 }
75
76 // except and only files
77 if !this.web.Root.MatchURL(this.URL()) {
78 this.write404()
79 return true
80 }
81
82 // 去掉其中的奇怪的路径
83 requestPath = strings.Replace(requestPath, "..\\", "", -1)
84
85 // 进行URL Decode
86 if this.web.Root.DecodePath {
87 p, err := url.QueryUnescape(requestPath)
88 if err == nil {
89 requestPath = p
90 } else {
91 if !this.canIgnore(err) {
92 logs.Error(err)
93 }
94 }
95 }
96
97 // 去掉前缀
98 stripPrefix := this.web.Root.StripPrefix
99 if len(stripPrefix) > 0 {
100 if stripPrefix[0] != '/' {
101 stripPrefix = "/" + stripPrefix

Callers 1

doBeginMethod · 0.95

Calls 15

write404Method · 0.95
FormatMethod · 0.95
URLMethod · 0.95
canIgnoreMethod · 0.95
write50xMethod · 0.95
findIndexFileMethod · 0.95
onRequestMethod · 0.95
requestHeaderMethod · 0.95
bytePoolMethod · 0.95
httpRequestReadRangeFunction · 0.85

Tested by

no test coverage detected