Is it possible to answer http requests in parts? #2772
Unanswered
Douglasgomestosta
asked this question in
Q&A
Replies: 1 comment
-
as I couldn't solve this problem, I decided to delete the code in bun and do the same in Nodejs using expressjs using res.write and res.end command... |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is it possible to answer Bun's http requests in parts? for example, sending part 1, then part 2 and then terminating the request?
in my code, the user makes a request with the name of a file, I request the file from another server using http.request and then send it to the user using "return new Response(file, {
headers: {
"Content-Type": "video/mp4",
},
});"
the problem is that with small files there is no inconvenience but with large files it takes too long for the server to respond to it, it can take up to 82 seconds to send an 82mb video(the video doesn't start until it finishes, since bun only starts sending data after downloading the whole video)
the code that downloads the media from the other server is this
async function get_image_url(url){ return new Promise((resolve, reject) => { http.request(url, function(response) { if(response.statusCode !== 200) { resolve("ERROR"); return false; } var data = new Stream(); response.on('data', function(chunk) { data.push(chunk); }); response.on('end', function() { resolve(data.read()); }); response.on('error', function(err) { resolve("ERROR"); }); }).end(); }); }
Beta Was this translation helpful? Give feedback.
All reactions