From df1920921195488fc618cf84b13987d2412041f5 Mon Sep 17 00:00:00 2001 From: Kevin Pham Date: Thu, 7 Dec 2023 09:58:52 -0600 Subject: [PATCH] fix content-type not set regression on main proxy handler --- handlers/outline.go | 1 + handlers/proxy.go | 11 ++++++++--- handlers/ruleset.go | 1 - proxychain/proxychain.go | 12 +++++++----- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/handlers/outline.go b/handlers/outline.go index ab1e105..d96dd78 100644 --- a/handlers/outline.go +++ b/handlers/outline.go @@ -20,6 +20,7 @@ func NewOutlineHandler(path string, opts *ProxyOptions) fiber.Handler { rx.SpoofReferrerFromGoogleSearch(), ). AddResponseModifications( + tx.ForwardResponseHeaders(), tx.DeleteIncomingCookies(), tx.RewriteHTMLResourceURLs(), tx.GenerateReadableOutline(), // <-- this response modification does the outline rendering diff --git a/handlers/proxy.go b/handlers/proxy.go index aaeebae..5984267 100644 --- a/handlers/proxy.go +++ b/handlers/proxy.go @@ -43,7 +43,7 @@ func NewProxySiteHandler(opts *ProxyOptions) fiber.Handler { //rx.RequestArchiveIs(), ). AddResponseModifications( - //tx.ForwardResponseHeaders(), + tx.ForwardResponseHeaders(), //tx.BlockThirdPartyScripts(), tx.DeleteIncomingCookies(), tx.DeleteLocalStorageData(), @@ -53,11 +53,16 @@ func NewProxySiteHandler(opts *ProxyOptions) fiber.Handler { tx.RewriteHTMLResourceURLs(), tx.PatchDynamicResourceURLs(), tx.PatchTrackerScripts(), - //tx.BlockElementRemoval(".article-content"), // techcrunch - tx.BlockElementRemoval(".available-content"), // substack + tx.BlockElementRemoval(".article-content"), // techcrunch + //tx.BlockElementRemoval(".available-content"), // substack // tx.SetContentSecurityPolicy("default-src * 'unsafe-inline' 'unsafe-eval' data: blob:;"), ) + // no options passed in, return early + if opts == nil { + return proxychain.Execute() + } + // load ruleset rule, exists := opts.Ruleset.GetRule(proxychain.Request.URL) if exists { diff --git a/handlers/ruleset.go b/handlers/ruleset.go index 5b9ea46..08e90c9 100644 --- a/handlers/ruleset.go +++ b/handlers/ruleset.go @@ -29,7 +29,6 @@ func NewRulesetSiteHandler(opts *ProxyOptions) fiber.Handler { return c.Send([]byte(jsn)) default: - // TODO: the ruleset.MarshalYAML() method is currently broken and panics yml, err := opts.Ruleset.YAML() if err != nil { return err diff --git a/proxychain/proxychain.go b/proxychain/proxychain.go index 8d8a51d..e38ebaf 100644 --- a/proxychain/proxychain.go +++ b/proxychain/proxychain.go @@ -525,12 +525,14 @@ func (chain *ProxyChain) Execute() error { return errors.New("no context set") } + // TODO: this seems broken // in case api user did not set or forward content-type, we do it for them - 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")) - } + /* + ct := string(chain.Context.Response().Header.Peek("content-type")) + if ct == "" { + chain.Context.Set("content-type", chain.Response.Header.Get("content-type")) + } + */ // Return request back to client return chain.Context.SendStream(body)