url icon indicating copy to clipboard operation
url copied to clipboard

assertion in `resolve`

Open madmongo1 opened this issue 2 years ago • 2 comments

The following code:

    boost::urls::resolve(url, loc, url, ec);
```

Asserts, because the base and dest are the same object. 
When performing a client redirect, I would prefer to avoid writing this code:

```
  auto new_url = boost::urls::url();
  boost::urls::redirect(my_url, new_loc, new_url, ec);
  if (!ec) {
    my_url = std::move(new_url);  // feels redundant. Can't the library do this for me?
    goto do_redirect;
  }
``` 

madmongo1 avatar Aug 13 '22 17:08 madmongo1

We could provide this overload

void resolve( url_base& base, url_view_base const& ref, error_code& ec );

Actually this could be a member function of url_base

void url_base::resolve( url_view_base const& ref, error_code& ec );

vinniefalco avatar Aug 13 '22 17:08 vinniefalco

This is my workaround:

Call site:

                    // perform the redirect by updating the URL and jumping to
                    // the goto label above.
                    url = resolve_redirect(
                        url,
                        boost::urls::url_view(
                            response[beast::http::field::location]));
                    goto again;

implementation:

boost::urls::url
resolve_redirect(boost::urls::url_view original, boost::urls::url_view loc)
{
    auto result = boost::urls::url();
    auto ec     = error_code();
    boost::urls::resolve(original, loc, result, ec);
    if (ec)
        throw system_error(ec, "failed to resolve redirect Location");
    return result;
}

madmongo1 avatar Aug 13 '22 17:08 madmongo1