add raw handler support
This commit is contained in:
@@ -168,7 +168,8 @@ func main() {
|
|||||||
app.Get("styles.css", handlers.Styles)
|
app.Get("styles.css", handlers.Styles)
|
||||||
app.Get("script.js", handlers.Script)
|
app.Get("script.js", handlers.Script)
|
||||||
app.Get("ruleset", handlers.Ruleset)
|
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))
|
app.Get("api/content/*", handlers.NewAPIContentHandler("api/outline/*", proxyOpts))
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ func NewProxySiteHandler(opts *ProxyOptions) fiber.Handler {
|
|||||||
SetRequestModifications(
|
SetRequestModifications(
|
||||||
//rx.SpoofJA3fingerprint(ja3, "Googlebot"),
|
//rx.SpoofJA3fingerprint(ja3, "Googlebot"),
|
||||||
rx.AddCacheBusterQuery(),
|
rx.AddCacheBusterQuery(),
|
||||||
//rx.MasqueradeAsGoogleBot(),
|
rx.MasqueradeAsGoogleBot(),
|
||||||
rx.ForwardRequestHeaders(),
|
rx.ForwardRequestHeaders(),
|
||||||
rx.DeleteOutgoingCookies(),
|
rx.DeleteOutgoingCookies(),
|
||||||
rx.SpoofReferrerFromRedditPost(),
|
rx.SpoofReferrerFromRedditPost(),
|
||||||
|
|||||||
@@ -1,9 +1,51 @@
|
|||||||
package handlers
|
package handlers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"ladder/proxychain"
|
||||||
|
rx "ladder/proxychain/requestmodifiers"
|
||||||
|
tx "ladder/proxychain/responsemodifiers"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Raw(c *fiber.Ctx) error {
|
func NewRawProxySiteHandler(opts *ProxyOptions) fiber.Handler {
|
||||||
return nil
|
|
||||||
|
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()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
|
|
||||||
func TestRaw(t *testing.T) {
|
func TestRaw(t *testing.T) {
|
||||||
app := fiber.New()
|
app := fiber.New()
|
||||||
app.Get("/raw/*", Raw)
|
app.Get("/raw/*", NewRawProxySiteHandler(nil))
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
|
|||||||
@@ -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
|
// 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"))
|
chain.Context.Set("content-type", chain.Response.Header.Get("content-type"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,16 +6,16 @@ import (
|
|||||||
|
|
||||||
// SetResponseHeader modifies response headers from the upstream server
|
// SetResponseHeader modifies response headers from the upstream server
|
||||||
func SetResponseHeader(key string, value string) proxychain.ResponseModification {
|
func SetResponseHeader(key string, value string) proxychain.ResponseModification {
|
||||||
return func(px *proxychain.ProxyChain) error {
|
return func(chain *proxychain.ProxyChain) error {
|
||||||
px.Context.Response().Header.Set(key, value)
|
chain.Context.Set(key, value)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// DeleteResponseHeader removes response headers from the upstream server
|
// DeleteResponseHeader removes response headers from the upstream server
|
||||||
func DeleteResponseHeader(key string) proxychain.ResponseModification {
|
func DeleteResponseHeader(key string) proxychain.ResponseModification {
|
||||||
return func(px *proxychain.ProxyChain) error {
|
return func(chain *proxychain.ProxyChain) error {
|
||||||
px.Context.Response().Header.Del(key)
|
chain.Context.Response().Header.Del(key)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user