/* }}} */
/* {{{ CURL *http_curl_init(http_request *) */
-PHP_HTTP_API CURL * _http_curl_init_ex(CURL *ch, void *context, char *error_buffer)
+PHP_HTTP_API CURL * _http_curl_init_ex(CURL *ch, http_request *request)
{
if (ch || (ch = curl_easy_init())) {
#if defined(ZTS)
HTTP_CURL_OPT_EX(ch, READFUNCTION, http_curl_read_callback);
HTTP_CURL_OPT_EX(ch, IOCTLFUNCTION, http_curl_ioctl_callback);
HTTP_CURL_OPT_EX(ch, WRITEFUNCTION, http_curl_dummy_callback);
- HTTP_CURL_OPT_EX(ch, DEBUGDATA, context);
- HTTP_CURL_OPT_EX(ch, PRIVATE, context);
- HTTP_CURL_OPT_EX(ch, ERRORBUFFER, error_buffer);
+
+ /* set context */
+ if (request) {
+ HTTP_CURL_OPT_EX(ch, PRIVATE, request);
+ HTTP_CURL_OPT_EX(ch, DEBUGDATA, request);
+ HTTP_CURL_OPT_EX(ch, ERRORBUFFER, request->_error);
+
+ /* attach curl handle */
+ request->ch = ch;
+ /* set defaults (also in http_request_reset()) */
+ http_request_defaults(request);
+ }
}
return ch;
TSRMLS_FETCH_FROM_CTX(request->tsrm_ls);
HTTP_CHECK_CURL_INIT(request->ch, http_curl_init(request), return FAILURE);
- http_request_defaults(request);
/* set options */
HTTP_CURL_OPT(URL, request->url);
/* useragent, default "PECL::HTTP/version (PHP/version)" */
if ((zoption = http_request_option(request, options, "useragent", IS_STRING))) {
+ /* allow to send no user agent, not even default one */
if (Z_STRLEN_P(zoption)) {
HTTP_CURL_OPT(USERAGENT, Z_STRVAL_P(zoption));
} else {
old_zo = zend_objects_get_address(this_ptr TSRMLS_CC);
new_ov = http_request_object_new_ex(old_zo->ce, NULL, &new_obj);
if (old_obj->request->ch) {
- new_obj->request->ch = http_curl_init_ex(curl_easy_duphandle(old_obj->request->ch), new_obj->request, new_obj->request->_error);
+ http_curl_init_ex(curl_easy_duphandle(old_obj->request->ch), new_obj->request);
}
zend_objects_clone_members(&new_obj->zo, new_ov, old_zo, Z_OBJ_HANDLE_P(this_ptr) TSRMLS_CC);
} http_request;
-#define http_curl_init(r) http_curl_init_ex(NULL, (r), (r)->_error)
-#define http_curl_init_ex(c, r, e) _http_curl_init_ex((c), (r), (e))
-PHP_HTTP_API CURL *_http_curl_init_ex(CURL *ch, void *context, char *error_buffer);
+#define http_curl_init(r) http_curl_init_ex(NULL, (r))
+#define http_curl_init_ex(c, r) _http_curl_init_ex((c), (r))
+PHP_HTTP_API CURL *_http_curl_init_ex(CURL *ch, http_request *request);
#define http_curl_free(c) _http_curl_free(c)
PHP_HTTP_API void _http_curl_free(CURL **ch);