fix fwd response headers
This commit is contained in:
@@ -32,7 +32,7 @@ func NewProxySiteHandler(opts *ProxyOptions) fiber.Handler {
|
|||||||
SetDebugLogging(opts.Verbose).
|
SetDebugLogging(opts.Verbose).
|
||||||
SetRequestModifications(
|
SetRequestModifications(
|
||||||
//rx.MasqueradeAsFacebookBot(),
|
//rx.MasqueradeAsFacebookBot(),
|
||||||
rx.MasqueradeAsGoogleBot(),
|
//rx.MasqueradeAsGoogleBot(),
|
||||||
//rx.DeleteOutgoingCookies(),
|
//rx.DeleteOutgoingCookies(),
|
||||||
rx.ForwardRequestHeaders(),
|
rx.ForwardRequestHeaders(),
|
||||||
rx.SetOutgoingCookie("nyt-a", " "),
|
rx.SetOutgoingCookie("nyt-a", " "),
|
||||||
@@ -45,10 +45,10 @@ func NewProxySiteHandler(opts *ProxyOptions) fiber.Handler {
|
|||||||
//rx.RequestArchiveIs(),
|
//rx.RequestArchiveIs(),
|
||||||
).
|
).
|
||||||
AddResponseModifications(
|
AddResponseModifications(
|
||||||
tx.BypassCORS(),
|
|
||||||
tx.BypassContentSecurityPolicy(),
|
|
||||||
//tx.DeleteIncomingCookies(),
|
|
||||||
tx.ForwardResponseHeaders(),
|
tx.ForwardResponseHeaders(),
|
||||||
|
//tx.BypassCORS(),
|
||||||
|
//tx.BypassContentSecurityPolicy(),
|
||||||
|
//tx.DeleteIncomingCookies(),
|
||||||
tx.RewriteHTMLResourceURLs(),
|
tx.RewriteHTMLResourceURLs(),
|
||||||
tx.PatchDynamicResourceURLs(),
|
tx.PatchDynamicResourceURLs(),
|
||||||
//tx.SetContentSecurityPolicy("default-src * 'unsafe-inline' 'unsafe-eval' data: blob:;"),
|
//tx.SetContentSecurityPolicy("default-src * 'unsafe-inline' 'unsafe-eval' data: blob:;"),
|
||||||
|
|||||||
@@ -354,7 +354,8 @@ func (chain *ProxyChain) _reset() {
|
|||||||
// NewProxyChain initializes a new ProxyChain
|
// NewProxyChain initializes a new ProxyChain
|
||||||
func NewProxyChain() *ProxyChain {
|
func NewProxyChain() *ProxyChain {
|
||||||
chain := new(ProxyChain)
|
chain := new(ProxyChain)
|
||||||
chain.Client = http.DefaultClient
|
//chain.Client = http.DefaultClient
|
||||||
|
chain.Client = &http.Client{}
|
||||||
return chain
|
return chain
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package requestmodifers
|
package requestmodifers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
//"fmt"
|
||||||
"ladder/proxychain"
|
"ladder/proxychain"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ func init() {
|
|||||||
func ForwardResponseHeaders() proxychain.ResponseModification {
|
func ForwardResponseHeaders() proxychain.ResponseModification {
|
||||||
return func(chain *proxychain.ProxyChain) error {
|
return func(chain *proxychain.ProxyChain) error {
|
||||||
|
|
||||||
|
//fmt.Println(chain.Response.Header)
|
||||||
for uname, headers := range chain.Response.Header {
|
for uname, headers := range chain.Response.Header {
|
||||||
name := strings.ToLower(uname)
|
name := strings.ToLower(uname)
|
||||||
if forwardBlacklist[name] {
|
if forwardBlacklist[name] {
|
||||||
@@ -42,6 +43,7 @@ func ForwardResponseHeaders() proxychain.ResponseModification {
|
|||||||
|
|
||||||
// forward headers
|
// forward headers
|
||||||
for _, value := range headers {
|
for _, value := range headers {
|
||||||
|
fmt.Println(name, value)
|
||||||
chain.Context.Set(name, value)
|
chain.Context.Set(name, value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"path"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -113,7 +114,7 @@ func (r *HTMLTokenURLRewriter) ModifyToken(token *html.Token) (string, string) {
|
|||||||
case !rewriteAttrs[token.Data][attr.Key]:
|
case !rewriteAttrs[token.Data][attr.Key]:
|
||||||
continue
|
continue
|
||||||
// don't touch attributes with special URIs (like data:)
|
// don't touch attributes with special URIs (like data:)
|
||||||
case schemeBlacklist[strings.Split(attr.Key, ":")[0]]:
|
case schemeBlacklist[strings.Split(attr.Val, ":")[0]]:
|
||||||
continue
|
continue
|
||||||
// don't double-overwrite the url
|
// don't double-overwrite the url
|
||||||
case strings.HasPrefix(attr.Val, r.proxyURL):
|
case strings.HasPrefix(attr.Val, r.proxyURL):
|
||||||
@@ -184,15 +185,17 @@ func handleRootRelativePath(attr *html.Attribute, baseURL *url.URL) {
|
|||||||
// Document-relative URLs: These are relative to the current document's path and don't start with a "/".
|
// Document-relative URLs: These are relative to the current document's path and don't start with a "/".
|
||||||
func handleDocumentRelativePath(attr *html.Attribute, baseURL *url.URL) {
|
func handleDocumentRelativePath(attr *html.Attribute, baseURL *url.URL) {
|
||||||
log.Printf("PROCESSING: key: %s val: %s\n", attr.Key, attr.Val)
|
log.Printf("PROCESSING: key: %s val: %s\n", attr.Key, attr.Val)
|
||||||
|
if strings.HasPrefix(attr.Val, "#") {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
relativePath := path.Join(strings.Trim(baseURL.RawPath, "/"), strings.Trim(attr.Val, "/"))
|
||||||
attr.Val = fmt.Sprintf(
|
attr.Val = fmt.Sprintf(
|
||||||
"%s://%s/%s%s",
|
"%s://%s/%s",
|
||||||
baseURL.Scheme,
|
baseURL.Scheme,
|
||||||
strings.Trim(baseURL.Host, "/"),
|
strings.Trim(baseURL.Host, "/"),
|
||||||
strings.Trim(baseURL.RawPath, "/"),
|
relativePath,
|
||||||
strings.Trim(attr.Val, "/"),
|
|
||||||
)
|
)
|
||||||
attr.Val = escape(attr.Val)
|
attr.Val = escape(attr.Val)
|
||||||
attr.Val = fmt.Sprintf("%s://%s/%s", baseURL.Scheme, baseURL.Host, attr.Val)
|
|
||||||
log.Printf("doc rel url rewritten-> '%s'='%s'", attr.Key, attr.Val)
|
log.Printf("doc rel url rewritten-> '%s'='%s'", attr.Key, attr.Val)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,7 +207,7 @@ func handleAbsolutePath(attr *html.Attribute, baseURL *url.URL) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if u.Scheme != "http" || u.Scheme != "https" {
|
if !(u.Scheme == "http" || u.Scheme == "https") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
attr.Val = fmt.Sprintf("/%s", escape(strings.TrimPrefix(attr.Val, "/")))
|
attr.Val = fmt.Sprintf("/%s", escape(strings.TrimPrefix(attr.Val, "/")))
|
||||||
@@ -232,7 +235,7 @@ func handleMetaRefresh(attr *html.Attribute, baseURL *url.URL) {
|
|||||||
url := strings.Split(attr.Val, ";url=")[1]
|
url := strings.Split(attr.Val, ";url=")[1]
|
||||||
f := &html.Attribute{Val: url, Key: "src"}
|
f := &html.Attribute{Val: url, Key: "src"}
|
||||||
handleURLPart(f, baseURL)
|
handleURLPart(f, baseURL)
|
||||||
attr.Val = fmt.Sprintf("%s;url=%s", sec, url)
|
attr.Val = fmt.Sprintf("%s;url=%s", sec, f.Val)
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleSrcSet(attr *html.Attribute, baseURL *url.URL) {
|
func handleSrcSet(attr *html.Attribute, baseURL *url.URL) {
|
||||||
@@ -246,14 +249,14 @@ func handleSrcSet(attr *html.Attribute, baseURL *url.URL) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
fakeAttr := &html.Attribute{Val: srcParts[0], Key: "src"}
|
f := &html.Attribute{Val: srcParts[0], Key: "src"}
|
||||||
handleURLPart(fakeAttr, baseURL)
|
handleURLPart(f, baseURL)
|
||||||
|
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
srcSetBuilder.WriteString(", ")
|
srcSetBuilder.WriteString(", ")
|
||||||
}
|
}
|
||||||
|
|
||||||
srcSetBuilder.WriteString(fakeAttr.Val)
|
srcSetBuilder.WriteString(f.Val)
|
||||||
if len(srcParts) > 1 {
|
if len(srcParts) > 1 {
|
||||||
srcSetBuilder.WriteString(" ")
|
srcSetBuilder.WriteString(" ")
|
||||||
srcSetBuilder.WriteString(strings.Join(srcParts[1:], " "))
|
srcSetBuilder.WriteString(strings.Join(srcParts[1:], " "))
|
||||||
@@ -264,5 +267,6 @@ func handleSrcSet(attr *html.Attribute, baseURL *url.URL) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func escape(str string) string {
|
func escape(str string) string {
|
||||||
|
//return str
|
||||||
return strings.ReplaceAll(url.PathEscape(str), "%2F", "/")
|
return strings.ReplaceAll(url.PathEscape(str), "%2F", "/")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user