cpp-netlib/uri

uri_builder unable to reset fields.

Closed this issue · 3 comments

The following code still prints the userid:password field when I try to obfuscate it by making a clone of an URI and explicitly resetting the user_info field. The reason this happens is that the fields are boost::optional. There should be some way to invoke reset on these optional fields to make them reset once more. The alternative is to either explicitly parse out the 'userid:password@' field from my ftp URI or start a uri_builder from scratch and reinitialize the fields.

John

if (CURLE_OK != res) {
    // we failed
    network::uri_builder bldr(rFTPUri);
    // reset the boost optional field
    bldr.user_info(network::uri::string_type());
    std::stringstream ss;
    ss << "error [" << curl_easy_strerror(res)
        << "] uri [" << bldr.uri() << "]" << std::endl;
    if (res == CURLE_REMOTE_FILE_NOT_FOUND) {
        throw UtlFileNotFoundException(ss.str());
    } else {
        throw UtlIOException(ss.str());
    }
} else {

Could you tell me if passing boost::optional<string_type> works?

I am not able to get that to work, I tried the following, however the compiler does not accept the bldr.user_info(boost::optionalstd::string()); line - complaining error C2079: 'impl' uses undefined struct 'network::detail::translate_impl' - I assume that string_type is network::uri_builder::string_type() in the example above to match the embedded optional field types in the uri builder. Note that the line bldr.user_info(network::uri::string_type()); leaves the bldr.uri().string() with the embedded @ symbol i.e. foo://@abc.def - which although technically correct is not the same as a default uninitialized user_info field which prints ftp://abc.def

John

network::uri_builder bldr;
bldr.scheme("ftp").host("abc.def").user_info(network::uri::string_type());
// foo will contain http://@abc.def
std::string foo = bldr.uri().string();
bldr.user_info(network::uri_builder::string_type());
// bar will contain http://@abc.def
std::string bar = bldr.uri().string();

Works well, thanks, BTW clear_all would be a nice useful addition when recycling a network::uri_builder