curl-library
Re: Configuration question
Date: Sat, 19 May 2001 14:28:19 +0200 (MET DST)
On Fri, 18 May 2001, Nilsson Johan wrote:
> First, libcurl is great (and using Mozilla cookies seems to work very well)!
Good! I've changed the documentation at some places to explicitly mention
that we support both Netscape and Mozilla cookie files.
> I'm a little bit confused regarding the FAILONERROR option (can't figure
> it out from the documentation). I want libcurl to fail on any error above
> 300 as long as there is no Location set in the header containing the HTTP
> code. So my question is will FAIL_ON_ERROR set to 1 only affect the last
> response after a redirect or will it fail immediately? Many servers
> return a response with code "302 Moved Temporary" and then a Location
> where to find the real file. I want libcurl to follow that location but
> if it gets for example "404 Not found" from that location it should fail
> with an error code.
>
> I want to do like this:
> curl_easy_setopt(mCurlHandle, CURLOPT_FAILONERROR, 1);
> curl_easy_setopt(mCurlHandle, CURLOPT_FOLLOWLOCATION, 1);
> curl_easy_setopt(mCurlHandle, CURLOPT_MAXREDIRS, 5);
>
> Will it work? It's hard for me to test it here and even if it would work
> I want to hear from someone else that it is a defined behaviour.
It will work!
Let me show you the relevant piece of code in lib/transfer.c (line 465 and
forwards in the latest CVS sources), and explain exactly what libcurl does:
/* This is the first header, it MUST be the error code line
or else we consiser this to be the body right away! */
if (2 == sscanf (p, " HTTP/1.%d %3d", &httpversion,
&httpcode)) {
/* 404 -> URL not found! */
if (
( ((data->bits.http_follow_location) &&
(httpcode >= 400))
||
(!data->bits.http_follow_location &&
(httpcode >= 300)))
&& (data->bits.http_fail_on_error)) {
The data->bits.http_follow_location is TRUE if we told libcurl to follow
locations and data->bits.http_fail_on_error is TRUE if we told it to fail on
errors.
/* If we have been told to fail hard on HTTP-errors,
here is the check for that: */
/* serious error, go home! */
failf (data, "The requested file was not found");
return CURLE_HTTP_NOT_FOUND;
}
I hope this answers your question.
-- Daniel Stenberg -- curl dude -- http://curl.haxx.se/ _______________________________________________ Curl-library mailing list Curl-library_at_lists.sourceforge.net http://lists.sourceforge.net/lists/listinfo/curl-libraryReceived on 2001-05-19