magicseth
magicseth2y ago

HTTP returning blobs are all length 0.

I've got a proxy that was working, but now seems to not work. The server logs are printing out the correct blob size, but my browser is saying content-length = 0
const proxy = httpAction(async ({}, request) => {
// treat everything after the real domain as the url to proxy
console.log("PROXY", request.url);
let urlToCheck = new URL(request.url).pathname.slice(7);
if (urlToCheck.startsWith("//")) {
urlToCheck = "https:" + urlToCheck;
}
const url = new URL(urlToCheck);

console.log("PROXY", url);
const resp = await fetch(url);
console.log("PROXY", resp);
const blob = await resp.blob();
console.log("PROXY", blob);
// return resp;
// const body = await resp.text();
return new Response(blob, {
headers: {
"content-type": resp.headers.get("content-type") || "image/png",
"content-length": resp.headers.get("content-length") || "0",
},
status: 200,
});
});
const proxy = httpAction(async ({}, request) => {
// treat everything after the real domain as the url to proxy
console.log("PROXY", request.url);
let urlToCheck = new URL(request.url).pathname.slice(7);
if (urlToCheck.startsWith("//")) {
urlToCheck = "https:" + urlToCheck;
}
const url = new URL(urlToCheck);

console.log("PROXY", url);
const resp = await fetch(url);
console.log("PROXY", resp);
const blob = await resp.blob();
console.log("PROXY", blob);
// return resp;
// const body = await resp.text();
return new Response(blob, {
headers: {
"content-type": resp.headers.get("content-type") || "image/png",
"content-length": resp.headers.get("content-length") || "0",
},
status: 200,
});
});
2 Replies
lee
lee2y ago
hi! we can repro and we're looking at it. sorry for the issue This should be resolved now. Thanks for reporting! (we've been working on supporting more kinds of Request/Response and a bug slipped through. a new regression test should make sure it doesn't happen again)
magicseth
magicsethOP2y ago
Thank you!

Did you find this page helpful?