Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -82,45 +82,44 @@ zerogpu_fix_js = """
|
|
| 82 |
|
| 83 |
const headerMap = headers instanceof Map ? headers : new Map(Object.entries(headers));
|
| 84 |
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
};
|
| 124 |
console.log("ZeroGPU Fix: Fetch interceptor installed.");
|
| 125 |
} else {
|
| 126 |
console.warn("ZeroGPU Fix: No headers received from parent.");
|
|
|
|
| 82 |
|
| 83 |
const headerMap = headers instanceof Map ? headers : new Map(Object.entries(headers));
|
| 84 |
|
| 85 |
+
headerMap.forEach((value, key) => {
|
| 86 |
+
// Force lowercase keys to avoid case mismatch
|
| 87 |
+
key = key.toLowerCase();
|
| 88 |
+
if (options.headers instanceof Headers) {
|
| 89 |
+
options.headers.set(key, value); // Use set instead of append to avoid duplicates
|
| 90 |
+
} else {
|
| 91 |
+
options.headers[key] = value;
|
| 92 |
+
}
|
| 93 |
+
});
|
| 94 |
+
return options;
|
| 95 |
+
};
|
| 96 |
+
|
| 97 |
+
if (headers) {
|
| 98 |
+
console.log("ZeroGPU Fix: Received initial headers", headers);
|
| 99 |
+
|
| 100 |
+
const originalFetch = window.fetch;
|
| 101 |
+
window.fetch = async function(url, options) {
|
| 102 |
+
console.log("ZeroGPU Fix: Intercepting request to", url);
|
| 103 |
+
|
| 104 |
+
if (!options) options = {};
|
| 105 |
+
// Inject headers for ALL requests to be safe
|
| 106 |
+
try {
|
| 107 |
+
// Attempt to refresh headers
|
| 108 |
+
const currentHeaders = await post_message("zerogpu-headers");
|
| 109 |
+
if (currentHeaders) {
|
| 110 |
+
options = updateHeaders(options, currentHeaders);
|
| 111 |
+
console.log("ZeroGPU Fix: Injected FRESH headers");
|
| 112 |
+
} else {
|
| 113 |
+
options = updateHeaders(options, headers);
|
| 114 |
+
console.log("ZeroGPU Fix: Injected CACHED headers (refresh failed)");
|
| 115 |
+
}
|
| 116 |
+
} catch (e) {
|
| 117 |
+
options = updateHeaders(options, headers);
|
| 118 |
+
console.log("ZeroGPU Fix: Injected CACHED headers (error)");
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
return originalFetch(url, options);
|
| 122 |
+
};
|
|
|
|
| 123 |
console.log("ZeroGPU Fix: Fetch interceptor installed.");
|
| 124 |
} else {
|
| 125 |
console.warn("ZeroGPU Fix: No headers received from parent.");
|