following redirects in libcurl
Date: Fri, 17 Jun 2016 11:41:25 -0400
I'm seeing the need to follow redirects in my application and so am looking at
the related libcurl options. This has generated some questions on libcurl
behavior. I'm interested in not only following the redirects (automagically
or manually) but being able to log/debug out where the redirects went.
Pass a pointer to a char pointer to receive the URL a redirect would take you
to if you would enable CURLOPT_FOLLOWLOCATION. This can come very handy if you
think using the built-in libcurl redirect logic isn't good enough for you but
you would still prefer to avoid implementing all the magic of figuring out the
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
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? )
If CURLOPT_FOLLOWLOCATION is in effect, does the pointer still get set if a
redirect occurred or set NULL if no redirect??
What is the persistence of the memory pointed to? (From other
curl_easy_getinfo options I see this is memory managed by libcurl.)
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?
Pass in a pointer to a char pointer and get the last used effective URL.
In cases when you've asked libcurl to follow redirects, it may very well not
be the same value you set with CURLOPT_URL.
The urlp pointer will be NULL or pointing to private memory you MUST NOT free
- it gets freed when you call curl_easy_cleanup on the corresponding CURL handle.
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 != CURLOPT_URL)
Once I understand things, I'll try to make some suggestions for the
List admin: https://cool.haxx.se/list/listinfo/curl-library
Received on 2016-06-17