- zval *meth, *URL, *meth_p, *URL_p;
- char *request_uri;
- STATUS status = SUCCESS;
-
- if (!body) {
- return FAILURE;
- }
- HTTP_CHECK_CURL_INIT(obj->ch, curl_easy_init(), return FAILURE);
-
- URL = convert_to_type_ex(IS_STRING, GET_PROP(obj, url), &URL_p);
- // HTTP_URI_MAXLEN+1 long char *
- if (!(request_uri = http_absolute_uri_ex(Z_STRVAL_P(URL), Z_STRLEN_P(URL), NULL, 0, NULL, 0, 0))) {
- if (URL_p) {
- zval_ptr_dtor(&URL_p);
+ zval *ctype = GET_PROP(contentType);
+
+ if (Z_STRLEN_P(ctype)) {
+ zval **headers, *opts = GET_PROP(options);
+
+ if ( (Z_TYPE_P(opts) == IS_ARRAY) &&
+ (SUCCESS == zend_hash_find(Z_ARRVAL_P(opts), "headers", sizeof("headers"), (void **) &headers)) &&
+ (Z_TYPE_PP(headers) == IS_ARRAY)) {
+ zval **ct_header;
+
+ /* only override if not already set */
+ if ((SUCCESS != zend_hash_find(Z_ARRVAL_PP(headers), "Content-Type", sizeof("Content-Type"), (void **) &ct_header))) {
+ add_assoc_stringl(*headers, "Content-Type", Z_STRVAL_P(ctype), Z_STRLEN_P(ctype), 1);
+ } else
+ /* or not a string, zero length string or a string of spaces */
+ if ((Z_TYPE_PP(ct_header) != IS_STRING) || !Z_STRLEN_PP(ct_header)) {
+ add_assoc_stringl(*headers, "Content-Type", Z_STRVAL_P(ctype), Z_STRLEN_P(ctype), 1);
+ } else {
+ int i, only_space = 1;
+
+ /* check for spaces only */
+ for (i = 0; i < Z_STRLEN_PP(ct_header); ++i) {
+ if (!isspace(Z_STRVAL_PP(ct_header)[i])) {
+ only_space = 0;
+ break;
+ }
+ }
+ if (only_space) {
+ add_assoc_stringl(*headers, "Content-Type", Z_STRVAL_P(ctype), Z_STRLEN_P(ctype), 1);
+ }
+ }
+ } else {
+ zval *headers;
+
+ MAKE_STD_ZVAL(headers);
+ array_init(headers);
+ add_assoc_stringl(headers, "Content-Type", Z_STRVAL_P(ctype), Z_STRLEN_P(ctype), 1);
+ zend_call_method_with_1_params(&getThis(), Z_OBJCE_P(getThis()), NULL, "addheaders", NULL, headers);
+ zval_ptr_dtor(&headers);