From 12eb21a5cd5133a4533ac2b9dc209e7b0c462e62 Mon Sep 17 00:00:00 2001 From: ExplodingDragon Date: Thu, 15 May 2025 23:29:34 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BD=AC=E5=8F=91=E8=AF=B7=E6=B1=82=E6=97=B6?= =?UTF-8?q?=E4=B8=8A=E6=8A=A5=E5=8F=8D=E5=90=91=E4=BB=A3=E7=90=86=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README_zh.md | 3 ++- pkg/server.go | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) 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 }