From 9750998940adf13190efe8046e9f7a699337fc67 Mon Sep 17 00:00:00 2001 From: ginuerzh Date: Tue, 31 Jan 2023 18:07:44 +0800 Subject: [PATCH] fix http response code when forwarder node is not available --- config/parsing/service.go | 3 +++ go.mod | 2 +- go.sum | 4 ++-- handler/forward/local/handler.go | 1 + handler/forward/remote/handler.go | 1 + 5 files changed, 8 insertions(+), 3 deletions(-) diff --git a/config/parsing/service.go b/config/parsing/service.go index 4852170..3d8cb91 100644 --- a/config/parsing/service.go +++ b/config/parsing/service.go @@ -338,6 +338,9 @@ func chainGroup(name string, group *config.ChainGroupConfig) chain.Chainer { } sel = parseChainSelector(group.Selector) } + if len(chains) == 0 { + return nil + } if sel == nil { sel = defaultChainSelector() diff --git a/go.mod b/go.mod index c02bc3b..3d637ef 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d github.com/gin-contrib/cors v1.3.1 github.com/gin-gonic/gin v1.8.2 - github.com/go-gost/core v0.0.0-20230131053758-ff3b77ac2899 + github.com/go-gost/core v0.0.0-20230131100536-f3482d7cd848 github.com/go-gost/gosocks4 v0.0.1 github.com/go-gost/gosocks5 v0.3.1-0.20211109033403-d894d75b7f09 github.com/go-gost/relay v0.3.1 diff --git a/go.sum b/go.sum index bbde453..8fa3017 100644 --- a/go.sum +++ b/go.sum @@ -91,8 +91,8 @@ github.com/gin-gonic/gin v1.8.2/go.mod h1:qw5AYuDrzRTnhvusDsrov+fDIxp9Dleuu12h8n github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= -github.com/go-gost/core v0.0.0-20230131053758-ff3b77ac2899 h1:Ofa8D9NViX+biyS3oUPgIzAjYD6i71abRGalX/0Den4= -github.com/go-gost/core v0.0.0-20230131053758-ff3b77ac2899/go.mod h1:R08B7BVdhWsYHX8s7wkEBpeKqc4+YFP6bLLFoao0J/A= +github.com/go-gost/core v0.0.0-20230131100536-f3482d7cd848 h1:jAack881fzd5s1jNC5w9SK1gL3bvnh4iK1lMFPnjUw8= +github.com/go-gost/core v0.0.0-20230131100536-f3482d7cd848/go.mod h1:R08B7BVdhWsYHX8s7wkEBpeKqc4+YFP6bLLFoao0J/A= github.com/go-gost/gosocks4 v0.0.1 h1:+k1sec8HlELuQV7rWftIkmy8UijzUt2I6t+iMPlGB2s= github.com/go-gost/gosocks4 v0.0.1/go.mod h1:3B6L47HbU/qugDg4JnoFPHgJXE43Inz8Bah1QaN9qCc= github.com/go-gost/gosocks5 v0.3.1-0.20211109033403-d894d75b7f09 h1:A95M6UWcfZgOuJkQ7QLfG0Hs5peWIUSysCDNz4pfe04= diff --git a/handler/forward/local/handler.go b/handler/forward/local/handler.go index 9d5cf3f..7d7c4d7 100644 --- a/handler/forward/local/handler.go +++ b/handler/forward/local/handler.go @@ -181,6 +181,7 @@ func (h *forwardHandler) handleHTTP(ctx context.Context, rw io.ReadWriter, log l } if target == nil { log.Warnf("node for %s not found", req.Host) + resp.StatusCode = http.StatusBadGateway return resp.Write(rw) } diff --git a/handler/forward/remote/handler.go b/handler/forward/remote/handler.go index a7563ef..8f33705 100644 --- a/handler/forward/remote/handler.go +++ b/handler/forward/remote/handler.go @@ -181,6 +181,7 @@ func (h *forwardHandler) handleHTTP(ctx context.Context, rw io.ReadWriter, log l } if target == nil { log.Warnf("node for %s not found", req.Host) + resp.StatusCode = http.StatusBadGateway return resp.Write(rw) }