diff --git a/cmd/main.go b/cmd/main.go index 753db5d..c1d9c5a 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -168,7 +168,8 @@ func main() { app.Get("styles.css", handlers.Styles) app.Get("script.js", handlers.Script) app.Get("ruleset", handlers.Ruleset) - app.Get("raw/*", handlers.Raw) + + app.All("raw/*", handlers.NewRawProxySiteHandler(proxyOpts)) app.Get("api/content/*", handlers.NewAPIContentHandler("api/outline/*", proxyOpts)) diff --git a/handlers/proxy.go b/handlers/proxy.go index 7a04fa4..aaeebae 100644 --- a/handlers/proxy.go +++ b/handlers/proxy.go @@ -34,7 +34,7 @@ func NewProxySiteHandler(opts *ProxyOptions) fiber.Handler { SetRequestModifications( //rx.SpoofJA3fingerprint(ja3, "Googlebot"), rx.AddCacheBusterQuery(), - //rx.MasqueradeAsGoogleBot(), + rx.MasqueradeAsGoogleBot(), rx.ForwardRequestHeaders(), rx.DeleteOutgoingCookies(), rx.SpoofReferrerFromRedditPost(), diff --git a/handlers/raw.go b/handlers/raw.go index d192f0e..6ccfdd0 100644 --- a/handlers/raw.go +++ b/handlers/raw.go @@ -1,9 +1,51 @@ package handlers import ( + "fmt" + "ladder/proxychain" + rx "ladder/proxychain/requestmodifiers" + tx "ladder/proxychain/responsemodifiers" + "github.com/gofiber/fiber/v2" ) -func Raw(c *fiber.Ctx) error { - return nil +func NewRawProxySiteHandler(opts *ProxyOptions) fiber.Handler { + + return func(c *fiber.Ctx) error { + proxychain := proxychain. + NewProxyChain(). + SetFiberCtx(c). + SetRequestModifications( + rx.AddCacheBusterQuery(), + rx.MasqueradeAsGoogleBot(), + rx.ForwardRequestHeaders(), + rx.HideOrigin(), + rx.DeleteOutgoingCookies(), + rx.SpoofReferrerFromRedditPost(), + ) + + // no options passed in, return early + if opts == nil { + // return as plaintext, overriding any rules + proxychain.AddOnceResponseModifications( + tx.SetResponseHeader("content-type", "text/plain; charset=UTF-8"), + ) + + return proxychain.Execute() + } + + // load ruleset + rule, exists := opts.Ruleset.GetRule(proxychain.Request.URL) + if exists { + proxychain.AddOnceRequestModifications(rule.RequestModifications...) + proxychain.AddOnceResponseModifications(rule.ResponseModifications...) + } + + // return as plaintext, overriding any rules + proxychain.AddOnceResponseModifications( + tx.SetResponseHeader("content-type", "text/plain; charset=UTF-8"), + ) + + return proxychain.Execute() + } } diff --git a/handlers/raw.test.go b/handlers/raw.test.go index f8867d0..0fd96b6 100644 --- a/handlers/raw.test.go +++ b/handlers/raw.test.go @@ -13,7 +13,7 @@ import ( func TestRaw(t *testing.T) { app := fiber.New() - app.Get("/raw/*", Raw) + app.Get("/raw/*", NewRawProxySiteHandler(nil)) testCases := []struct { name string diff --git a/proxychain/proxychain.go b/proxychain/proxychain.go index 4f3df50..ac33475 100644 --- a/proxychain/proxychain.go +++ b/proxychain/proxychain.go @@ -530,7 +530,10 @@ func (chain *ProxyChain) Execute() error { } // in case api user did not set or forward content-type, we do it for them - if chain.Context.Get("content-type") == "" { + // warning: the fiber method chain.Context.Get() doesn't seem to work as described + ct := chain.Context.Response().Header.Peek("content-type") + CT := chain.Context.Response().Header.Peek("Content-Type") + if ct == nil && CT == nil { chain.Context.Set("content-type", chain.Response.Header.Get("content-type")) } diff --git a/proxychain/responsemodifiers/modify_response_header.go b/proxychain/responsemodifiers/modify_response_header.go index 0d6c850..2eca24d 100644 --- a/proxychain/responsemodifiers/modify_response_header.go +++ b/proxychain/responsemodifiers/modify_response_header.go @@ -6,16 +6,16 @@ import ( // SetResponseHeader modifies response headers from the upstream server func SetResponseHeader(key string, value string) proxychain.ResponseModification { - return func(px *proxychain.ProxyChain) error { - px.Context.Response().Header.Set(key, value) + return func(chain *proxychain.ProxyChain) error { + chain.Context.Set(key, value) return nil } } // DeleteResponseHeader removes response headers from the upstream server func DeleteResponseHeader(key string) proxychain.ResponseModification { - return func(px *proxychain.ProxyChain) error { - px.Context.Response().Header.Del(key) + return func(chain *proxychain.ProxyChain) error { + chain.Context.Response().Header.Del(key) return nil } }