2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.0 of the PHP license, that |
6 | is bundled with this package in the file LICENSE, and is available |
7 | through the world-wide-web at http://www.php.net/license/3_0.txt. |
8 | If you did not receive a copy of the PHP license and are unable to |
9 | obtain it through the world-wide-web, please send a note to |
10 | license@php.net so we can mail you a copy immediately. |
11 +----------------------------------------------------------------------+
12 | Copyright (c) 2004-2005 Michael Wallner <mike@php.net> |
13 +----------------------------------------------------------------------+
28 #include "ext/standard/head.h"
31 #include "php_http_api.h"
32 #include "php_http_std_defs.h"
33 #include "php_http_response_object.h"
34 #include "php_http_exception_object.h"
35 #include "php_http_send_api.h"
36 #include "php_http_cache_api.h"
40 ZEND_EXTERN_MODULE_GLOBALS(http
);
42 #define USE_STATIC_PROP() USE_STATIC_PROP_EX(http_response_object_ce)
43 #define GET_STATIC_PROP(n) *GET_STATIC_PROP_EX(http_response_object_ce, n)
44 #define SET_STATIC_PROP(n, v) SET_STATIC_PROP_EX(http_response_object_ce, n, v)
45 #define SET_STATIC_PROP_STRING(n, s, d) SET_STATIC_PROP_STRING_EX(http_response_object_ce, n, s, d)
46 #define SET_STATIC_PROP_STRINGL(n, s, l, d) SET_STATIC_PROP_STRINGL_EX(http_response_object_ce, n, s, l, d)
48 #define HTTP_BEGIN_ARGS(method, req_args) HTTP_BEGIN_ARGS_EX(HttpResponse, method, 0, req_args)
49 #define HTTP_EMPTY_ARGS(method, ret_ref) HTTP_EMPTY_ARGS_EX(HttpResponse, method, ret_ref)
50 #define HTTP_RESPONSE_ME(method, visibility) PHP_ME(HttpResponse, method, HTTP_ARGS(HttpResponse, method), visibility|ZEND_ACC_STATIC)
51 #define HTTP_RESPONSE_ALIAS(method, func) HTTP_STATIC_ME_ALIAS(method, func, HTTP_ARGS(HttpResponse, method))
53 HTTP_EMPTY_ARGS(getETag
, 0);
54 HTTP_BEGIN_ARGS(setETag
, 1)
58 HTTP_EMPTY_ARGS(getCache
, 0);
59 HTTP_BEGIN_ARGS(setCache
, 1)
60 HTTP_ARG_VAL(cache
, 0)
63 HTTP_EMPTY_ARGS(getGzip
, 0);
64 HTTP_BEGIN_ARGS(setGzip
, 1)
68 HTTP_EMPTY_ARGS(getCacheControl
, 0);
69 HTTP_BEGIN_ARGS(setCacheControl
, 1)
70 HTTP_ARG_VAL(cache_control
, 0)
71 HTTP_ARG_VAL(max_age
, 0)
74 HTTP_EMPTY_ARGS(getContentType
, 0);
75 HTTP_BEGIN_ARGS(setContentType
, 1)
76 HTTP_ARG_VAL(content_type
, 0)
79 HTTP_EMPTY_ARGS(getContentDisposition
, 0);
80 HTTP_BEGIN_ARGS(setContentDisposition
, 1)
81 HTTP_ARG_VAL(filename
, 0)
82 HTTP_ARG_VAL(send_inline
, 0)
85 HTTP_EMPTY_ARGS(getThrottleDelay
, 0);
86 HTTP_BEGIN_ARGS(setThrottleDelay
, 1)
87 HTTP_ARG_VAL(seconds
, 0)
90 HTTP_EMPTY_ARGS(getBufferSize
, 0);
91 HTTP_BEGIN_ARGS(setBufferSize
, 1)
92 HTTP_ARG_VAL(bytes
, 0)
95 HTTP_EMPTY_ARGS(getData
, 0);
96 HTTP_BEGIN_ARGS(setData
, 1)
100 HTTP_EMPTY_ARGS(getStream
, 0);
101 HTTP_BEGIN_ARGS(setStream
, 1)
102 HTTP_ARG_VAL(stream
, 0)
105 HTTP_EMPTY_ARGS(getFile
, 0);
106 HTTP_BEGIN_ARGS(setFile
, 1)
107 HTTP_ARG_VAL(filepath
, 0)
110 HTTP_BEGIN_ARGS(send
, 0)
111 HTTP_ARG_VAL(clean_ob
, 0)
114 HTTP_EMPTY_ARGS(capture
, 0);
116 HTTP_BEGIN_ARGS(redirect
, 0)
118 HTTP_ARG_VAL(params
, 0)
119 HTTP_ARG_VAL(session
, 0)
120 HTTP_ARG_VAL(permanent
, 0)
123 HTTP_BEGIN_ARGS(sendStatus
, 1)
124 HTTP_ARG_VAL(status
, 0)
127 HTTP_BEGIN_ARGS(sendHeader
, 1)
128 HTTP_ARG_VAL(header
, 0)
129 HTTP_ARG_VAL(replace
, 0)
130 HTTP_ARG_VAL(status
, 0)
133 HTTP_EMPTY_ARGS(getRequestHeaders
, 0);
134 HTTP_EMPTY_ARGS(getRequestBody
, 0);
136 #define http_response_object_declare_default_properties() _http_response_object_declare_default_properties(TSRMLS_C)
137 static inline void _http_response_object_declare_default_properties(TSRMLS_D
);
139 zend_class_entry
*http_response_object_ce
;
140 zend_function_entry http_response_object_fe
[] = {
142 HTTP_RESPONSE_ME(setETag
, ZEND_ACC_PUBLIC
)
143 HTTP_RESPONSE_ME(getETag
, ZEND_ACC_PUBLIC
)
145 HTTP_RESPONSE_ME(setContentDisposition
, ZEND_ACC_PUBLIC
)
146 HTTP_RESPONSE_ME(getContentDisposition
, ZEND_ACC_PUBLIC
)
148 HTTP_RESPONSE_ME(setContentType
, ZEND_ACC_PUBLIC
)
149 HTTP_RESPONSE_ME(getContentType
, ZEND_ACC_PUBLIC
)
151 HTTP_RESPONSE_ME(setCache
, ZEND_ACC_PUBLIC
)
152 HTTP_RESPONSE_ME(getCache
, ZEND_ACC_PUBLIC
)
154 HTTP_RESPONSE_ME(setCacheControl
, ZEND_ACC_PUBLIC
)
155 HTTP_RESPONSE_ME(getCacheControl
, ZEND_ACC_PUBLIC
)
157 HTTP_RESPONSE_ME(setGzip
, ZEND_ACC_PUBLIC
)
158 HTTP_RESPONSE_ME(getGzip
, ZEND_ACC_PUBLIC
)
160 HTTP_RESPONSE_ME(setThrottleDelay
, ZEND_ACC_PUBLIC
)
161 HTTP_RESPONSE_ME(getThrottleDelay
, ZEND_ACC_PUBLIC
)
163 HTTP_RESPONSE_ME(setBufferSize
, ZEND_ACC_PUBLIC
)
164 HTTP_RESPONSE_ME(getBufferSize
, ZEND_ACC_PUBLIC
)
166 HTTP_RESPONSE_ME(setData
, ZEND_ACC_PUBLIC
)
167 HTTP_RESPONSE_ME(getData
, ZEND_ACC_PUBLIC
)
169 HTTP_RESPONSE_ME(setFile
, ZEND_ACC_PUBLIC
)
170 HTTP_RESPONSE_ME(getFile
, ZEND_ACC_PUBLIC
)
172 HTTP_RESPONSE_ME(setStream
, ZEND_ACC_PUBLIC
)
173 HTTP_RESPONSE_ME(getStream
, ZEND_ACC_PUBLIC
)
175 HTTP_RESPONSE_ME(send
, ZEND_ACC_PUBLIC
)
176 HTTP_RESPONSE_ME(capture
, ZEND_ACC_PUBLIC
)
178 HTTP_RESPONSE_ALIAS(redirect
, http_redirect
)
180 HTTP_RESPONSE_ALIAS(sendStatus
, http_send_status
)
181 HTTP_RESPONSE_ALIAS(sendHeader
, header
)
183 HTTP_RESPONSE_ALIAS(getRequestHeaders
, http_get_request_headers
)
184 HTTP_RESPONSE_ALIAS(getRequestBody
, http_get_request_body
)
189 void _http_response_object_init(INIT_FUNC_ARGS
)
191 HTTP_REGISTER_CLASS(HttpResponse
, http_response_object
, NULL
, 0);
192 http_response_object_declare_default_properties();
195 static inline void _http_response_object_declare_default_properties(TSRMLS_D
)
197 zend_class_entry
*ce
= http_response_object_ce
;
199 DCL_STATIC_PROP(PRIVATE
, bool, sent
, 0);
200 DCL_STATIC_PROP(PRIVATE
, bool, catch, 0);
201 DCL_STATIC_PROP(PRIVATE
, long, mode
, -1);
202 DCL_STATIC_PROP(PROTECTED
, bool, cache
, 0);
203 DCL_STATIC_PROP(PROTECTED
, bool, gzip
, 0);
204 DCL_STATIC_PROP(PROTECTED
, long, stream
, 0);
205 DCL_STATIC_PROP_N(PROTECTED
, file
);
206 DCL_STATIC_PROP_N(PROTECTED
, data
);
207 DCL_STATIC_PROP_N(PROTECTED
, eTag
);
208 DCL_STATIC_PROP(PROTECTED
, long, lastModified
, 0);
209 DCL_STATIC_PROP_N(PROTECTED
, cacheControl
);
210 DCL_STATIC_PROP_N(PROTECTED
, contentType
);
211 DCL_STATIC_PROP_N(PROTECTED
, contentDisposition
);
212 DCL_STATIC_PROP(PROTECTED
, long, bufferSize
, HTTP_SENDBUF_SIZE
);
213 DCL_STATIC_PROP(PROTECTED
, double, throttleDelay
, 0.0);
216 /* ### USERLAND ### */
218 /* {{{ proto static bool HttpResponse::setCache(bool cache)
220 * Whether it sould be attempted to cache the entitity.
221 * This will result in necessary caching headers and checks of clients
222 * "If-Modified-Since" and "If-None-Match" headers. If one of those headers
223 * matches a "304 Not Modified" status code will be issued.
225 * NOTE: If you're using sessions, be shure that you set session.cache_limiter
226 * to something more appropriate than "no-cache"!
228 PHP_METHOD(HttpResponse
, setCache
)
230 zend_bool do_cache
= 0;
232 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "b", &do_cache
)) {
236 ZVAL_BOOL(GET_STATIC_PROP(cache
), do_cache
);
241 /* {{{ proto static bool HttpResponse::getCache()
243 * Get current caching setting.
245 PHP_METHOD(HttpResponse
, getCache
)
250 RETURN_BOOL(Z_LVAL_P(GET_STATIC_PROP(cache
)));
255 /* {{{ proto static bool HttpResponse::setGzip(bool gzip)
257 * Enable on-thy-fly gzipping of the sent entity. NOT IMPLEMENTED YET.
259 PHP_METHOD(HttpResponse
, setGzip
)
261 zend_bool do_gzip
= 0;
263 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "b", &do_gzip
)) {
267 ZVAL_BOOL(GET_STATIC_PROP(gzip
), do_gzip
);
272 /* {{{ proto static bool HttpResponse::getGzip()
274 * Get current gzipping setting.
276 PHP_METHOD(HttpResponse
, getGzip
)
281 RETURN_BOOL(Z_LVAL_P(GET_STATIC_PROP(gzip
)));
286 /* {{{ proto static bool HttpResponse::setCacheControl(string control[, long max_age = 0])
288 * Set a custom cache-control header, usually being "private" or "public";
289 * The max_age parameter controls how long the cache entry is valid on the client side.
291 PHP_METHOD(HttpResponse
, setCacheControl
)
293 char *ccontrol
, *cctl
;
297 #define HTTP_CACHECONTROL_TEMPLATE "%s, must-revalidate, max_age=%ld"
299 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s|l", &ccontrol
, &cc_len
, &max_age
)) {
303 if (strcmp(ccontrol
, "public") && strcmp(ccontrol
, "private") && strcmp(ccontrol
, "no-cache")) {
304 http_error_ex(HE_WARNING
, HTTP_E_INVALID_PARAM
, "Cache-Control '%s' doesn't match public, private or no-cache", ccontrol
);
308 spprintf(&cctl
, 0, HTTP_CACHECONTROL_TEMPLATE
, ccontrol
, max_age
);
309 SET_STATIC_PROP_STRING(cacheControl
, cctl
, 0);
315 /* {{{ proto static string HttpResponse::getCacheControl()
317 * Get current Cache-Control header setting.
319 PHP_METHOD(HttpResponse
, getCacheControl
)
324 zval
*ccontrol
= GET_STATIC_PROP(cacheControl
);
325 RETURN_STRINGL(Z_STRVAL_P(ccontrol
), Z_STRLEN_P(ccontrol
), 1);
330 /* {{{ proto static bool HttpResponse::setContentType(string content_type)
332 * Set the content-type of the sent entity.
334 PHP_METHOD(HttpResponse
, setContentType
)
339 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s", &ctype
, &ctype_len
)) {
343 if (!strchr(ctype
, '/')) {
344 http_error_ex(HE_WARNING
, HTTP_E_INVALID_PARAM
, "Content type '%s' doesn't seem to contain a primary and a secondary part", ctype
);
349 SET_STATIC_PROP_STRINGL(contentType
, ctype
, ctype_len
, 1);
354 /* {{{ proto static string HttpResponse::getContentType()
356 * Get current Content-Type header setting.
358 PHP_METHOD(HttpResponse
, getContentType
)
363 zval
*ctype
= GET_STATIC_PROP(contentType
);
364 RETURN_STRINGL(Z_STRVAL_P(ctype
), Z_STRLEN_P(ctype
), 1);
369 /* {{{ proto static bool HttpResponse::setContentDisposition(string filename[, bool inline = false])
371 * Set the Content-Disposition of the sent entity. This setting aims to suggest
372 * the receiveing user agent how to handle the sent entity; usually the client
373 * will show the user a "Save As..." popup.
375 PHP_METHOD(HttpResponse
, setContentDisposition
)
379 zend_bool send_inline
= 0;
381 #define HTTP_CONTENTDISPOSITION_TEMPLATE "%s; filename=\"%s\""
383 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s|b", &file
, &file_len
, &send_inline
)) {
387 spprintf(&cd
, 0, HTTP_CONTENTDISPOSITION_TEMPLATE
, send_inline
? "inline" : "attachment", file
);
388 SET_STATIC_PROP_STRING(contentDisposition
, cd
, 0);
393 /* {{{ proto static string HttpResponse::getContentDisposition()
395 * Get current Content-Disposition setting.
397 PHP_METHOD(HttpResponse
, getContentDisposition
)
402 zval
*cd
= GET_STATIC_PROP(contentDisposition
);
403 RETURN_STRINGL(Z_STRVAL_P(cd
), Z_STRLEN_P(cd
), 1);
408 /* {{{ proto static bool HttpResponse::setETag(string etag)
410 * Set a custom ETag. Use this only if you know what you're doing.
412 PHP_METHOD(HttpResponse
, setETag
)
417 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "s", &etag
, &etag_len
)) {
422 SET_STATIC_PROP_STRINGL(eTag
, etag
, etag_len
, 1);
427 /* {{{ proto static string HttpResponse::getETag()
429 * Get the previously set custom ETag.
431 PHP_METHOD(HttpResponse
, getETag
)
436 zval
*etag
= GET_STATIC_PROP(eTag
);
437 RETURN_STRINGL(Z_STRVAL_P(etag
), Z_STRLEN_P(etag
), 1);
442 /* {{{ proto static void HttpResponse::setThrottleDelay(double seconds)
445 PHP_METHOD(HttpResponse
, setThrottleDelay
)
449 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "d", &seconds
)) {
450 ZVAL_DOUBLE(GET_STATIC_PROP(throttleDelay
), seconds
);
455 /* {{{ proto static double HttpResponse::getThrottleDelay()
458 PHP_METHOD(HttpResponse
, getThrottleDelay
)
463 RETURN_DOUBLE(Z_DVAL_P(GET_STATIC_PROP(throttleDelay
)));
468 /* {{{ proto static void HttpResponse::setBufferSize(long bytes)
471 PHP_METHOD(HttpResponse
, setBufferSize
)
475 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "l", &bytes
)) {
476 ZVAL_LONG(GET_STATIC_PROP(bufferSize
), bytes
);
481 /* {{{ proto static long HttpResponse::getBufferSize()
484 PHP_METHOD(HttpResponse
, getBufferSize
)
489 RETURN_LONG(Z_LVAL_P(GET_STATIC_PROP(bufferSize
)));
494 /* {{{ proto static bool HttpResponse::setData(string data)
496 * Set the data to be sent.
498 PHP_METHOD(HttpResponse
, setData
)
502 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "z", &the_data
)) {
505 convert_to_string_ex(&the_data
);
508 SET_STATIC_PROP(data
, the_data
);
509 ZVAL_LONG(GET_STATIC_PROP(lastModified
), http_last_modified(the_data
, SEND_DATA
));
510 ZVAL_LONG(GET_STATIC_PROP(mode
), SEND_DATA
);
511 if (!Z_STRLEN_P(GET_STATIC_PROP(eTag
))) {
512 SET_STATIC_PROP_STRING(eTag
, http_etag(Z_STRVAL_P(the_data
), Z_STRLEN_P(the_data
), SEND_DATA
), 0);
519 /* {{{ proto static string HttpResponse::getData()
521 * Get the previously set data to be sent.
523 PHP_METHOD(HttpResponse
, getData
)
528 zval
*the_data
= GET_STATIC_PROP(data
);
529 RETURN_STRINGL(Z_STRVAL_P(the_data
), Z_STRLEN_P(the_data
), 1);
534 /* {{{ proto static bool HttpResponse::setStream(resource stream)
536 * Set the resource to be sent.
538 PHP_METHOD(HttpResponse
, setStream
)
541 php_stream
*the_real_stream
;
543 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "r", &the_stream
)) {
546 zend_list_addref(Z_LVAL_P(the_stream
));
547 php_stream_from_zval(the_real_stream
, &the_stream
);
550 ZVAL_LONG(GET_STATIC_PROP(stream
), Z_LVAL_P(the_stream
));
551 ZVAL_LONG(GET_STATIC_PROP(lastModified
), http_last_modified(the_real_stream
, SEND_RSRC
));
552 ZVAL_LONG(GET_STATIC_PROP(mode
), SEND_RSRC
);
553 if (!Z_STRLEN_P(GET_STATIC_PROP(eTag
))) {
554 SET_STATIC_PROP_STRING(eTag
, http_etag(the_real_stream
, 0, SEND_RSRC
), 0);
561 /* {{{ proto static resource HttpResponse::getStream()
563 * Get the previously set resource to be sent.
565 PHP_METHOD(HttpResponse
, getStream
)
570 RETURN_RESOURCE(Z_LVAL_P(GET_STATIC_PROP(stream
)));
575 /* {{{ proto static bool HttpResponse::setFile(string file)
577 * Set the file to be sent.
579 PHP_METHOD(HttpResponse
, setFile
)
583 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "z", &the_file
)) {
587 convert_to_string_ex(&the_file
);
589 SET_STATIC_PROP(file
, the_file
);
590 ZVAL_LONG(GET_STATIC_PROP(lastModified
), http_last_modified(the_file
, -1));
591 ZVAL_LONG(GET_STATIC_PROP(mode
), -1);
592 if (!Z_STRLEN_P(GET_STATIC_PROP(eTag
))) {
593 SET_STATIC_PROP_STRING(eTag
, http_etag(the_file
, 0, -1), 0);
600 /* {{{ proto static string HttpResponse::getFile()
602 * Get the previously set file to be sent.
604 PHP_METHOD(HttpResponse
, getFile
)
609 zval
*the_file
= GET_STATIC_PROP(file
);
610 RETURN_STRINGL(Z_STRVAL_P(the_file
), Z_STRLEN_P(the_file
), 1);
615 /* {{{ proto static bool HttpResponse::send([bool clean_ob = true])
617 * Finally send the entity.
622 * HttpResponse::setCache(true);
623 * HttpResponse::setContentType('application/pdf');
624 * HttpResponse::setContentDisposition("$user.pdf", false);
625 * HttpResponse::setFile('sheet.pdf');
626 * HttpResponse::send();
630 PHP_METHOD(HttpResponse
, send
)
633 zend_bool clean_ob
= 1;
635 if (SUCCESS
!= zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|b", &clean_ob
)) {
638 if (SG(headers_sent
)) {
639 http_error(HE_WARNING
, HTTP_E_RESPONSE
, "Cannot send HttpResponse, headers have already been sent");
643 sent
= GET_STATIC_PROP(sent
);
644 if (Z_LVAL_P(sent
)) {
645 http_error(HE_WARNING
, HTTP_E_RESPONSE
, "Cannot send HttpResponse, response has already been sent");
652 if (Z_LVAL_P(GET_STATIC_PROP(catch))) {
655 INIT_PZVAL(&the_data
);
656 php_ob_get_buffer(&the_data TSRMLS_CC
);
659 SET_STATIC_PROP(data
, &the_data
);
660 ZVAL_LONG(GET_STATIC_PROP(mode
), SEND_DATA
);
662 if (!Z_STRLEN_P(GET_STATIC_PROP(eTag
))) {
663 SET_STATIC_PROP_STRING(eTag
, http_etag(Z_STRVAL(the_data
), Z_STRLEN(the_data
), SEND_DATA
), 0);
665 zval_dtor(&the_data
);
671 /* interrupt on-the-fly etag generation */
672 HTTP_G(etag
).started
= 0;
673 /* discard previous output buffers */
674 php_end_ob_buffers(0 TSRMLS_CC
);
678 if (Z_LVAL_P(GET_STATIC_PROP(gzip
))) {
679 php_start_ob_buffer_named("ob_gzhandler", 0, 1 TSRMLS_CC
);
681 php_start_ob_buffer(NULL
, 0, 0 TSRMLS_CC
);
685 if (Z_LVAL_P(GET_STATIC_PROP(cache
))) {
686 zval
*cctl
, *etag
, *lmod
;
688 etag
= GET_STATIC_PROP(eTag
);
689 lmod
= GET_STATIC_PROP(lastModified
);
690 cctl
= GET_STATIC_PROP(cacheControl
);
692 http_cache_etag(Z_STRVAL_P(etag
), Z_STRLEN_P(etag
), Z_STRVAL_P(cctl
), Z_STRLEN_P(cctl
));
693 http_cache_last_modified(Z_LVAL_P(lmod
), Z_LVAL_P(lmod
) ? Z_LVAL_P(lmod
) : time(NULL
), Z_STRVAL_P(cctl
), Z_STRLEN_P(cctl
));
698 zval
*ctype
= GET_STATIC_PROP(contentType
);
699 if (Z_STRLEN_P(ctype
)) {
700 http_send_content_type(Z_STRVAL_P(ctype
), Z_STRLEN_P(ctype
));
702 char *ctypes
= INI_STR("default_mimetype");
703 size_t ctlen
= ctypes
? strlen(ctypes
) : 0;
706 http_send_content_type(ctypes
, ctlen
);
708 http_send_content_type("application/x-octetstream", lenof("application/x-octetstream"));
713 /* content disposition */
715 zval
*cd
= GET_STATIC_PROP(contentDisposition
);
716 if (Z_STRLEN_P(cd
)) {
719 spprintf(&cds
, 0, "Content-Disposition: %s", Z_STRVAL_P(cd
));
720 http_send_header(cds
);
727 HTTP_G(send
).buffer_size
= Z_LVAL_P(GET_STATIC_PROP(bufferSize
));
728 HTTP_G(send
).throttle_delay
= Z_DVAL_P(GET_STATIC_PROP(throttleDelay
));
733 switch (Z_LVAL_P(GET_STATIC_PROP(mode
)))
737 zval
*zdata
= GET_STATIC_PROP(data
);
738 RETURN_SUCCESS(http_send_data(Z_STRVAL_P(zdata
), Z_STRLEN_P(zdata
)));
743 php_stream
*the_real_stream
;
744 zval
*the_stream
= GET_STATIC_PROP(stream
);
745 the_stream
->type
= IS_RESOURCE
;
746 php_stream_from_zval(the_real_stream
, &the_stream
);
747 RETURN_SUCCESS(http_send_stream(the_real_stream
));
752 RETURN_SUCCESS(http_send_file(Z_STRVAL_P(GET_STATIC_PROP(file
))));
759 /* {{{ proto static void HttpResponse::capture()
761 * Capture script output.
766 * HttpResponse::setCache(true);
767 * HttpResponse::capture();
772 PHP_METHOD(HttpResponse
, capture
)
778 INIT_PZVAL(&do_catch
);
779 ZVAL_LONG(&do_catch
, 1);
781 SET_STATIC_PROP(catch, &do_catch
);
783 php_end_ob_buffers(0 TSRMLS_CC
);
784 php_start_ob_buffer(NULL
, 0, 0 TSRMLS_CC
);
786 /* register shutdown function */
788 zval func
, retval
, arg
, *argp
[1];
793 ZVAL_STRINGL(&func
, "register_shutdown_function", lenof("register_shutdown_function"), 0);
796 add_next_index_stringl(&arg
, "HttpResponse", lenof("HttpResponse"), 1);
797 add_next_index_stringl(&arg
, "send", lenof("send"), 1);
799 call_user_function(EG(function_table
), NULL
, &func
, &retval
, 1, argp TSRMLS_CC
);
805 #endif /* ZEND_ENGINE_2 */
812 * vim600: noet sw=4 ts=4 fdm=marker
813 * vim<600: noet sw=4 ts=4