@@ -125,6 +125,7 @@ func rewriteProxyRequest(req *http.Request, targetURL *neturl.URL) {
125125 req .Host = targetURL .Host
126126
127127 req .Header .Del ("Accept-Encoding" )
128+ req .Header .Del ("TE" ) // Disable transfer encoding compression
128129 for _ , headerName := range []string {"Origin" , "Referer" } {
129130 if rewritten := rewriteProxyHeaderURL (req .Header .Get (headerName ), targetURL ); rewritten != "" {
130131 req .Header .Set (headerName , rewritten )
@@ -341,7 +342,7 @@ func newCaptchaProxyTransport(dialer *dnsdialer.Dialer) *http.Transport {
341342 IdleConnTimeout : 90 * time .Second ,
342343 TLSHandshakeTimeout : 10 * time .Second ,
343344 ExpectContinueTimeout : 1 * time .Second ,
344- ForceAttemptHTTP2 : true ,
345+ ForceAttemptHTTP2 : false ,
345346 }
346347 if dialer != nil {
347348 transport .DialContext = dialer .DialContext
@@ -458,16 +459,17 @@ func solveCaptchaViaProxy(redirectURI string, dialer *dnsdialer.Dialer) (string,
458459 rewriteProxyRequest (req .Out , targetURL )
459460 },
460461 ErrorHandler : func (w http.ResponseWriter , r * http.Request , err error ) {
461- log .Printf ("captcha proxy error for %s: %v" , r .URL .String (), err )
462+ log .Printf ("[Captcha Proxy] ERROR for %s %s : %v" , r . Method , r .URL .String (), err )
462463 w .Header ().Set ("Content-Type" , "text/html; charset=utf-8" )
463464 w .WriteHeader (http .StatusBadGateway )
464- _ , _ = fmt .Fprintf (w , `<!DOCTYPE html><html><body style="font-family:sans-serif;padding:20px"><h2>Captcha proxy error</h2><p>%v</p></body></html>` , err )
465+ _ , _ = fmt .Fprintf (w , `<!DOCTYPE html><html><body style="font-family:sans-serif;padding:20px"><h2>Captcha proxy error</h2><p>%s %s</p><p>% v</p></body></html>` , r . Method , r . URL . String () , err )
465466 },
466467 ModifyResponse : func (res * http.Response ) error {
467468 rewriteProxyCookies (res .Header )
468469
469470 if res .StatusCode >= 300 && res .StatusCode < 400 {
470471 if loc := res .Header .Get ("Location" ); loc != "" {
472+ log .Printf ("[Captcha Proxy] Redirecting to: %s" , loc )
471473 if rewritten , ok := rewriteProxyRedirectLocation (loc , targetURL ); ok {
472474 res .Header .Set ("Location" , rewritten )
473475 } else {
@@ -477,7 +479,13 @@ func solveCaptchaViaProxy(redirectURI string, dialer *dnsdialer.Dialer) (string,
477479 }
478480
479481 contentType := res .Header .Get ("Content-Type" )
480- shouldInspectBody := strings .Contains (contentType , "text/html" ) || strings .Contains (res .Request .URL .Path , "captchaNotRobot.check" )
482+ contentEncoding := res .Header .Get ("Content-Encoding" )
483+ log .Printf ("[Captcha Proxy] %s %d | Content-Type: %q, Encoding: %q" , res .Request .Method , res .StatusCode , contentType , contentEncoding )
484+
485+ shouldInspectBody := strings .Contains (contentType , "text/html" ) ||
486+ strings .Contains (contentType , "application/xhtml+xml" ) ||
487+ strings .Contains (res .Request .URL .Path , "captchaNotRobot.check" )
488+
481489 if ! shouldInspectBody {
482490 return nil
483491 }
@@ -517,6 +525,8 @@ func solveCaptchaViaProxy(redirectURI string, dialer *dnsdialer.Dialer) (string,
517525 "Cross-Origin-Embedder-Policy" ,
518526 "Cross-Origin-Resource-Policy" ,
519527 "X-Frame-Options" ,
528+ "Strict-Transport-Security" ,
529+ "Alt-Svc" ,
520530 } {
521531 res .Header .Del (headerName )
522532 }
@@ -559,7 +569,9 @@ func solveCaptchaViaProxy(redirectURI string, dialer *dnsdialer.Dialer) (string,
559569 })
560570
561571 mux .HandleFunc ("/" , func (w http.ResponseWriter , r * http.Request ) {
572+ log .Printf ("[Captcha Proxy] HTTP %s %s" , r .Method , r .URL .String ())
562573 if r .URL .Path == "/" && targetURL .Path != "" && targetURL .Path != "/" && r .URL .RawQuery == "" {
574+ log .Printf ("[Captcha Proxy] Redirecting ROOT to: %s" , localCaptchaURLForTarget (targetURL ))
563575 http .Redirect (w , r , localCaptchaURLForTarget (targetURL ), http .StatusTemporaryRedirect )
564576 return
565577 }
0 commit comments