+ if (stream_ctx->finished) {
+ return FAILURE;
+ }
+ if (!stream_ctx->started) {
+ if (SUCCESS != php_http_env_response_stream_start(stream_ctx TSRMLS_CC)) {
+ return FAILURE;
+ }
+ }
+
+ if (data_len != php_stream_write(stream_ctx->stream, data_str, data_len)) {
+ return FAILURE;
+ }
+
+ return SUCCESS;
+}
+static STATUS php_http_env_response_stream_flush(php_http_env_response_t *r)
+{
+ php_http_env_response_stream_ctx_t *stream_ctx = r->ctx;
+ TSRMLS_FETCH_FROM_CTX(r->ts);
+
+ if (stream_ctx->finished) {
+ return FAILURE;
+ }
+ if (!stream_ctx->started) {
+ if (SUCCESS != php_http_env_response_stream_start(stream_ctx TSRMLS_CC)) {
+ return FAILURE;
+ }
+ }
+
+ return php_stream_flush(stream_ctx->stream);
+}
+static STATUS php_http_env_response_stream_finish(php_http_env_response_t *r)
+{
+ php_http_env_response_stream_ctx_t *ctx = r->ctx;
+ TSRMLS_FETCH_FROM_CTX(r->ts);
+
+ if (ctx->finished) {
+ return FAILURE;
+ }
+ if (!ctx->started) {
+ if (SUCCESS != php_http_env_response_stream_start(ctx TSRMLS_CC)) {
+ return FAILURE;
+ }
+ }
+
+ php_stream_flush(ctx->stream);
+ if (ctx->chunked && ctx->chunked_filter) {
+ php_stream_filter_flush(ctx->chunked_filter, 1);
+ ctx->chunked_filter = php_stream_filter_remove(ctx->chunked_filter, 1 TSRMLS_CC);
+ }
+
+ ctx->finished = 1;
+
+ return SUCCESS;
+}
+
+static php_http_env_response_ops_t php_http_env_response_stream_ops = {
+ php_http_env_response_stream_init,
+ php_http_env_response_stream_dtor,
+ php_http_env_response_stream_get_status,
+ php_http_env_response_stream_set_status,
+ php_http_env_response_stream_set_protocol_version,
+ php_http_env_response_stream_set_header,
+ php_http_env_response_stream_add_header,
+ php_http_env_response_stream_del_header,
+ php_http_env_response_stream_write,
+ php_http_env_response_stream_flush,
+ php_http_env_response_stream_finish
+};
+
+php_http_env_response_ops_t *php_http_env_response_get_stream_ops(void)
+{
+ return &php_http_env_response_stream_ops;
+}
+
+#define PHP_HTTP_ENV_RESPONSE_OBJECT_INIT(obj) \
+ do { \
+ if (!obj->message) { \
+ obj->message = php_http_message_init_env(NULL, PHP_HTTP_RESPONSE TSRMLS_CC); \
+ } \
+ } while (0)
+
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse___construct, 0, 0, 0)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpEnvResponse, __construct)
+{
+ php_http_message_object_t *obj;
+
+ php_http_expect(SUCCESS == zend_parse_parameters_none(), invalid_arg, return);
+
+ obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ php_http_expect(obj->message = php_http_message_init_env(obj->message, PHP_HTTP_RESPONSE TSRMLS_CC), unexpected_val, return);
+}
+
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse___invoke, 0, 0, 1)
+ ZEND_ARG_INFO(0, ob_string)
+ ZEND_ARG_INFO(0, ob_flags)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpEnvResponse, __invoke)
+{
+ char *ob_str;
+ int ob_len;
+ long ob_flags = 0;
+
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|l", &ob_str, &ob_len, &ob_flags)) {
+ php_http_message_object_t *obj = zend_object_store_get_object(getThis() TSRMLS_CC);
+
+ PHP_HTTP_ENV_RESPONSE_OBJECT_INIT(obj);
+
+ 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
+ }
+}
+
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setEnvRequest, 0, 0, 1)
+ ZEND_ARG_OBJ_INFO(0, env_request, http\\Message, 1)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpEnvResponse, setEnvRequest)
+{
+ zval *env_req = NULL;
+
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|O", &env_req, php_http_message_class_entry), invalid_arg, return);
+
+ set_option(getThis(), ZEND_STRL("request"), IS_OBJECT, env_req, 0 TSRMLS_CC);
+ RETVAL_ZVAL(getThis(), 1, 0);
+}
+
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setContentType, 0, 0, 1)
+ ZEND_ARG_INFO(0, content_type)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpEnvResponse, setContentType)
+{
+ char *ct_str = NULL;
+ int ct_len = 0;
+
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s!", &ct_str, &ct_len), invalid_arg, return);
+
+ set_option(getThis(), ZEND_STRL("contentType"), IS_STRING, ct_str, ct_len TSRMLS_CC);
+ RETVAL_ZVAL(getThis(), 1, 0);
+}
+
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setContentDisposition, 0, 0, 1)
+ ZEND_ARG_ARRAY_INFO(0, disposition_params, 1)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpEnvResponse, setContentDisposition)
+{
+ zval *zdisposition;
+
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &zdisposition), invalid_arg, return);
+
+ zend_update_property(Z_OBJCE_P(getThis()), getThis(), ZEND_STRL("contentDisposition"), zdisposition TSRMLS_CC);
+ RETVAL_ZVAL(getThis(), 1, 0);
+}
+
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setContentEncoding, 0, 0, 1)
+ ZEND_ARG_INFO(0, content_encoding)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpEnvResponse, setContentEncoding)
+{
+ long ce;
+
+ php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &ce), invalid_arg, return);
+
+ set_option(getThis(), ZEND_STRL("contentEncoding"), IS_LONG, &ce, 0 TSRMLS_CC);
+ RETVAL_ZVAL(getThis(), 1, 0);
+}
+
+ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setCacheControl, 0, 0, 1)
+ ZEND_ARG_INFO(0, cache_control)
+ZEND_END_ARG_INFO();
+static PHP_METHOD(HttpEnvResponse, setCacheControl)