class

Vug::GrayPlaceholderHandler

Inherits Reference < Object

Detects gray/placeholder favicon images and generates fallback URLs. Extracted from Fetcher to follow Single Responsibility Principle.

Constants

DDG_DEFAULT_ICON_SIZE = 2441

DuckDuckGo's default icon returned when it has no real favicon for a domain. This is a 32x32 PNG always at exactly 2441 bytes.

DDG_IP3_PATTERN = /\/ip3\/(.+?)\.ico\z/

Regex to extract domain from DuckDuckGo /ip3/{domain}.ico URLs.

GOOGLE_FAVICON_SIZE = 256

Google favicon API size parameter — kept as a local constant for google_larger_url regex replacement within this handler.

MAX_FALLBACK_ATTEMPTS = 3

Upper bound on the number of fallback attempts the fetch loop will make when it keeps receiving gray placeholders. The loop terminates with a :too_many_gray_placeholder_attempts error once the counter reaches this value.

Constructors

new(config : Config, cache_coordinator : CacheCoordinator | Nil)
Source

Instance methods

cached_larger_version(url : String) : String | Nil

Try to find a cached larger version of a gray placeholder. Returns the cached path if found, nil otherwise.

Source
fallback_url(current_url : String) : String | Nil

Generate a fallback URL for fetching a non-gray version of the favicon.

Source
gray_placeholder?(url : String, data : Bytes | Nil) : Bool

Returns true if the fetched data is a known gray placeholder image.

Source
store_larger_version(url : String, cached_path : String) : Nil

Store a cached path under the original URL key.

Source