A fast and efficient favicon fetching service built in Rust. GetIcon provides a simple HTTP API to retrieve favicons from any website, with built-in caching and performance optimizations.
- π Simple REST API endpoints for both image and JSON responses
- π¦ Server-side caching for consistent results
- π ETag support for efficient client-side caching
- β‘ HTTP cache headers for improved performance
- π Support for any website's favicon.ico
- π Built-in HTML documentation page
- π Smart icon selection with size parameter support
- π± Detection of multiple icon types (favicon.ico, Apple Touch, Web App Manifest)
- π Docker support for easy deployment
- π Sentry integration for error monitoring (optional)
- Ensure you have Rust installed (1.75.0 or later)
- Clone the repository:
git clone https://github.com/yourusername/geticon.git
cd geticon- Build and run:
cargo runThe server will start at http://localhost:8080
- Pull the Docker image:
docker pull ghcr.io/snapbooks-app/geticon:latest- Run the container:
docker run -p 8080:8080 ghcr.io/snapbooks-app/geticon:latestOr use Docker Compose:
# docker-compose.yml
version: '3'
services:
geticon:
image: ghcr.io/snapbooks-app/geticon:latest
ports:
- "8080:8080"
environment:
- RUST_LOG=info # Controls log level
- SENTRY_DSN=your_sentry_dsn # Optional
- SENTRY_ENVIRONMENT=production # OptionalThen run:
docker-compose up -dGetIcon is in production use at snapbooks.no.
GET /img?url={website-url}
Optional: Specify size with the size parameter:
GET /img?url={website-url}&size={size}
GET /json?url={website-url}
Optional: Specify size with the size parameter:
GET /json?url={website-url}&size={size}
GET /health
Returns a JSON response with service status information.
To fetch GitHub's favicon as an image:
GET http://localhost:8080/img?url=github.com
To fetch Microsoft's favicon at 192px size:
GET http://localhost:8080/img?url=microsoft.com&size=192
To get JSON information about Google's favicon:
GET http://localhost:8080/json?url=google.com
- Success: Returns the favicon with appropriate content type (image/png, image/x-icon, etc.)
- Not Found: Returns 404 if favicon doesn't exist
- Not Modified: Returns 304 if favicon hasn't changed (when using ETag)
Returns a JSON object with:
url: The normalized URLicons: Array of all detected icons with their propertiesbest_icon: The selected best icon based on scoring algorithm
GetIcon implements efficient caching through:
- Server-side in-memory cache with 2-hour TTL
- Consistent icon selection for the same URL and size
- ETag headers for client-side caching
- Cache-Control headers with a 2-hour max age
- 304 Not Modified responses when content hasn't changed
GetIcon searches for icons in multiple locations:
- Standard favicon.ico in site root
- HTML link tags with rel="icon", "shortcut icon", etc.
- Apple Touch icons
- Web App Manifest icons
- Microsoft Tile images
- Open Graph images (as fallback)
GetIcon uses device-specific User-Agent strings to improve compatibility with websites that implement strict security measures:
- Apple Touch Icons: iOS/Safari User-Agent
- Android/Maskable Icons: Android/Chrome User-Agent
- Microsoft Tile Images: Windows/Edge User-Agent
- Standard Icons: Windows/Chrome User-Agent
The User-Agent strings are periodically updated from useragents.me to ensure they remain current and effective.
To keep the service working optimally with all websites, the User-Agent strings should be updated periodically (recommended: every 3-6 months) by checking the latest common User-Agents at useragents.me.
The following environment variables can be configured:
| Variable | Description | Default |
|---|---|---|
| RUST_LOG | Controls log filtering (e.g., info, geticon=debug, debug) |
info |
| SENTRY_DSN | Sentry DSN for error monitoring | (none) |
| SENTRY_ENVIRONMENT | Environment name for Sentry | production |
Built with:
- Rust
- Actix-web framework for the HTTP server
- reqwest for HTTP requests
- scraper for HTML parsing
- serde for JSON serialization
- md5 for ETag generation
- moka for high-performance in-memory caching
- log and env_logger for structured logging
- sentry for error monitoring
See LICENSE file for details.