cURL / Mailing Lists / curl-library / Single Mail


Re: following redirects in libcurl

From: Daniel Stenberg <>
Date: Fri, 17 Jun 2016 18:19:53 +0200 (CEST)

On Fri, 17 Jun 2016, Richard Gray wrote:


> I take it this is only valid if the operation got a redirect (HTTP 3xx)?


> What if the operation was not redirected - do I need to check
> Or does it cleanly return NULL in the non-redirect case? (Can I use this
> option to simply check for a redirect by testing for NULL or non-NULL? )

Yeps, it will return a NULL if there wasn't a redirect (and a Location:
header). A proper thorough check would use the CURLINFO_RESPONSE_CODE as well.

> If CURLOPT_FOLLOWLOCATION is in effect, does the pointer still get set if a
> redirect occurred or set NULL if no redirect??

If libcurl is told to follow redirects it will go on itself, so not it doesn't
return any redirect URL then.

> What is the persistence of the memory pointed to? (From other
> curl_easy_getinfo options I see this is memory managed by libcurl.)

The memory is held by the easy handle and it may be freed/modified at the next
invoke of a perform call using that easy handle.

> Is it safe to say that the returned pointer will remain valid until the next
> transfer operation or cleanup on the handle? No guarantee beyond that?

Yes, like that. So if there's any risk of you wanting the URL beyond that,
make a copy!

> Can the effective URL get changed from the given URL when there is no
> redirect?


> Or does libcurl possibly 'cleanup' the given URL by doing things like
> unescaping, path squashing or other transformation? (CURLINFO_EFFECTIVE_URL

It will not unescape it, but it may have cleaned it up. Like if you'd specify
the URL without a scheme:// part, the CURLINFO_EFFECTIVE_URL will still return
a URL _with_ such a part. It should however still be "effectively" the same

List admin:
Received on 2016-06-17