@@ -175,6 +175,11 @@ async function handleRequest(request, env, ctx) {
175175
176176 // Check if this is a Hugging Face API request
177177 const isHF = isHuggingFaceAPIRequest ( request , url ) ;
178+ const shouldVaryCacheByOrigin =
179+ platform === 'flathub' && isFlatpakReferenceFilePath ( effectivePath ) ;
180+ const cacheTargetUrl = shouldVaryCacheByOrigin
181+ ? `${ targetUrl } ${ targetUrl . includes ( '?' ) ? '&' : '?' } __xget_origin=${ encodeURIComponent ( url . origin ) } `
182+ : targetUrl ;
178183 const canUseCache = request . method === 'GET' || request . method === 'HEAD' ;
179184 const shouldPassthroughRequest =
180185 isGit || isGitLFS || isDocker || isAI || isHF || ! canUseCache ;
@@ -199,7 +204,7 @@ async function handleRequest(request, env, ctx) {
199204 ) {
200205 try {
201206 // For Range requests, try cache match first
202- const cacheKey = new Request ( targetUrl , {
207+ const cacheKey = new Request ( cacheTargetUrl , {
203208 method : 'GET' ,
204209 headers : request . headers
205210 } ) ;
@@ -211,7 +216,7 @@ async function handleRequest(request, env, ctx) {
211216 // If Range request missed cache, try with original request to see if we have full content cached
212217 const rangeHeader = request . headers . get ( 'Range' ) ;
213218 if ( rangeHeader ) {
214- const fullContentKey = new Request ( targetUrl , {
219+ const fullContentKey = new Request ( cacheTargetUrl , {
215220 method : 'GET' , // Always use GET method for cache key consistency
216221 headers : new Headers (
217222 [ ...request . headers . entries ( ) ] . filter (
@@ -631,15 +636,15 @@ async function handleRequest(request, env, ctx) {
631636 ) {
632637 const rangeHeader = request . headers . get ( 'Range' ) ;
633638 const cacheKey = rangeHeader
634- ? new Request ( targetUrl , {
639+ ? new Request ( cacheTargetUrl , {
635640 method : 'GET' ,
636641 headers : new Headers (
637642 [ ...request . headers . entries ( ) ] . filter (
638643 ( [ k ] ) => k . toLowerCase ( ) !== 'range'
639644 )
640645 )
641646 } )
642- : new Request ( targetUrl , { method : 'GET' } ) ;
647+ : new Request ( cacheTargetUrl , { method : 'GET' } ) ;
643648
644649 try {
645650 if ( ctx && typeof ctx . waitUntil === 'function' ) {
@@ -652,7 +657,7 @@ async function handleRequest(request, env, ctx) {
652657
653658 if ( rangeHeader && response . status === 200 ) {
654659 const rangedResponse = await cache . match (
655- new Request ( targetUrl , {
660+ new Request ( cacheTargetUrl , {
656661 method : 'GET' ,
657662 headers : request . headers
658663 } )
0 commit comments