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:

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::filesystem::path(filePath));
    std::shared_ptr<char[]> buffer = std::make_shared<char[]>(bigResponseChunkSize);

    std::cout << fileSize << " bytes size" << std::endl;

    std::function trySendTillEnd = [clientConnectio…

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