Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Readme.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ There is not a lot to configure, but these environment variables exist
| `CORS_ALLOW_CREDENTIALS` | Boolean, passed to middleware | |
| `CORS_DEBUG` | Boolean, passed to middleware | |
| `DISABLE_BROWSE_PAGES` | Boolean, if true, the server will not serve any of the HTML pages | false |
| `DISABLE_LETTER_FALLBACK` | Boolean, if true, missing website icons return an empty 204 response instead of redirecting to a generated letter icon | false |
| `HOST_ONLY_DOMAINS` | | \* |
| `HTTP_CLIENT_TIMEOUT` | Timeout used for HTTP requests. Supports units like ms, s, m. | 5s |
| `HTTP_MAX_AGE_DURATION` | Cache duration for all dynamically generated HTTP responses. Supports units like ms, s, m. | 720h _(30 days)_ |
Expand Down
6 changes: 6 additions & 0 deletions besticon/iconserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ func (s *server) iconHandler(w http.ResponseWriter, r *http.Request) {
return
}

if getTrueFromEnv("DISABLE_LETTER_FALLBACK") {
addCacheControl(w, s.cacheDuration)
w.WriteHeader(http.StatusNoContent)
return
}

iconColor := finder.MainColorForIcons()
letter := lettericon.MainLetterFromURL(url)

Expand Down
18 changes: 18 additions & 0 deletions besticon/iconserver/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,24 @@ func TestGetIconWith404Page(t *testing.T) {
assertStringEquals(t, "/lettericons/H-32.png", w.Header().Get("Location"))
}

func TestGetIconWithLetterFallbackDisabled(t *testing.T) {
t.Setenv("DISABLE_LETTER_FALLBACK", "true")

req, err := http.NewRequest("GET", "/icons?size=32&url=httpbin.org/status/404", nil)
if err != nil {
log.Fatal(err)
}

w := httptest.NewRecorder()
s := newTestServer()
s.iconHandler(w, req)

assertStringEquals(t, "204", fmt.Sprintf("%d", w.Code))
assertStringEquals(t, "max-age=2592000", w.Header().Get("Cache-Control"))
assertStringEquals(t, "", w.Header().Get("Location"))
assertStringEquals(t, "", w.Body.String())
}

func TestGet404IconWithFallbackColor(t *testing.T) {
req, err := http.NewRequest("GET", "/icons?size=32&url=httpbin.org/status/404&fallback_icon_color=123456", nil)
if err != nil {
Expand Down