cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Curl error - HTTP error before end of send, stop sending

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Thu, 2 May 2013 15:30:41 +0200 (CEST)

On Tue, 30 Apr 2013, Rahul R wrote:

Please don't top-post!

> In the case below, is it possible that curl_easy_perform() returns CURLE_OK,
> but at least does it return HTTP code other than 200 ? So that the caller
> can know there was an error while uploading data.

In libcurl's perspective, a HTTP transfer is about sending a request and
getting a response (and in some cases more than one). If that process works,
things are fine and CURLE_OK is returned.

In some cases you will send stuff to a server that it doesn't like for some
reason or it may otherwise send back hints to you, as HTTP response codes.
That may be a 404 file not found or whatever. Just getting a non-2xx HTTP
response code is not a cause for libcurl to return failure, as you may in fact
have wanted such a code for all libcurl knows.

Thus, if you want to know the HTTP code you need to check it explicitly after
libcurl returns OK.

In your original case you mentioned doing a PUT request during which the
operation is aborted when the server returns an error code. This is kind of an
optimization so that libcurl stops sending things that won't be handled
anyway. As the request is then not completed, we could argue that the transfer
wasn't successful and possibly that should lead to libcurl not returning
CURLE_OK for that situation.

It is a bit of a gray area and I'm open for what others have to say about it.

-- 
  / daniel.haxx.se
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html
Received on 2013-05-02