/* }}} */
/* {{{ http_request *http_request_init(http_request *) */
-PHP_HTTP_API http_request *_http_request_init_ex(http_request *request, CURL *ch, http_request_method meth, const char *url TSRMLS_DC)
+PHP_HTTP_API http_request *_http_request_init_ex(http_request *request, CURL *ch, http_request_method meth, const char *url ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC TSRMLS_DC)
{
http_request *r;
if (request) {
r = request;
} else {
- r = emalloc(sizeof(http_request));
+ r = emalloc_rel(sizeof(http_request));
}
memset(r, 0, sizeof(http_request));
phpstr_init(&r->_cache.cookies);
zend_hash_init(&r->_cache.options, 0, NULL, ZVAL_PTR_DTOR, 0);
- TSRMLS_SET_CTX(request->tsrm_ls);
+ TSRMLS_SET_CTX(r->tsrm_ls);
return r;
}
{
if (*request) {
TSRMLS_FETCH_FROM_CTX((*request)->tsrm_ls);
+ http_request_body_free(&(*request)->body);
http_request_dtor(*request);
efree(*request);
*request = NULL;
request->conv.last_type = 0;
phpstr_dtor(&request->conv.request);
phpstr_dtor(&request->conv.response);
- http_request_body_free(&request->body);
+ http_request_body_dtor(request->body);
}
/* }}} */
HTTP_CURL_OPT(READFUNCTION, http_curl_read_callback);
HTTP_CURL_OPT(IOCTLFUNCTION, http_curl_ioctl_callback);
HTTP_CURL_OPT(WRITEFUNCTION, http_curl_dummy_callback);
- HTTP_CURL_OPT(PROGRESSFUNCTION, http_curl_progress_callback);
+ HTTP_CURL_OPT(PROGRESSFUNCTION, NULL);
HTTP_CURL_OPT(URL, NULL);
HTTP_CURL_OPT(NOPROGRESS, 1);
HTTP_CURL_OPT(PROXY, NULL);
HTTP_CURL_OPT(PORT, 0);
HTTP_CURL_OPT(USERPWD, NULL);
HTTP_CURL_OPT(HTTPAUTH, 0);
- HTTP_CURL_OPT(ENCODING, 0);
+ HTTP_CURL_OPT(ENCODING, NULL);
HTTP_CURL_OPT(FOLLOWLOCATION, 0);
HTTP_CURL_OPT(UNRESTRICTED_AUTH, 0);
HTTP_CURL_OPT(REFERER, NULL);
if ((zoption = http_request_option(request, options, "onprogress", 0))) {
HTTP_CURL_OPT(NOPROGRESS, 0);
HTTP_CURL_OPT(PROGRESSDATA, request);
+ HTTP_CURL_OPT(PROGRESSFUNCTION, http_curl_progress_callback);
http_request_set_progress_callback(request, zoption);
}
HTTP_CURL_OPT(HTTPAUTH, Z_LVAL_P(zoption));
}
- /* compress, empty string enables all supported if libcurl was build with zlib support */
- if ((zoption = http_request_option(request, options, "compress", IS_BOOL)) && Z_LVAL_P(zoption)) {
-#ifdef HTTP_HAVE_CURL_ZLIB
- HTTP_CURL_OPT(ENCODING, "gzip, deflate");
-#else
- HTTP_CURL_OPT(ENCODING, "gzip;q=1.0, deflate;q=0.5, *;q=0.1");
-#endif
- }
-
/* redirects, defaults to 0 */
if ((zoption = http_request_option(request, options, "redirect", IS_LONG))) {
HTTP_CURL_OPT(FOLLOWLOCATION, Z_LVAL_P(zoption) ? 1 : 0);
}
/* additional headers, array('name' => 'value') */
+ if (request->_cache.headers) {
+ curl_slist_free_all(request->_cache.headers);
+ request->_cache.headers = NULL;
+ }
if ((zoption = http_request_option(request, options, "headers", IS_ARRAY))) {
char *header_key;
ulong header_idx;
HashPosition pos;
- if (request->_cache.headers) {
- curl_slist_free_all(request->_cache.headers);
- request->_cache.headers = NULL;
- }
-
FOREACH_KEY(pos, zoption, header_key, header_idx) {
if (header_key) {
zval **header_val;
}
}
}
+ if ((zoption = http_request_option(request, options, "compress", IS_BOOL)) && Z_LVAL_P(zoption)) {
+ request->_cache.headers = curl_slist_append(request->_cache.headers, "Accept-Encoding: gzip;q=1.0,deflate;q=0.5,*;q=0.1");
+ }
+ HTTP_CURL_OPT(HTTPHEADER, request->_cache.headers);
/* cookies, array('name' => 'value') */
if ((zoption = http_request_option(request, options, "cookies", IS_ARRAY))) {
static inline zval *_http_request_option_ex(http_request *r, HashTable *options, char *key, size_t keylen, int type TSRMLS_DC)
{
zval **zoption;
+#ifdef ZEND_ENGINE_2
ulong h = zend_get_hash_value(key, keylen);
-
- if (!options || (SUCCESS != zend_hash_quick_find(options, key, keylen, h, (void **) &zoption))) {
+#endif
+
+ if (!options ||
+#ifdef ZEND_ENGINE_2
+ (SUCCESS != zend_hash_quick_find(options, key, keylen, h, (void **) &zoption))
+#else
+ (SUCCESS != zend_hash_find(options, key, keylen, (void **) &zoption))
+#endif
+ ) {
return NULL;
}
}
}
- ZVAL_ADDREF(*zoption);
- _zend_hash_quick_add_or_update(&r->_cache.options, key, keylen, h, zoption, sizeof(zval *), NULL,
- zend_hash_quick_exists(&r->_cache.options, key, keylen, h)?HASH_UPDATE:HASH_ADD ZEND_FILE_LINE_CC);
-
+ /* cache strings */
+ if (type == IS_STRING) {
+ ZVAL_ADDREF(*zoption);
+#ifdef ZEND_ENGINE_2
+ _zend_hash_quick_add_or_update(&r->_cache.options, key, keylen, h, zoption, sizeof(zval *), NULL,
+ zend_hash_quick_exists(&r->_cache.options, key, keylen, h)?HASH_UPDATE:HASH_ADD ZEND_FILE_LINE_CC);
+#else
+ zend_hash_add_or_update(&r->_cache.options, key, keylen, zoption, sizeof(zval *), NULL,
+ zend_hash_exists(&r->_cache.options, key, keylen)?HASH_UPDATE:HASH_ADD);
+#endif
+ }
+
return *zoption;
}
/* }}} */