Skip to content

Automatically sending Transfer-Encoding: chunked but I want to send Content-Length #1835

Closed Answered by MacroMelon
MacroMelon asked this question in Q&A
Discussion options

You must be logged in to vote

It turns out I was going about this wrong, I re-wrote it to use tryEnd and onWritable instead of write:

-- EDIT- IMPORTANT NOTE: I'm not too sure about this anymore because I noticed the while loop could potentially block the event loop for way too long if no backpressure occurs, so I don't recommend using this solution --

void initSendFile(HttpResponse<true> *clientConnection, std::string filePath) {

    //start sending a file in chunks to the client (handles backpressure, creates appropriate onwritable callback)
    std::shared_ptr<std::ifstream> in = std::make_shared<std::ifstream>(filePath, std::ios::in | std::ios::binary);
    uintmax_t fileSize = std::filesystem::file_size(std::fil…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by MacroMelon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant