- unify script termination
[m6w6/ext-http] / http_api.c
index e9f3bf093afaa037b5955ba10633e080cc8317d8..5a0dd3728a8a4f655bbb609d89b0aca73b071935 100644 (file)
@@ -27,6 +27,7 @@
 #include "php_http_std_defs.h"
 #include "php_http_api.h"
 #include "php_http_headers_api.h"
+#include "php_http_send_api.h"
 
 #ifdef ZEND_ENGINE_2
 #      include "php_http_exception_object.h"
@@ -81,6 +82,25 @@ void _http_error_ex(long type, long code, const char *format, ...)
 }
 /* }}} */
 
+/* {{{ STATUS http_exit(int, char*) */
+STATUS _http_exit_ex(int status, char *header, zend_bool free_header TSRMLS_DC)
+{
+       if (SUCCESS != http_send_status_header(status, header)) {
+               http_error_ex(E_WARNING, HTTP_E_HEADER, "Failed to exit with status/header: %d - %s", status, header ? header : "");
+               if (free_header && header) {
+                       efree(header);
+               }
+               return FAILURE;
+       }
+       if (free_header && header) {
+               efree(header);
+       }
+       zend_bailout();
+       /* fake */
+       return SUCCESS;
+}
+/* }}} */
+
 /* {{{ zval *http_get_server_var_ex(char *, size_t) */
 PHP_HTTP_API zval *_http_get_server_var_ex(const char *key, size_t key_size, zend_bool check TSRMLS_DC)
 {