Skip to content

Commit 0f43b2c

Browse files
committed
Fall through sharedPrefetch when proxy returns non-2xx
Joe says: What Claude says below is accurate, no more notes on functionality Emmanuel had reported an issue with loading shared images and shared programs on pyret.bootstrapworld.org. There was indeed a problem where the proxy for shared URLs could report failures *from the proxy* when the file had actually been published or added on PBO. This fixes that issue with the "proxy back to CPO for legacy share URLs" feature. Claude says: The /shared-image-contents, /shared-program-contents, and /shared-file endpoints try the SHARED_FETCH_SERVER proxy first and fall back to a local Drive fetch on failure. sharedPrefetch was resolving on any HTTP response from the upstream, including 4xx, which meant the upstream's error body got piped straight back to the client — the local fallback never ran. For shares minted on this deploy and unknown to the proxy server (e.g., PBO or pyret-horizon proxying through CPO), this turned every fetch into a 400 "Could not access shared file" instead of falling through to the local fetch where it would have succeeded. Only resolve sharedPrefetch on 2xx; abort the in-flight request and reject otherwise, so the existing .fail handlers do their job.
1 parent b2a67fc commit 0f43b2c

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/server.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,19 @@ function start(config, onServerReady) {
861861
if(config.sharedFetchServer) {
862862
let response = request({url: url});
863863
response.on("error", (error) => { ret.reject(error); });
864-
response.on("response", (resp) => ret.resolve(response));
864+
response.on("response", (resp) => {
865+
// Only treat 2xx as a real proxy hit. A 4xx from the upstream
866+
// (e.g. when the shared id was minted on *this* deploy and the
867+
// proxy server has no record of it) must fall through to the
868+
// local Drive fetch — otherwise the upstream error body gets
869+
// piped straight back to the client.
870+
if (resp.statusCode >= 200 && resp.statusCode < 300) {
871+
ret.resolve(response);
872+
} else {
873+
response.abort();
874+
ret.reject("Proxy returned status " + resp.statusCode);
875+
}
876+
});
865877
}
866878
else {
867879
ret.reject("No fallback server configured");

0 commit comments

Comments
 (0)