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

Method write50x

internal/nodes/http_request_error.go:68–119  ·  view source on GitHub ↗
(err error, statusCode int, enMessage string, zhMessage string, canTryStale bool)

Source from the content-addressed store, hash-verified

66}
67
68func (this *HTTPRequest) write50x(err error, statusCode int, enMessage string, zhMessage string, canTryStale bool) {
69 if err != nil {
70 this.addError(err)
71 }
72
73 // 尝试从缓存中恢复
74 if canTryStale &&
75 this.cacheCanTryStale &&
76 this.web.Cache.Stale != nil &&
77 this.web.Cache.Stale.IsOn &&
78 (len(this.web.Cache.Stale.Status) == 0 || lists.ContainsInt(this.web.Cache.Stale.Status, statusCode)) {
79 var ok = this.doCacheRead(true)
80 if ok {
81 return
82 }
83 }
84
85 // 显示自定义页面
86 if this.doPage(statusCode) {
87 return
88 }
89
90 // 内置HTML模板
91 var pageContent = configutils.ParseVariables(httpStatusPageTemplate, func(varName string) (value string) {
92 switch varName {
93 case "status":
94 return types.String(statusCode)
95 case "statusMessage":
96 return http.StatusText(statusCode)
97 case "requestId":
98 return this.requestId
99 case "message":
100 var acceptLanguages = this.RawReq.Header.Get("Accept-Language")
101 if len(acceptLanguages) > 0 {
102 var index = strings.Index(acceptLanguages, ",")
103 if index > 0 {
104 var firstLanguage = acceptLanguages[:index]
105 if firstLanguage == "zh-CN" {
106 return "网站出了一点小问题,原因:" + zhMessage + "。"
107 }
108 }
109 }
110 return "The site is unavailable now, cause: " + enMessage + "."
111 }
112 return this.Format("${" + varName + "}")
113 })
114
115 this.ProcessResponseHeaders(this.writer.Header(), statusCode)
116 this.writer.WriteHeader(statusCode)
117
118 _, _ = this.writer.Write([]byte(pageContent))
119}

Callers 8

doRootMethod · 0.95
DoMethod · 0.95
doBeginMethod · 0.95
doAuthMethod · 0.95
doWebsocketMethod · 0.95
doFastcgiMethod · 0.95
doOriginRequestMethod · 0.95
doURLMethod · 0.95

Calls 10

addErrorMethod · 0.95
doCacheReadMethod · 0.95
doPageMethod · 0.95
FormatMethod · 0.95
WriteHeaderMethod · 0.65
WriteMethod · 0.65
StringMethod · 0.45
GetMethod · 0.45
HeaderMethod · 0.45

Tested by

no test coverage detected