+ if (stream_ctx->finished) {
+ return FAILURE;
+ }
+ if (!stream_ctx->started) {
+ if (SUCCESS != php_http_env_response_stream_start(stream_ctx)) {
+ return FAILURE;
+ }
+ }
+
+ return php_stream_flush(stream_ctx->stream);
+}
+static ZEND_RESULT_CODE php_http_env_response_stream_finish(php_http_env_response_t *r)
+{
+ php_http_env_response_stream_ctx_t *stream_ctx = r->ctx;
+
+ if (stream_ctx->finished) {
+ return FAILURE;
+ }
+ if (!stream_ctx->started) {
+ if (SUCCESS != php_http_env_response_stream_start(stream_ctx)) {
+ return FAILURE;
+ }
+ }
+
+ if (stream_ctx->chunked && 5 != php_stream_write_string(stream_ctx->stream, "0" PHP_HTTP_CRLF PHP_HTTP_CRLF)) {
+ return FAILURE;
+ }
+
+ stream_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); \
+ } \
+ } 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 = PHP_HTTP_OBJ(NULL, getThis());
+
+ php_http_expect(obj->message = php_http_message_init_env(obj->message, PHP_HTTP_RESPONSE), 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)