LiuZichen commited on
Commit
73ff2a0
·
verified ·
1 Parent(s): 95cc63b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -39
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
- headerMap.forEach((value, key) => {
86
- if (options.headers instanceof Headers) {
87
- options.headers.append(key, value);
88
- } else {
89
- options.headers[key] = value;
90
- }
91
- });
92
- return options;
93
- };
94
-
95
- if (headers) {
96
- console.log("ZeroGPU Fix: Received initial headers", headers);
97
-
98
- const originalFetch = window.fetch;
99
- window.fetch = async function(url, options) {
100
- // Inject headers for ALL requests to be safe, especially queue/join
101
- // We filter out only obviously external or static asset requests if needed,
102
- // but for debugging, let's be aggressive.
103
- if (typeof url === 'string' && (url.includes('/queue/') || url.includes('/api/') || url.includes('run/predict'))) {
104
- console.log("ZeroGPU Fix: Intercepting request to", url);
105
-
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
-
122
- return originalFetch(url, options);
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.");