调用临时关闭页面
()
| 13 | |
| 14 | // 调用临时关闭页面 |
| 15 | func (this *HTTPRequest) doShutdown() { |
| 16 | var shutdown = this.web.Shutdown |
| 17 | if shutdown == nil { |
| 18 | return |
| 19 | } |
| 20 | |
| 21 | if len(shutdown.BodyType) == 0 || shutdown.BodyType == serverconfigs.HTTPPageBodyTypeURL { |
| 22 | // URL |
| 23 | if urlSchemeRegexp.MatchString(shutdown.URL) { |
| 24 | this.doURL(http.MethodGet, shutdown.URL, "", shutdown.Status, true) |
| 25 | return |
| 26 | } |
| 27 | |
| 28 | // URL为空,则显示文本 |
| 29 | if len(shutdown.URL) == 0 { |
| 30 | // 自定义响应Headers |
| 31 | if shutdown.Status > 0 { |
| 32 | this.ProcessResponseHeaders(this.writer.Header(), shutdown.Status) |
| 33 | this.writer.WriteHeader(shutdown.Status) |
| 34 | } else { |
| 35 | this.ProcessResponseHeaders(this.writer.Header(), http.StatusOK) |
| 36 | this.writer.WriteHeader(http.StatusOK) |
| 37 | } |
| 38 | _, _ = this.writer.WriteString("The site have been shutdown.") |
| 39 | return |
| 40 | } |
| 41 | |
| 42 | // 从本地文件中读取 |
| 43 | var realpath = path.Clean(shutdown.URL) |
| 44 | if !strings.HasPrefix(realpath, "/pages/") && !strings.HasPrefix(realpath, "pages/") { // only files under "/pages/" can be used |
| 45 | var msg = "404 page not found: '" + shutdown.URL + "'" |
| 46 | this.writer.WriteHeader(http.StatusNotFound) |
| 47 | _, _ = this.writer.Write([]byte(msg)) |
| 48 | return |
| 49 | } |
| 50 | var file = Tea.Root + Tea.DS + shutdown.URL |
| 51 | fp, err := os.Open(file) |
| 52 | if err != nil { |
| 53 | var msg = "404 page not found: '" + shutdown.URL + "'" |
| 54 | this.writer.WriteHeader(http.StatusNotFound) |
| 55 | _, _ = this.writer.Write([]byte(msg)) |
| 56 | return |
| 57 | } |
| 58 | |
| 59 | defer func() { |
| 60 | _ = fp.Close() |
| 61 | }() |
| 62 | |
| 63 | // 自定义响应Headers |
| 64 | if shutdown.Status > 0 { |
| 65 | this.ProcessResponseHeaders(this.writer.Header(), shutdown.Status) |
| 66 | this.writer.WriteHeader(shutdown.Status) |
| 67 | } else { |
| 68 | this.ProcessResponseHeaders(this.writer.Header(), http.StatusOK) |
| 69 | this.writer.WriteHeader(http.StatusOK) |
| 70 | } |
| 71 | var buf = utils.BytePool1k.Get() |
| 72 | _, err = utils.CopyWithFilter(this.writer, fp, buf.Bytes, func(p []byte) []byte { |
no test coverage detected