Getting this problem below. How do I put and get values for both event.response.headers and event.response.body?
Please help. Thanks in advance.
worker.js:6 Uncaught (in promise) TypeError: KV put() accepts only strings, ArrayBuffers, ArrayBufferViews, and ReadableStreams as values.
at handleRequest (VM3 worker.js:6)
async function handleRequest(request) {
const response = await fetch(url)
const results = await gatherResponse(response)
//let cloneResponse = results.clone()
EDGE_CACHE.put("h",results.headers)
EDGE_CACHE.put("b",results.Body)
let body123 = EDGE_CACHE.get("b")
return new Response(body123,results)
//return new Response(results.body,results)
}
addEventListener('fetch', event => {
return event.respondWith(handleRequest(event.request))
})
/**
* gatherResponse awaits and returns a response body as a string.
* Use await gatherResponse(..) in an async function to get the response body
* @param {Response} response
*/
async function gatherResponse(response) {
const { headers } = response
const contentType = headers.get('content-type')
if (contentType.includes('application/json')) {
console.log("z");
return await response.json()
} else if (contentType.includes('application/text')) {
console.log("a")
return await response.text()
} else if (contentType.includes('text/html')) {
console.log("b")
//return await response.text()
return await response
} else {
console.log("c");
return await response.text()
}
}
/**
* Example someHost at url is set up to respond with HTML
* Replace url with the host you wish to send requests to
* */
//const someHost = 'https://workers-tooling.cf/demos'
const someHost = 'https://community.cloudflare.com'
const url = someHost + '/t/anyone-using-fauna-with-workers/175419'