Skip to content

Ranges that are not in the form 0-n do not work. #2157

Open
@NikkiOfTheValley

Description

@NikkiOfTheValley

The library makes several bad assumptions in range_error and in a few other places that I haven't been able to track down that ranges are always from zero and that the body field of the response contains the entire file (this makes no sense. Why would you want to waste disk space and time getting the entire file rather than just a smaller chunk of it?), as ranges that are not formatted like that cause range errors. If I comment out the range_error call in the library, it still doesn't work.
The reason why this needs to be implemented is that video streaming needs the ability to get an arbitrary range of bytes.

This is my code for handling range requests:

std::ostringstream sstr;
std::string data = "";

if (req.ranges.size() != 0)
{
    Range range = req.ranges[0];

    ssize_t numBytes = range.second == -1 ? 1024 : range.second - range.first;
    ssize_t offset = range.first;

    data.resize(numBytes + 1);

    inputFile.seekg(offset);
    numBytes = inputFile.readsome(data.data(), numBytes);

    res.set_content(data.data(), numBytes, "video/webm");
    res.content_length_ = numBytes;
    logger->log("numbytes:" + std::to_string(numBytes));

    inputFile.close();
}
else
{
    sstr << inputFile.rdbuf();
    data = sstr.str();
    inputFile.close();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions