Mmm I'm only passing the request.body to the put function via the worker
Mmm I'm only passing the request.body to the put function via the worker



%23
get: The specified method is not allowed against this resource (10060)
%23function retrieve (url, env) {
const path = url.hostname + url.pathname;
const split = path.split("/");
const tmpIndex = split.indexOf("tmp");
if (tmpIndex >= 0) {
split.splice(tmpIndex, 1);
const bucket = env.TMP_BUCKET;
const key = split.join("/");
return bucket.get(key);
} else {
const bucket = env.BIG_BUCKET;
const key = split.join("/");
return bucket.get(key);
}
}
export default {
async fetch (request, env, context) {
const cache = await caches.open("r2");
const cachedResponse = await cache.match(request);
if (cachedResponse)
return cachedResponse;
const object = await retrieve(new URL(request.url), env);
if (object === null)
return fetch(request);
const body = await object.body;
const headers = new Headers();
object.writeHttpMetadata(headers);
headers.set('etag', object.httpEtag);
headers.append('Cache-Control', 's-maxage=691200');
const response = new Response(body, { headers });
const range = request.headers.get("Range");
if (range === null) {
context.waitUntil(cache.put(request, response.clone()));
return response;
} else {
await cache.put(request, response);
return cache.match(request);
}
}
};await env.Testing_bucket.put(key, request.body, request.headers);