curl / Mailing Lists / curl-library / Single Mail


Re: a URL API ?

From: Daniel Stenberg <>
Date: Fri, 3 Aug 2018 12:32:10 +0200 (CEST)

On Fri, 3 Aug 2018, Samuel Hurst wrote:

> For example, being able to build new
> URLs from relative ones. I can't quite tell from the examples provided
> whether curl_url would do relative transformation if the urlhandle is already
> valid. I can see a use case where I'd want to do the following:
> CURLURL *url_handle = NULL;
> curl_url("", url_handle, 0);
> ...
> curl_url("/image.png", url_handle, 0);

Ah, yes. I like this suggestion - even if "/image.png" could've been handled
with just setting a new path. I suppose "../image.png" or something would be a
better example.

As for the specific API to deal with a relative URL, I think I prefer to have
it not overload curl_url() for that. As I prefer the "alternative B" API, I
think we can just add a dedicated CURLUPart for a relative URL. Then it would
be used like this:

   curl_url("", &url_handle, 0);

   curl_url_set(url_handle, CURLUPART_RELURL, "../image.png", 0);

> Some form of handle copy might be useful here too, if you're having to do a
> lot of relative transformations from a single base URL.

Yes, something like this:

   CURLURL *handle = curl_url_dup(inhandle);

> In addition, our own URL classes support returning the path as an array of
> strings corresponding to to each individual path segment. We've certainly
> found use for this in the past, and others may also find this useful.

Mm, maybe. Is there anything else to that than splitting the path on every
forward slash?

Received on 2018-08-03