调用本地静态资源 如果返回true,则终止请求
()
| 42 | // 调用本地静态资源 |
| 43 | // 如果返回true,则终止请求 |
| 44 | func (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 |
no test coverage detected