How to create a response from a file that has CJK filename

134 views Asked by At

I'm trying to load a file to be a HTTP response with Boost.Beast, but it doesn't work on Windows. My code is similar to this:

typedef boost::beast::http::response<boost::beast::http::file_body> response_t;

response_t render_response_from_file(const std::filesystem::path& paFile)
{
    boost::beast::http::file_body::value_type body;
    body.open(paFile.c_str(), boost::beast::file_mode::scan, ec);
    ...
}

Method open won't be able to find the local file, if the filename contains any CJK character. I've tried to pass paFile.u8string().c_str() instead of paFile.c_str() as the 1st argument, but in vain. Any suggestion? Thanks.

By the way, on Linux, there is no such problem, because the file-systems on Linux usually use UTF-8 char strings to be filenames, not like Windows uses UTF16 wchar_t strings. It seems that the conversion to UTF-8 has Windows unable to find the file. However, without the conversion, I don't know if there is any other way to open the file to the boost::beast::http::file_body::value_type object.

1

There are 1 answers

1
sehe On

It looks like this may have been fixed in Boost 1.79.0 - can you give that a try?

For context: