diff --git a/README_zh.md b/README_zh.md index 77256a6..a6a2a24 100644 --- a/README_zh.md +++ b/README_zh.md @@ -24,7 +24,6 @@ make gitea-pages 具体配置可查看 [`config.yaml`](./config.yaml)。 - ### Page Config 在项目的 `gh-pages` 分支创建 `.pages.yaml`,填入如下内容 @@ -47,6 +46,8 @@ ignore: .git/**,.pages.yaml - [x] CNAME 自定义域名 - [x] 模板渲染 - [x] 反向代理请求 +- [ ] 支持跨域 +- [ ] 支持自定义缓存策略 (http cache-control) - [ ] OAuth2 授权访问私有页面 - [ ] ~~http01 自动签发证书~~: 交由 Caddy 完成 - [ ] ~~Web 钩子触发更新~~: 对实时性需求不大 diff --git a/pkg/server.go b/pkg/server.go index 193e799..3fd8c49 100644 --- a/pkg/server.go +++ b/pkg/server.go @@ -4,6 +4,7 @@ import ( "fmt" "io" "mime" + "net" "net/http" "net/http/httputil" "net/url" @@ -137,8 +138,16 @@ func (s *Server) Serve(writer http.ResponseWriter, request *http.Request) error request.RequestURI = request.URL.RequestURI() proxy := httputil.NewSingleHostReverseProxy(u) proxy.Transport = s.options.HttpClient.Transport + + if host, _, err := net.SplitHostPort(request.RemoteAddr); err == nil { + request.Header.Set("X-Real-IP", host) + } + request.Header.Set("X-Page-IP", utils.GetRemoteIP(request)) + request.Header.Set("X-Page-Refer", fmt.Sprintf("%s/%s/%s", meta.Owner, meta.Repo, meta.Path)) + request.Header.Set("X-Page-Host", request.Host) zap.L().Debug("命中反向代理", zap.Any("prefix", prefix), zap.Any("backend", backend), zap.Any("path", proxyPath), zap.Any("target", fmt.Sprintf("%s%s", u, targetPath))) + // todo(security): 处理 websocket proxy.ServeHTTP(writer, request) return nil }