struct {
HashTable cache;
+ struct curl_slist *proxyheaders;
struct curl_slist *headers;
struct curl_slist *resolve;
php_http_buffer_t cookies;
return 0;
}
-static curlioerr php_http_curle_ioctl_callback(CURL *ch, curliocmd cmd, void *ctx)
+static int php_http_curle_seek_callback(void *userdata, curl_off_t offset, int origin)
{
- php_http_message_body_t *body = ctx;
+ php_http_message_body_t *body = userdata;
+ TSRMLS_FETCH_FROM_CTX(body->ts);
- if (cmd != CURLIOCMD_RESTARTREAD) {
- return CURLIOE_UNKNOWNCMD;
+ if (!body) {
+ return 1;
}
-
- if (body) {
- TSRMLS_FETCH_FROM_CTX(body->ts);
-
- if (SUCCESS == php_stream_rewind(php_http_message_body_stream(body))) {
- return CURLIOE_OK;
- }
+ if (0 == php_stream_seek(php_http_message_body_stream(body), offset, origin)) {
+ return 0;
}
-
- return CURLIOE_FAILRESTART;
+ return 2;
}
static int php_http_curle_raw_callback(CURL *ch, curl_infotype type, char *data, size_t length, void *ctx)
static STATUS php_http_curle_option_set_compress(php_http_option_t *opt, zval *val, void *userdata)
{
php_http_client_curl_handler_t *curl = userdata;
+ CURL *ch = curl->handle;
- if (Z_BVAL_P(val)) {
- curl->options.headers = curl_slist_append(curl->options.headers, "Accept-Encoding: gzip;q=1.0,deflate;q=0.5");
+ if (CURLE_OK != curl_easy_setopt(ch, CURLOPT_ACCEPT_ENCODING, Z_BVAL_P(val) ? "" : NULL)) {
+ return FAILURE;
}
return SUCCESS;
}
return SUCCESS;
}
+#if PHP_HTTP_CURL_VERSION(7,37,0)
+static STATUS php_http_curle_option_set_proxyheader(php_http_option_t *opt, zval *val, void *userdata)
+{
+ php_http_client_curl_handler_t *curl = userdata;
+ TSRMLS_FETCH_FROM_CTX(curl->client->ts);
+
+ if (val && Z_TYPE_P(val) != IS_NULL) {
+ php_http_array_hashkey_t header_key = php_http_array_hashkey_init(0);
+ zval **header_val, *header_cpy;
+ HashPosition pos;
+ php_http_buffer_t header;
+
+ php_http_buffer_init(&header);
+ FOREACH_KEYVAL(pos, val, header_key, header_val) {
+ if (header_key.type == HASH_KEY_IS_STRING) {
+ header_cpy = php_http_ztyp(IS_STRING, *header_val);
+ php_http_buffer_appendf(&header, "%s: %s", header_key.str, Z_STRVAL_P(header_cpy));
+ php_http_buffer_fix(&header);
+ curl->options.proxyheaders = curl_slist_append(curl->options.proxyheaders, header.data);
+ php_http_buffer_reset(&header);
+
+ zval_ptr_dtor(&header_cpy);
+ }
+ }
+ php_http_buffer_dtor(&header);
+ }
+ if (CURLE_OK != curl_easy_setopt(curl->handle, CURLOPT_PROXYHEADER, curl->options.proxyheaders)) {
+ return FAILURE;
+ }
+ if (CURLE_OK != curl_easy_setopt(curl->handle, CURLOPT_HEADEROPT, CURLHEADER_SEPARATE)) {
+ curl_easy_setopt(curl->handle, CURLOPT_PROXYHEADER, NULL);
+ return FAILURE;
+ }
+ return SUCCESS;
+}
+#endif
+
#if PHP_HTTP_CURL_VERSION(7,21,3)
static STATUS php_http_curle_option_set_resolve(php_http_option_t *opt, zval *val, void *userdata)
{
}
#endif
+#if PHP_HTTP_CURL_VERSION(7,21,4)
+static STATUS php_http_curle_option_set_ssl_tlsauthtype(php_http_option_t *opt, zval *val, void *userdata)
+{
+ php_http_client_curl_handler_t *curl = userdata;
+ CURL *ch = curl->handle;
+
+ if (val && Z_LVAL_P(val)) {
+ switch (Z_LVAL_P(val)) {
+ case CURL_TLSAUTH_SRP:
+ if (CURLE_OK == curl_easy_setopt(ch, CURLOPT_TLSAUTH_TYPE, PHP_HTTP_CURL_TLSAUTH_SRP)) {
+ return SUCCESS;
+ }
+ /* no break */
+ default:
+ return FAILURE;
+ }
+ }
+ if (CURLE_OK != curl_easy_setopt(ch, CURLOPT_TLSAUTH_TYPE, PHP_HTTP_CURL_TLSAUTH_DEF)) {
+ return FAILURE;
+ }
+ return SUCCESS;
+}
+#endif
+
static void php_http_curle_options_init(php_http_options_t *registry TSRMLS_DC)
{
php_http_option_t *opt;
php_http_option_register(registry, ZEND_STRL("noproxy"), CURLOPT_NOPROXY, IS_STRING);
#endif
+#if PHP_HTTP_CURL_VERSION(7,37,0)
+ if ((opt = php_http_option_register(registry, ZEND_STRL("proxyheader"), CURLOPT_PROXYHEADER, IS_ARRAY))) {
+ opt->setter = php_http_curle_option_set_proxyheader;
+ }
+#endif
+
/* dns */
if ((opt = php_http_option_register(registry, ZEND_STRL("dns_cache_timeout"), CURLOPT_DNS_CACHE_TIMEOUT, IS_LONG))) {
Z_LVAL(opt->defval) = 60;
ZVAL_BOOL(&opt->defval, 1);
opt->setter = php_http_curle_option_set_ssl_verifyhost;
}
+#if PHP_HTTP_CURL_VERSION(7,41,0)
+ php_http_option_register(registry, ZEND_STRL("verifystatus"), CURLOPT_SSL_VERIFYSTATUS, IS_BOOL);
+#endif
php_http_option_register(registry, ZEND_STRL("cipher_list"), CURLOPT_SSL_CIPHER_LIST, IS_STRING);
if ((opt = php_http_option_register(registry, ZEND_STRL("cainfo"), CURLOPT_CAINFO, IS_STRING))) {
opt->flags |= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN;
opt->flags |= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN;
opt->flags |= PHP_HTTP_CURLE_OPTION_CHECK_BASEDIR;
}
+#endif
+#if PHP_HTTP_CURL_VERSION(7,21,4)
+ if ((opt = php_http_option_register(registry, ZEND_STRL("tlsauthtype"), CURLOPT_TLSAUTH_TYPE, IS_LONG))) {
+ opt->setter = php_http_curle_option_set_ssl_tlsauthtype;
+ }
+ if ((opt = php_http_option_register(registry, ZEND_STRL("tlsauthuser"), CURLOPT_TLSAUTH_USERNAME, IS_STRING))) {
+ opt->flags |= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN;
+ }
+ if ((opt = php_http_option_register(registry, ZEND_STRL("tlsauthpass"), CURLOPT_TLSAUTH_PASSWORD, IS_STRING))) {
+ opt->flags |= PHP_HTTP_CURLE_OPTION_CHECK_STRLEN;
+ }
#endif
}
}
curl_slist_free_all(curl->options.headers);
curl->options.headers = NULL;
}
+ if (curl->options.proxyheaders) {
+ curl_slist_free_all(curl->options.proxyheaders);
+ curl->options.proxyheaders = NULL;
+ }
php_http_buffer_reset(&curl->options.cookies);
php_http_buffer_reset(&curl->options.ranges);
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, php_http_curle_body_callback);
curl_easy_setopt(handle, CURLOPT_DEBUGFUNCTION, php_http_curle_raw_callback);
curl_easy_setopt(handle, CURLOPT_READFUNCTION, php_http_curle_read_callback);
- curl_easy_setopt(handle, CURLOPT_IOCTLFUNCTION, php_http_curle_ioctl_callback);
+ curl_easy_setopt(handle, CURLOPT_SEEKFUNCTION, php_http_curle_seek_callback);
#if PHP_HTTP_CURL_VERSION(7,32,0)
curl_easy_setopt(handle, CURLOPT_XFERINFOFUNCTION, php_http_curle_xferinfo_callback);
curl_easy_setopt(handle, CURLOPT_XFERINFODATA, handler);
}
}
+ /* apply options */
+ php_http_options_apply(&php_http_curle_options, enqueue->options, curl);
+
/* request headers */
php_http_message_update_headers(msg);
if (zend_hash_num_elements(&msg->hdrs)) {
* does not allow a request body.
*/
php_stream_rewind(php_http_message_body_stream(msg->body));
- curl_easy_setopt(curl->handle, CURLOPT_IOCTLDATA, msg->body);
+ curl_easy_setopt(curl->handle, CURLOPT_SEEKDATA, msg->body);
curl_easy_setopt(curl->handle, CURLOPT_READDATA, msg->body);
curl_easy_setopt(curl->handle, CURLOPT_INFILESIZE, body_size);
curl_easy_setopt(curl->handle, CURLOPT_POSTFIELDSIZE, body_size);
} else {
- curl_easy_setopt(curl->handle, CURLOPT_IOCTLDATA, NULL);
+ curl_easy_setopt(curl->handle, CURLOPT_SEEKDATA, NULL);
curl_easy_setopt(curl->handle, CURLOPT_READDATA, NULL);
curl_easy_setopt(curl->handle, CURLOPT_INFILESIZE, 0L);
curl_easy_setopt(curl->handle, CURLOPT_POSTFIELDSIZE, 0L);
}
- php_http_options_apply(&php_http_curle_options, enqueue->options, curl);
-
return SUCCESS;
}
REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_SSLv2", CURL_SSLVERSION_SSLv2, CONST_CS|CONST_PERSISTENT);
REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_SSLv3", CURL_SSLVERSION_SSLv3, CONST_CS|CONST_PERSISTENT);
REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "SSL_VERSION_ANY", CURL_SSLVERSION_DEFAULT, CONST_CS|CONST_PERSISTENT);
+#if PHP_HTTP_CURL_VERSION(7,21,4)
+ REGISTER_NS_LONG_CONSTANT("http\\Client\\Curl", "TLSAUTH_SRP", CURL_TLSAUTH_SRP, CONST_CS|CONST_PERSISTENT);
+#endif
/*
* DNS IPvX resolving