diff --git a/messagix/client.go b/messagix/client.go index 7e5e789..0d07315 100644 --- a/messagix/client.go +++ b/messagix/client.go @@ -86,8 +86,7 @@ func NewClient(cookies *cookies.Cookies, logger zerolog.Logger) *Client { ResponseHeaderTimeout: 40 * time.Second, ForceAttemptHTTP2: true, }, - CheckRedirect: checkHTTPRedirect, - Timeout: 60 * time.Second, + Timeout: 60 * time.Second, }, cookies: cookies, Logger: logger, @@ -97,6 +96,7 @@ func NewClient(cookies *cookies.Cookies, logger zerolog.Logger) *Client { activeTasks: make([]int, 0), taskMutex: &sync.Mutex{}, } + cli.http.CheckRedirect = cli.checkHTTPRedirect cli.configurePlatformClient() cli.configs = &Configs{ diff --git a/messagix/http.go b/messagix/http.go index 9755b6b..25b1f7e 100644 --- a/messagix/http.go +++ b/messagix/http.go @@ -8,6 +8,7 @@ import ( "net/http" "net/url" "strconv" + "strings" "time" "go.mau.fi/mautrix-meta/messagix/cookies" @@ -94,10 +95,20 @@ func isPermanentRequestError(err error) bool { errors.Is(err, ErrConsentRequired) } -func checkHTTPRedirect(req *http.Request, _ []*http.Request) error { +func (c *Client) checkHTTPRedirect(req *http.Request, via []*http.Request) error { if req.Response == nil { return nil } + if !strings.HasSuffix(req.URL.Hostname(), "fbcdn.net") && !strings.HasSuffix(req.URL.Hostname(), "facebookcooa4ldbat4g7iacswl3p2zrf5nuylvnhxn6kqolvojixwid.onion") { + var prevURL string + if len(via) > 0 { + prevURL = via[0].URL.String() + } + c.Logger.Warn(). + Stringer("url", req.URL). + Str("prev_url", prevURL). + Msg("HTTP request was redirected") + } if req.URL.Path == "/challenge/" { return fmt.Errorf("%w: redirected to %s", ErrChallengeRequired, req.URL.String()) } else if req.URL.Path == "/consent/" || req.URL.Path == "/privacy/consent/" {