Hi, i’m working on Cloudflare workers scheduler which i used to fetch api from Cloudflare to call several requests but i am facing content-type: null when i request on http protocol but for https it working normally can anyone help me with this?
** But in local i can call http protocol via fetch normally.
this is my code
async function gatherResponse(response: any, url: string) {
const { headers } = response;
const contentType = headers.get("content-type") || "";
console.log("url", url);
console.log("response", JSON.stringify(response));
console.log("content-type", headers.get("content-type"));
if (contentType.includes("application/json")) {
return response.json();
}
return response.text();
}
export default {
async scheduled(
controller: ScheduledController,
env: Env,
ctx: ExecutionContext
): Promise<void> {
const responses = await Promise.all(
urls.map((url) => {
return fetch(url, {
method: "post",
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
body: JSON.stringify({
message: "hello",
}),
}).then((res) => gatherResponse(res, url));
})
);
console.log("responses", JSON.stringify(responses));
},
};