Skip to content

Instantly share code, notes, and snippets.

@Kakarot-2000
Last active August 22, 2021 09:09
Show Gist options
  • Save Kakarot-2000/dd75d52c44f0cd35c913a3e2fa713a4c to your computer and use it in GitHub Desktop.
Save Kakarot-2000/dd75d52c44f0cd35c913a3e2fa713a4c to your computer and use it in GitHub Desktop.
fetch("http://127.0.0.1:5000/getSummary", {
"body": JSON.stringify({"url":"https://owasp.org/www-community/attacks/csrf"}),
"method": "POST",
"headers":{
"Content-Type": "application/json"
}
}).then(response=> response.body). then(rb => {
const reader = rb.getReader();
return new ReadableStream({
start(controller) {
// The following function handles each data chunk
function push() {
// "done" is a Boolean and value a "Uint8Array"
reader.read().then( ({done, value}) => {
// If there is no more data to read
if (done) {
controller.close();
return;
}
// Get the data and send it to the browser via the controller
controller.enqueue(value);
push();
})
}
push();
}
});
})
.then(stream => {
// Respond with our stream
return new Response(stream, { headers: { "Content-Type": "text/html" } }).text();
})
.then(result => {
// Do things with result
console.log('Response : ',result);
})
.catch(e=>console.log('Error : ',e));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment