if val, ok := t.K_v.LoadV("ip路径").(string); ok && val != "" {
t.SerF.Store(val, func(w http.ResponseWriter, r *http.Request) {
- if DefaultHttpCheck(t, w, r, http.MethodGet) {
+ if DefaultHttpFunc(t, w, r, http.MethodGet) {
return
}
for ip := range sys.GetIpByCidr() {
if val, ok := t.K_v.LoadV("性能路径").(string); ok && val != "" {
var cache web.Cache
t.SerF.Store(val, func(w http.ResponseWriter, r *http.Request) {
- if DefaultHttpCheck(t, w, r, http.MethodGet) {
+ if DefaultHttpFunc(t, w, r, http.MethodGet) {
return
}
return data
}
-func DefaultHttpCheck(c *Common, w http.ResponseWriter, r *http.Request, method ...string) bool {
+func DefaultHttpFunc(c *Common, w http.ResponseWriter, r *http.Request, method ...string) bool {
if strings.Contains(r.URL.Path, "../") {
web.WithStatusCode(w, http.StatusForbidden)
return true
web.WithStatusCode(w, http.StatusTooManyRequests)
return true
}
+ //Web自定义响应头
+ if resHeaders, ok := c.K_v.LoadV("Web自定义响应头").(map[string]any); ok && len(resHeaders) > 0 {
+ for k, v := range resHeaders {
+ if k == "" {
+ continue
+ } else if vs, ok := v.(string); !ok || vs == "" {
+ continue
+ } else {
+ w.Header().Set(k, vs)
+ }
+ }
+ }
return false
}
### 说明
本项目使用github action自动构建,构建过程详见[yml](https://github.com/qydysky/bili_danmu/blob/master/.github/workflows/go.yml)
+#### Web自定义响应头
+配置文件中添加配置项`Web自定义响应头`(>v0.14.19)。默认为空,当不为空时,将在所有响应中添加指定头。
+例子:
+```
+{
+ "Web服务地址":"0.0.0.0:11000",
+ "直播Web服务路径":"/web/",
+ "Web自定义响应头": {
+ "Access-Control-Allow-Origin":"*"
+ }
+}
+```
+
+```
+curl -i http://{主机名}:11000/web/emots/4e9621239e8a349b1ad198af90458e06.png
+HTTP/1.1 200 OK
+Access-Control-Allow-Origin: *
+Cache-Control: private
+Etag: 2024-09-24T01:53:03+08:00
+Last-Modified: Tue, 24 Sep 2024 01:53:03 CST
+Date: Sat, 05 Oct 2024 14:02:18 GMT
+Content-Type: image/png
+Transfer-Encoding: chunked
+```
+
+
#### ip路径
配置文件中添加配置项`ip路径`(>v0.14.16)。不为空时,将会在指定路径显示出当前主机ip,从而可以使用主机名来获取主机ipv6,以便于[ddns-go](https://github.com/jeessy2/ddns-go)等通过命令获取ipv6。默认空。
// debug模式
if debugP, ok := c.C.K_v.LoadV(`debug路径`).(string); ok && debugP != "" {
c.C.SerF.Store(debugP, func(w http.ResponseWriter, r *http.Request) {
- if c.DefaultHttpCheck(c.C, w, r, http.MethodGet, http.MethodPost) {
+ if c.DefaultHttpFunc(c.C, w, r, http.MethodGet, http.MethodPost) {
return
}
if name, found := strings.CutPrefix(r.URL.Path, debugP); found && name != "" {
// 直播流主页
c.C.SerF.Store(spath, func(w http.ResponseWriter, r *http.Request) {
- if c.DefaultHttpCheck(c.C, w, r, http.MethodGet, http.MethodHead) {
+ if c.DefaultHttpFunc(c.C, w, r, http.MethodGet, http.MethodHead) {
return
}
// 直播流文件列表api
c.C.SerF.Store(spath+"filePath", func(w http.ResponseWriter, r *http.Request) {
- if c.DefaultHttpCheck(c.C, w, r, http.MethodGet) {
+ if c.DefaultHttpFunc(c.C, w, r, http.MethodGet) {
return
}
// 表情
c.C.SerF.Store(spath+"emots/", func(w http.ResponseWriter, r *http.Request) {
- if c.DefaultHttpCheck(c.C, w, r, http.MethodGet) {
+ if c.DefaultHttpFunc(c.C, w, r, http.MethodGet) {
return
}
// 直播流播放器
c.C.SerF.Store(spath+"player/", func(w http.ResponseWriter, r *http.Request) {
- if c.DefaultHttpCheck(c.C, w, r, http.MethodGet) {
+ if c.DefaultHttpFunc(c.C, w, r, http.MethodGet) {
return
}
}
c.C.SerF.Store(spath+"keepAlive", func(w http.ResponseWriter, r *http.Request) {
- if c.DefaultHttpCheck(c.C, w, r, http.MethodGet) {
+ if c.DefaultHttpFunc(c.C, w, r, http.MethodGet) {
return
}
if key, e := expirer.Reg(time.Second*30, r.URL.Query().Get("key")); e != nil {
// 流地址
c.C.SerF.Store(spath+"stream", func(w http.ResponseWriter, r *http.Request) {
- if c.DefaultHttpCheck(c.C, w, r, http.MethodGet) {
+ if c.DefaultHttpFunc(c.C, w, r, http.MethodGet) {
return
}
// 弹幕回放
c.C.SerF.Store(spath+"player/ws", func(w http.ResponseWriter, r *http.Request) {
- if c.DefaultHttpCheck(c.C, w, r, http.MethodGet) {
+ if c.DefaultHttpFunc(c.C, w, r, http.MethodGet) {
return
}
// 弹幕回放xml
c.C.SerF.Store(spath+"player/xml", func(w http.ResponseWriter, r *http.Request) {
- if c.DefaultHttpCheck(c.C, w, r, http.MethodGet) {
+ if c.DefaultHttpFunc(c.C, w, r, http.MethodGet) {
return
}