Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CURLOPT_FAILONERROR forces connection to be closed #325

Closed
bemoody opened this issue Jun 23, 2015 · 2 comments
Closed

CURLOPT_FAILONERROR forces connection to be closed #325

bemoody opened this issue Jun 23, 2015 · 2 comments
Assignees
Labels

Comments

@bemoody
Copy link

bemoody commented Jun 23, 2015

If CURLOPT_FAILONERROR is used, and the server returns an error,
the connection will be closed immediately, regardless of the HTTP
version and keep-alive headers.

I guess that the reason this is done is so that libcurl doesn't
have to wait to receive the body of the error page. However,
error pages tend to be small, and it seems likely to me that in
many cases (if the application is making a large number of
requests, and especially when using HTTPS), it's more efficient
just to download the error page and discard it, rather than
having to open a new connection to the server. Moreover, in the
case of HEAD requests, there is no reason to close the connection
at all.

Of course, it is possible to work around this at the application
level - instead of setting CURLOPT_FAILONERROR, check the
CURLINFO_RESPONSE_CODE, and if it's >= 400, ignore the body of
the response. However, that has its own problems: aside from
being annoying to implement, it relies on the assumption that all
future protocols supported by libcurl will use HTTP/FTP-like
response codes.

@bagder
Copy link
Member

bagder commented Jun 24, 2015

This behavior should be documented to not be a surprise to users. Note how the documentation already limits this functionality to HTTP.

It is closed for HEAD as well as it allows for libcurl to return without even reading the full set of headers.

@bagder bagder self-assigned this Jun 24, 2015
@bagder bagder added the HTTP label Jun 24, 2015
bagder added a commit that referenced this issue Jun 24, 2015
@bagder
Copy link
Member

bagder commented Jun 24, 2015

This behavior is now documented as of commit 37402b5

@bagder bagder closed this as completed Jun 24, 2015
jgsogo pushed a commit to jgsogo/curl that referenced this issue Oct 19, 2015
@lock lock bot locked as resolved and limited conversation to collaborators May 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

2 participants