On Fri, 17 Jun 2016, Richard Gray wrote:
CURLINFO_REDIRECT_URL
I take it this is only valid if the operation got a redirect (HTTP 3xx)?
Yes.
What if the operation was not redirected - do I need to check
CURLINFO_RESPONSE_CODE for 3xx first or CURLINFO_REDIRECT_COUNT?
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!
https://curl.haxx.se/libcurl/c/CURLINFO_EFFECTIVE_URL.html
Can the effective URL get changed from the given URL when there is no
redirect?
Yes.
Or does libcurl possibly 'cleanup' the given URL by doing things like
unescaping, path squashing or other transformation? (CURLINFO_EFFECTIVE_URL
!= CURLOPT_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
URL.
--
/ daniel.haxx.se
-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html