Explorar el Código

fix(finder): do not add redirections to the list of subscriptions to avoid confusion

Frédéric Guillot hace 1 año
padre
commit
e9520f5d1c

+ 9 - 0
internal/reader/fetcher/response_handler.go

@@ -89,6 +89,15 @@ func (r *ResponseHandler) IsModified(lastEtagValue, lastModifiedValue string) bo
 	return true
 }
 
+func (r *ResponseHandler) IsRedirect() bool {
+	return r.httpResponse != nil &&
+		(r.httpResponse.StatusCode == http.StatusMovedPermanently ||
+			r.httpResponse.StatusCode == http.StatusFound ||
+			r.httpResponse.StatusCode == http.StatusSeeOther ||
+			r.httpResponse.StatusCode == http.StatusTemporaryRedirect ||
+			r.httpResponse.StatusCode == http.StatusPermanentRedirect)
+}
+
 func (r *ResponseHandler) Close() {
 	if r.httpResponse != nil && r.httpResponse.Body != nil && r.clientErr == nil {
 		r.httpResponse.Body.Close()

+ 10 - 1
internal/reader/subscription/finder.go

@@ -228,8 +228,17 @@ func (f *SubscriptionFinder) FindSubscriptionsFromWellKnownURLs(websiteURL strin
 			localizedError := responseHandler.LocalizedError()
 			responseHandler.Close()
 
+			// Do not add redirections to the possible list of subscriptions to avoid confusion.
+			if responseHandler.IsRedirect() {
+				slog.Debug("Ignore URL redirection during feed discovery", slog.String("fullURL", fullURL))
+				continue
+			}
+
 			if localizedError != nil {
-				slog.Debug("Unable to subscribe", slog.String("fullURL", fullURL), slog.Any("error", localizedError.Error()))
+				slog.Debug("Ignore invalid feed URL during feed discovery",
+					slog.String("fullURL", fullURL),
+					slog.Any("error", localizedError.Error()),
+				)
 				continue
 			}