curl-library
Re: a URL API ?
Date: Fri, 3 Aug 2018 10:27:25 +0100
On 01/08/18 23:17, Daniel Stenberg wrote:
> Hi,
>
> In the 2018 user survey, more than 40% of the 395 users who answered the
> question said they'd use a "URL handling" API in libcurl if one existed.
>
> I gave it some thoughts the other day and I've now jotted down my
> initial suggestion on how it could be made to work. An API that can
> parse a URL, extract the individual pieces, allow the user to set
> individual parts and finally to get the full URL out from there again.
>
> Here's my thoughts:
>
> https://github.com/curl/curl/wiki/URL-API
>
> Good or bad? What would your application need and would this work for
> that? If not, how should we change it to make it better?
I think the current proposal is fairly sound as a first step. I think
having something built-in to cURL makes a lot of sense, given the
project's focus on "doing stuff with URLs", and not having to add
another library dependency is a definite plus point.
However, I can think of a couple of worthwhile improvements:
Currently, we have our own URL parsing classes, and there's a couple of
important features that we find useful. 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("https://example.org/hello", url_handle, 0);
...
curl_url("/image.png", url_handle, 0);
I'd then expect a call to curl_url_get() on url_handle to return
something like "https://example.org/image.png"
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.
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.
That's just my two pennies worth anyway.
-Sam
-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2018-08-03