| modification, are permitted provided that the conditions mentioned |
| in the accompanying LICENSE file are met. |
+--------------------------------------------------------------------+
- | Copyright (c) 2004-2013, Michael Wallner <mike@php.net> |
+ | Copyright (c) 2004-2014, Michael Wallner <mike@php.net> |
+--------------------------------------------------------------------+
*/
{
php_http_env_response_t *r = context;
- r->ops->write(r, buf, len);
+ if (SUCCESS != r->ops->write(r, buf, len)) {
+ return (size_t) -1;
+ }
/* we really only need to flush when throttling is enabled,
because we push the data as fast as possible anyway if not */
#define php_http_env_response_send_done(r) php_http_env_response_send_data((r), NULL, 0)
static STATUS php_http_env_response_send_data(php_http_env_response_t *r, const char *buf, size_t len)
{
- size_t chunk = r->throttle.chunk ? r->throttle.chunk : PHP_HTTP_SENDBUF_SIZE;
+ size_t chunks_sent, chunk = r->throttle.chunk ? r->throttle.chunk : PHP_HTTP_SENDBUF_SIZE;
TSRMLS_FETCH_FROM_CTX(r->ts);
if (r->content.encoder) {
}
}
- if (enc_str) {
- php_http_buffer_chunked_output(&r->buffer, enc_str, enc_len, buf ? chunk : 0, output, r TSRMLS_CC);
- STR_FREE(enc_str);
+ if (!enc_str) {
+ return SUCCESS;
}
+ chunks_sent = php_http_buffer_chunked_output(&r->buffer, enc_str, enc_len, buf ? chunk : 0, output, r TSRMLS_CC);
+ STR_FREE(enc_str);
} else {
- php_http_buffer_chunked_output(&r->buffer, buf, len, buf ? chunk : 0, output, r TSRMLS_CC);
+ chunks_sent = php_http_buffer_chunked_output(&r->buffer, buf, len, buf ? chunk : 0, output, r TSRMLS_CC);
}
- return SUCCESS;
+ return chunks_sent != (size_t) -1 ? SUCCESS : FAILURE;
}
php_http_env_response_t *php_http_env_response_init(php_http_env_response_t *r, zval *options, php_http_env_response_ops_t *ops, void *init_arg TSRMLS_DC)
return ret;
}
+ if ((zoption = get_option(options, ZEND_STRL("headers") TSRMLS_CC))) {
+ if (Z_TYPE_P(zoption) == IS_ARRAY) {
+ php_http_header_to_callback(Z_ARRVAL_P(zoption), 0, (php_http_pass_format_callback_t) r->ops->set_header, r TSRMLS_CC);
+ }
+ zval_ptr_dtor(&zoption);
+ }
+
+ if (ret != SUCCESS) {
+ return ret;
+ }
+
if ((zoption = get_option(options, ZEND_STRL("responseCode") TSRMLS_CC))) {
zval *zoption_copy = php_http_ztyp(IS_LONG, zoption);
return ret;
}
- if ((zoption = get_option(options, ZEND_STRL("headers") TSRMLS_CC))) {
- if (Z_TYPE_P(zoption) == IS_ARRAY) {
- php_http_header_to_callback(Z_ARRVAL_P(zoption), 0, (php_http_pass_format_callback_t) r->ops->set_header, r TSRMLS_CC);
- }
- zval_ptr_dtor(&zoption);
- }
-
- if (ret != SUCCESS) {
- return ret;
- }
-
if ((zoption = get_option(options, ZEND_STRL("contentType") TSRMLS_CC))) {
zval *zoption_copy = php_http_ztyp(IS_STRING, zoption);
}
}
- php_stream_write(stream_ctx->stream, data_str, data_len);
+ if (data_len != php_stream_write(stream_ctx->stream, data_str, data_len)) {
+ return FAILURE;
+ }
return SUCCESS;
}
PHP_HTTP_ENV_RESPONSE_OBJECT_INIT(obj);
- if (obj->body || SUCCESS == php_http_new(NULL, php_http_message_body_class_entry, (php_http_new_t) php_http_message_body_object_new_ex, NULL, (void *) php_http_message_body_init(&obj->message->body, NULL TSRMLS_CC), (void *) &obj->body TSRMLS_CC)) {
- php_http_message_body_append(obj->message->body, ob_str, ob_len);
- RETURN_TRUE;
- }
- RETURN_FALSE;
+ php_http_message_object_init_body_object(obj);
+ php_http_message_body_append(obj->message->body, ob_str, ob_len);
+#if PHP_VERSION_ID >= 50400
+ RETURN_TRUE;
+#else
+ RETURN_EMPTY_STRING();
+#endif
}
}