+#define http_request_object_check_request_content_type(t) _http_request_object_check_request_content_type((t) TSRMLS_CC)
+static inline void _http_request_object_check_request_content_type(zval *this_ptr TSRMLS_DC)
+{
+ 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);
+ }
+ }
+}
+