Skip to content

Commit 9109940

Browse files
committed
fix(favicons): keep the presenter's 204 literal and read only a 200 body before one classification
1 parent a87bfde commit 9109940

3 files changed

Lines changed: 5 additions & 7 deletions

File tree

‎apps/sim/app/api/favicon/route.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const GET = defineInternalBinaryRoute({
3232
},
3333
}
3434
: {
35-
status: 204,
35+
status: 204 as const,
3636
headers: {
3737
'Cache-Control': favicon.kind === 'miss' ? 'private, max-age=3600' : 'no-store',
3838
},

‎apps/sim/lib/favicon/hosts.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const HOST_SHAPE = /^[^\s/?#@\\]+$/
66
/**
77
* Hosts to ask a favicon provider about, most specific first. A private tenant such as
88
* `acme.atlassian.net` is invisible to providers, but its platform is not, so each parent
9-
* domain follows, stopping before the ICANN public suffix (`gitlab.io` is a valid last step;
9+
* domain follows — at most three, stopping before the ICANN public suffix (`gitlab.io` is a valid last step;
1010
* `io` and `co.uk` are not). Internal hosts — IP literals, single labels, and names outside
1111
* the public DNS — yield nothing, so they never leave the server, and neither does a name with
1212
* characters DNS can't hold, which could otherwise reshape a provider's URL.

‎apps/sim/lib/favicon/resolve.server.ts‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,9 @@ async function askProvider(url: string, signal: AbortSignal): Promise<FaviconRes
7878
signal,
7979
headers: { Accept: 'image/png,image/x-icon,image/jpeg,image/gif,image/webp' },
8080
})
81-
if (response.status !== 200) {
82-
await response.body?.cancel().catch(() => {})
83-
return classifyProviderResponse(response.status, new Uint8Array())
84-
}
85-
const bytes = Buffer.from(await response.arrayBuffer())
81+
let bytes = Buffer.alloc(0)
82+
if (response.status === 200) bytes = Buffer.from(await response.arrayBuffer())
83+
else await response.body?.cancel().catch(() => {})
8684
const result = classifyProviderResponse(response.status, bytes)
8785
return result.kind === 'hit' ? { ...result, bytes } : result
8886
} catch (error) {

0 commit comments

Comments
 (0)