cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: http status code early?

From: <RBramante_at_on.com>
Date: Fri, 4 Apr 2003 11:54:50 -0500

I played around a little bit with this today. As you say, it does look to
me like you can get this via curl_easy_getinfo() from within the context of
a write callback (i.e. while curl_easy_perform() is executing) for both 200
and 404 conditions. I didn't test anything else.

Thinking back, the reason I did what I did was because I needed to know
what the return status was before I ever got my first write callback.

Maybe it is too specialized of a callback, but I suppose curl could add
another that would callback as soon as the status was parsed. This might
benefit the original poster who was not using write callbacks in the first
place.

typedef size_t (*curl_status_callback)(int code, void *userdata);

User could could return 0 to continue or !0 to tell curl it didn't like the
status and just abort right there.

I suppose it gets down to the level granularity provided. The info is
there and you can get at it, the question is whether it should be more of a
"first-class" api.

                                                                                                                                                   
                      Daniel Stenberg
                      <daniel_at_haxx.se> To: libcurl Mailing list <curl-library_at_lists.sourceforge.net>
                      Sent by: cc:
                      curl-library-admin_at_lists.sour Subject: Re: http status code early?
                      ceforge.net
                                                                                                                                                   
                                                                                                                                                   
                      04/04/2003 01:47 AM
                      Please respond to
                      curl-library
                                                                                                                                                   
                                                                                                                                                   

On Thu, 3 Apr 2003 RBramante_at_on.com wrote:

> I also needed to know the HTTP response code prior to receiving the
content
> (and hence before curl_easy_peform() returned).
>
> The way I did it was to setup for the CURLOPT_HEADERFUNCTION callback,
and
> in there parse the response code out of the header manually. Then I
> stuffed that value away in a place accessible from the other callbacks so
> they knew how to behave based on the response.
>
> Kind of hacky, but it was the only way I could see to do it. I suppose
> this might be a feature that is desirable to others, maybe a more
standard
> solution could be identified.

Reading the code, it sure looks as if curl_easy_getinfo(curl,
CURLINFO_HTTP_CODE, ...) will return the HTTP code whenever you call it,
even
if curl_easy_peform() hasn't returned yet.

If we want to support this kind of behavior (I mean documented as well) we
better make sure the function return an error code or something well
defined
if the HTTP code hasn't yet been recevied. Currently I believe it will
return
the previous value until the new one is set, which is bound to confuse
applications...

I'm open to syggestions.

--
 Daniel Stenberg -- curl, cURL, Curl, CURL. Groks URLs.
-------------------------------------------------------
This SF.net email is sponsored by: ValueWeb:
Dedicated Hosting for just $79/mo with 500 GB of bandwidth!
No other company gives more support or power for your dedicated server
http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/
-------------------------------------------------------
This SF.net email is sponsored by: ValueWeb: 
Dedicated Hosting for just $79/mo with 500 GB of bandwidth! 
No other company gives more support or power for your dedicated server
http://click.atdmt.com/AFF/go/sdnxxaff00300020aff/direct/01/
Received on 2003-04-04