X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=http_request_api.c;h=444e43fe5a6929992d3c04317a55d9ac9485cf1c;hb=389e280e0bba312ff5ca9981801cc842dad26ec2;hp=082c5fc768bece975c572a8a28031a97954a244b;hpb=e9dbd50bf2da38361ebbdca1c3a9fe24e5e4dc03;p=m6w6%2Fext-http diff --git a/http_request_api.c b/http_request_api.c index 082c5fc..444e43f 100644 --- a/http_request_api.c +++ b/http_request_api.c @@ -12,10 +12,7 @@ /* $Id$ */ -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - +#define HTTP_WANT_SAPI #define HTTP_WANT_CURL #include "php_http.h" @@ -211,7 +208,7 @@ static curlioerr http_curl_ioctl_callback(CURL *, curliocmd, void *); /* }}} */ /* {{{ 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) @@ -226,9 +223,18 @@ PHP_HTTP_API CURL * _http_curl_init_ex(CURL *ch, void *context, char *error_buff 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; @@ -382,6 +388,11 @@ PHP_HTTP_API void _http_request_defaults(http_request *request) HTTP_CURL_OPT(READDATA, NULL); HTTP_CURL_OPT(INFILESIZE, 0); HTTP_CURL_OPT(HTTP_VERSION, CURL_HTTP_VERSION_NONE); + HTTP_CURL_OPT(CUSTOMREQUEST, NULL); + HTTP_CURL_OPT(NOBODY, 0); + HTTP_CURL_OPT(POST, 0); + HTTP_CURL_OPT(UPLOAD, 0); + HTTP_CURL_OPT(HTTPGET, 1); } } /* }}} */ @@ -414,7 +425,6 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti 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); @@ -477,8 +487,13 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti } /* useragent, default "PECL::HTTP/version (PHP/version)" */ - if ((zoption = http_request_option(request, options, "useragent", IS_STRING)) && Z_STRLEN_P(zoption)) { - HTTP_CURL_OPT(USERAGENT, Z_STRVAL_P(zoption)); + 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 { + HTTP_CURL_OPT(USERAGENT, NULL); + } } /* additional headers, array('name' => 'value') */ @@ -572,7 +587,7 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti if (Z_LVAL_P(zoption) > 0) { HTTP_CURL_OPT(TIMEVALUE, Z_LVAL_P(zoption)); } else { - HTTP_CURL_OPT(TIMEVALUE, time(NULL) + Z_LVAL_P(zoption)); + HTTP_CURL_OPT(TIMEVALUE, HTTP_GET_REQUEST_TIME() + Z_LVAL_P(zoption)); } HTTP_CURL_OPT(TIMECONDITION, range_req ? CURL_TIMECOND_IFUNMODSINCE : CURL_TIMECOND_IFMODSINCE); } else { @@ -629,38 +644,22 @@ PHP_HTTP_API STATUS _http_request_prepare(http_request *request, HashTable *opti switch (request->meth) { case HTTP_GET: - HTTP_CURL_OPT(NOBODY, 0); - HTTP_CURL_OPT(POST, 0); - HTTP_CURL_OPT(UPLOAD, 0); HTTP_CURL_OPT(HTTPGET, 1); break; case HTTP_HEAD: - HTTP_CURL_OPT(POST, 0); - HTTP_CURL_OPT(UPLOAD, 0); - HTTP_CURL_OPT(HTTPGET, 0); HTTP_CURL_OPT(NOBODY, 1); break; case HTTP_POST: - HTTP_CURL_OPT(UPLOAD, 0); - HTTP_CURL_OPT(HTTPGET, 0); - HTTP_CURL_OPT(NOBODY, 0); HTTP_CURL_OPT(POST, 1); break; case HTTP_PUT: - HTTP_CURL_OPT(HTTPGET, 0); - HTTP_CURL_OPT(NOBODY, 0); - HTTP_CURL_OPT(POST, 0); HTTP_CURL_OPT(UPLOAD, 1); break; default: - HTTP_CURL_OPT(HTTPGET, 0); - HTTP_CURL_OPT(NOBODY, 0); - HTTP_CURL_OPT(POST, 0); - HTTP_CURL_OPT(UPLOAD, 0); if (http_request_method_exists(0, request->meth, NULL)) { HTTP_CURL_OPT(CUSTOMREQUEST, http_request_method_name(request->meth)); } else {