Skip to content

ext/curl interface.c: modify curl_setopt_handler to allow resetting CURLOPT_HEADERFUNCTION callback #279

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

Closed
wants to merge 6 commits into from
18 changes: 18 additions & 0 deletions ext/curl/interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -2542,6 +2542,24 @@ static int _php_curl_setopt(php_curl *ch, long option, zval **zvalue, zval *retu
break;

case CURLOPT_HEADERFUNCTION:
/* check if we're setting to NULL = we're restoring php default handler */
if(Z_TYPE_PP(zvalue) == IS_NULL) {
if(ch->handlers->write_header->method == PHP_CURL_USER) {
if(ch->handlers->write_header->func_name) {
zval_ptr_dtor(&ch->handlers->write_header->func_name);
ch->handlers->write_header->fci_cache = empty_fcall_info_cache;
}
ch->handlers->write_header->func_name = NULL;
ch->handlers->write_header->method = PHP_CURL_IGNORE;
break;
} else if(ch->handlers->write_header->method == PHP_CURL_IGNORE) {
/* prevent the assign-code later on if user passed NULL and the handler was IGNORE already */
break;
} else {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Tried to set CURLOPT_HEADERFUNCTION to NULL after it was something other than a callable");
break;
}
}
if (ch->handlers->write_header->func_name) {
zval_ptr_dtor(&ch->handlers->write_header->func_name);
ch->handlers->write_header->fci_cache = empty_fcall_info_cache;
Expand Down