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

Method doShutdown

internal/nodes/http_request_shutdown.go:15–114  ·  view source on GitHub ↗

调用临时关闭页面

()

Source from the content-addressed store, hash-verified

13
14// 调用临时关闭页面
15func (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 {

Callers 1

doBeginMethod · 0.95

Calls 15

doURLMethod · 0.95
FormatMethod · 0.95
canIgnoreMethod · 0.95
CopyWithFilterFunction · 0.92
WarnFunction · 0.92
httpStatusIsRedirectFunction · 0.85
httpRedirectFunction · 0.85
MatchStringMethod · 0.80
WriteStringMethod · 0.80
SetOkMethod · 0.80
WriteHeaderMethod · 0.65

Tested by

no test coverage detected