2 +--------------------------------------------------------------------+
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the conditions mentioned |
7 | in the accompanying LICENSE file are met. |
8 +--------------------------------------------------------------------+
9 | Copyright (c) 2004-2014, Michael Wallner <mike@php.net> |
10 +--------------------------------------------------------------------+
13 #include "php_http_api.h"
15 static void set_option(zval
*options
, const char *name_str
, size_t name_len
, int type
, void *value_ptr
, size_t value_len
)
17 if (Z_TYPE_P(options
) == IS_OBJECT
) {
21 zend_update_property_double(Z_OBJCE_P(options
), options
, name_str
, name_len
, *(double *)value_ptr
);
24 zend_update_property_long(Z_OBJCE_P(options
), options
, name_str
, name_len
, *(zend_long
*)value_ptr
);
27 zend_update_property_stringl(Z_OBJCE_P(options
), options
, name_str
, name_len
, value_ptr
, value_len
);
31 zend_update_property(Z_OBJCE_P(options
), options
, name_str
, name_len
, value_ptr
);
35 zend_update_property_null(Z_OBJCE_P(options
), options
, name_str
, name_len
);
38 convert_to_array(options
);
42 add_assoc_double_ex(options
, name_str
, name_len
, *(double *)value_ptr
);
45 add_assoc_long_ex(options
, name_str
, name_len
, *(zend_long
*)value_ptr
);
48 zend_string
*value
= zend_string_init(value_ptr
, value_len
, 0);
49 add_assoc_str_ex(options
, name_str
, name_len
, value
);
53 Z_ADDREF_P(value_ptr
);
54 add_assoc_zval_ex(options
, name_str
, name_len
, value_ptr
);
59 add_assoc_null_ex(options
, name_str
, name_len
);
63 static zval
*get_option(zval
*options
, const char *name_str
, size_t name_len
)
67 if (Z_TYPE_P(options
) == IS_OBJECT
) {
68 val
= zend_read_property(Z_OBJCE_P(options
), options
, name_str
, name_len
, 0);
70 val
= zend_symtable_str_find(Z_ARRVAL_P(options
), name_str
, name_len
);
77 static php_http_message_body_t
*get_body(zval
*options
)
80 php_http_message_body_t
*body
= NULL
;
82 if ((zbody
= get_option(options
, ZEND_STRL("body")))) {
83 if ((Z_TYPE_P(zbody
) == IS_OBJECT
) && instanceof_function(Z_OBJCE_P(zbody
), php_http_message_body_class_entry
)) {
84 php_http_message_body_object_t
*body_obj
= PHP_HTTP_OBJ(NULL
, zbody
);
86 body
= body_obj
->body
;
93 static php_http_message_t
*get_request(zval
*options
)
96 php_http_message_t
*request
= NULL
;
98 if ((zrequest
= get_option(options
, ZEND_STRL("request")))) {
99 if (Z_TYPE_P(zrequest
) == IS_OBJECT
&& instanceof_function(Z_OBJCE_P(zrequest
), php_http_message_class_entry
)) {
100 php_http_message_object_t
*request_obj
= PHP_HTTP_OBJ(NULL
, zrequest
);
102 request
= request_obj
->message
;
104 zval_ptr_dtor(zrequest
);
109 static void set_cookie(zval
*options
, zval
*zcookie_new TSRMLS_DC
)
112 php_http_arrkey_t key
;
113 php_http_cookie_object_t
*obj
= PHP_HTTP_OBJ(NULL
, zcookie_new
);
115 zcookies_set
= get_option(options
, ZEND_STRL("cookies"));
116 if (!zcookies_set
|| Z_TYPE_P(zcookies_set
) != IS_ARRAY
) {
118 zval_ptr_dtor(zcookies_set
);
120 array_init_size(zcookies_set
, zend_hash_num_elements(&obj
->list
->cookies
));
122 Z_ADDREF_P(zcookies_set
);
123 SEPARATE_ZVAL(zcookies_set
);
126 ZEND_HASH_FOREACH_KEY(&obj
->list
->cookies
, key
.h
, key
.key
)
128 Z_ADDREF_P(zcookie_new
);
130 add_assoc_zval_ex(zcookies_set
, key
.key
->val
, key
.key
->len
, zcookie_new
);
132 add_index_zval(zcookies_set
, key
.h
, zcookie_new
);
135 ZEND_HASH_FOREACH_END();
137 set_option(options
, ZEND_STRL("cookies"), IS_ARRAY
, zcookies_set
, 0);
138 zval_ptr_dtor(zcookies_set
);
141 php_http_cache_status_t
php_http_env_is_response_cached_by_etag(zval
*options
, const char *header_str
, size_t header_len
, php_http_message_t
*request
)
143 php_http_cache_status_t ret
= PHP_HTTP_CACHE_NO
;
144 char *header
= NULL
, *etag
= NULL
;
145 php_http_message_body_t
*body
;
149 if (!(body
= get_body(options
))) {
153 if ((zetag
= get_option(options
, ZEND_STRL("etag")))) {
154 zend_string
*zs
= zval_get_string(zetag
);
155 etag
= estrndup(zs
->val
, zs
->len
);
156 zend_string_release(zs
);
157 zval_ptr_dtor(zetag
);
160 if (!etag
&& (etag
= php_http_message_body_etag(body
))) {
161 set_option(options
, ZEND_STRL("etag"), IS_STRING
, etag
, strlen(etag
));
164 if (etag
&& (header
= php_http_env_get_request_header(header_str
, header_len
, NULL
, request
))) {
165 ret
= php_http_match(header
, etag
, PHP_HTTP_MATCH_WORD
) ? PHP_HTTP_CACHE_HIT
: PHP_HTTP_CACHE_MISS
;
174 php_http_cache_status_t
php_http_env_is_response_cached_by_last_modified(zval
*options
, const char *header_str
, size_t header_len
, php_http_message_t
*request
)
176 php_http_cache_status_t ret
= PHP_HTTP_CACHE_NO
;
179 php_http_message_body_t
*body
;
182 if (!(body
= get_body(options
))) {
186 if ((zlm
= get_option(options
, ZEND_STRL("lastModified")))) {
187 lm
= zval_get_long(zlm
);
192 lm
= php_http_message_body_mtime(body
);
193 set_option(options
, ZEND_STRL("lastModified"), IS_LONG
, &lm
, 0);
196 if ((header
= php_http_env_get_request_header(header_str
, header_len
, NULL
, request
))) {
197 ums
= php_parse_date(header
, NULL
);
199 if (ums
> 0 && ums
>= lm
) {
200 ret
= PHP_HTTP_CACHE_HIT
;
202 ret
= PHP_HTTP_CACHE_MISS
;
210 static zend_bool
php_http_env_response_is_cacheable(php_http_env_response_t
*r
, php_http_message_t
*request
)
212 if (r
->ops
->get_status(r
) >= 400) {
216 if (php_http_env_got_request_header(ZEND_STRL("Authorization"), request
)) {
220 if (-1 == php_http_select_str(php_http_env_get_request_method(request
), 2, "HEAD", "GET")) {
227 static size_t output(void *context
, char *buf
, size_t len
)
229 php_http_env_response_t
*r
= context
;
231 if (SUCCESS
!= r
->ops
->write(r
, buf
, len
)) {
235 /* we really only need to flush when throttling is enabled,
236 because we push the data as fast as possible anyway if not */
237 if (r
->throttle
.delay
>= PHP_HTTP_DIFFSEC
) {
239 php_http_sleep(r
->throttle
.delay
);
244 static ZEND_RESULT_CODE
php_http_env_response_send_data(php_http_env_response_t
*r
, const char *buf
, size_t len
)
246 size_t chunks_sent
, chunk
= r
->throttle
.chunk
? r
->throttle
.chunk
: PHP_HTTP_SENDBUF_SIZE
;
248 if (r
->content
.encoder
) {
249 char *enc_str
= NULL
;
253 if (SUCCESS
!= php_http_encoding_stream_update(r
->content
.encoder
, buf
, len
, &enc_str
, &enc_len
)) {
257 if (SUCCESS
!= php_http_encoding_stream_finish(r
->content
.encoder
, &enc_str
, &enc_len
)) {
265 chunks_sent
= php_http_buffer_chunked_output(&r
->buffer
, enc_str
, enc_len
, buf
? chunk
: 0, output
, r
);
268 chunks_sent
= php_http_buffer_chunked_output(&r
->buffer
, buf
, len
, buf
? chunk
: 0, output
, r
);
271 return chunks_sent
!= (size_t) -1 ? SUCCESS
: FAILURE
;
274 static inline ZEND_RESULT_CODE
php_http_env_response_send_done(php_http_env_response_t
*r
)
276 return php_http_env_response_send_data(r
, NULL
, 0);
279 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
)
284 r
= emalloc(sizeof(*r
));
286 memset(r
, 0, sizeof(*r
));
291 r
->ops
= php_http_env_response_get_sapi_ops();
294 r
->buffer
= php_http_buffer_init(NULL
);
296 ZVAL_COPY(&r
->options
, options
);
298 if (r
->ops
->init
&& (SUCCESS
!= r
->ops
->init(r
, init_arg
))) {
300 php_http_env_response_free(&r
);
302 php_http_env_response_dtor(r
);
310 void php_http_env_response_dtor(php_http_env_response_t
*r
)
315 php_http_buffer_free(&r
->buffer
);
316 zval_ptr_dtor(&r
->options
);
317 PTR_FREE(r
->content
.type
);
318 PTR_FREE(r
->content
.encoding
);
319 if (r
->content
.encoder
) {
320 php_http_encoding_stream_free(&r
->content
.encoder
);
324 void php_http_env_response_free(php_http_env_response_t
**r
)
327 php_http_env_response_dtor(*r
);
333 static ZEND_RESULT_CODE
php_http_env_response_send_head(php_http_env_response_t
*r
, php_http_message_t
*request
)
335 ZEND_RESULT_CODE ret
= SUCCESS
;
336 zval
*zoption
, *options
= &r
->options
;
342 if ((zoption
= get_option(options
, ZEND_STRL("headers")))) {
343 if (Z_TYPE_P(zoption
) == IS_ARRAY
) {
344 php_http_header_to_callback(Z_ARRVAL_P(zoption
), 0, (php_http_pass_format_callback_t
) r
->ops
->set_header
, r
);
346 zval_ptr_dtor(zoption
);
349 if (ret
!= SUCCESS
) {
353 if ((zoption
= get_option(options
, ZEND_STRL("responseCode")))) {
354 zend_long rc
= zval_get_long(zoption
);
356 zval_ptr_dtor(zoption
);
358 ret
= r
->ops
->set_status(r
, rc
);
362 if (ret
!= SUCCESS
) {
366 if ((zoption
= get_option(options
, ZEND_STRL("httpVersion")))) {
367 php_http_version_t v
;
368 zend_string
*zs
= zval_get_string(zoption
);
370 zval_ptr_dtor(zoption
);
371 if (zs
->len
&& php_http_version_parse(&v
, zs
->val
)) {
372 ret
= r
->ops
->set_protocol_version(r
, &v
);
373 php_http_version_dtor(&v
);
375 zend_string_release(zs
);
378 if (ret
!= SUCCESS
) {
382 if ((zoption
= get_option(options
, ZEND_STRL("cookies")))) {
383 if (Z_TYPE_P(zoption
) == IS_ARRAY
) {
386 ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(zoption
), zcookie
)
388 if (Z_TYPE_P(zcookie
) == IS_OBJECT
&& instanceof_function(Z_OBJCE_P(zcookie
), php_http_cookie_class_entry
)) {
389 php_http_cookie_object_t
*obj
= PHP_HTTP_OBJ(NULL
, zcookie
);
393 php_http_cookie_list_to_string(obj
->list
, &str
, &len
);
394 if (SUCCESS
!= (ret
= r
->ops
->add_header(r
, "Set-Cookie: %s", str
))) {
401 ZEND_HASH_FOREACH_END();
403 zval_ptr_dtor(zoption
);
406 if (ret
!= SUCCESS
) {
410 if ((zoption
= get_option(options
, ZEND_STRL("contentType")))) {
411 zend_string
*zs
= zval_get_string(zoption
);
413 zval_ptr_dtor(zoption
);
414 if (zs
->len
&& strchr(zs
->val
, '/')) {
415 if (SUCCESS
== (ret
= r
->ops
->set_header(r
, "Content-Type: %.*s", zs
->len
, zs
->val
))) {
416 r
->content
.type
= estrndup(zs
->val
, zs
->len
);
419 zend_string_release(zs
);
422 if (ret
!= SUCCESS
) {
426 if (r
->range
.status
== PHP_HTTP_RANGE_OK
) {
427 if (zend_hash_num_elements(&r
->range
.values
) == 1) {
428 zval
*range
, *begin
, *end
;
430 if ( 1 == php_http_array_list(&r
->range
.values
, 1, &range
)
431 && 2 == php_http_array_list(Z_ARRVAL_P(range
), 2, &begin
, &end
)
433 if (SUCCESS
== (ret
= r
->ops
->set_status(r
, 206))) {
434 ret
= r
->ops
->set_header(r
, "Content-Range: bytes %ld-%ld/%zu", Z_LVAL_P(begin
), Z_LVAL_P(end
), r
->content
.length
);
437 /* this should never happen */
438 zend_hash_destroy(&r
->range
.values
);
442 php_http_boundary(r
->range
.boundary
, sizeof(r
->range
.boundary
));
443 if (SUCCESS
== (ret
= r
->ops
->set_status(r
, 206))) {
444 ret
= r
->ops
->set_header(r
, "Content-Type: multipart/byteranges; boundary=%s", r
->range
.boundary
);
448 if ((zoption
= get_option(options
, ZEND_STRL("cacheControl")))) {
449 zend_string
*zs
= zval_get_string(zoption
);
451 zval_ptr_dtor(zoption
);
453 ret
= r
->ops
->set_header(r
, "Cache-Control: %.*s", zs
->len
, zs
->val
);
455 zend_string_release(zs
);
458 if (ret
!= SUCCESS
) {
462 if ((zoption
= get_option(options
, ZEND_STRL("contentDisposition")))) {
463 php_http_buffer_t buf
;
465 if (Z_TYPE_P(zoption
) != IS_ARRAY
) {
468 convert_to_array(tmp
);
472 php_http_buffer_init(&buf
);
473 if (php_http_params_to_string(&buf
, Z_ARRVAL_P(zoption
), ZEND_STRL(","), ZEND_STRL(";"), ZEND_STRL("="), PHP_HTTP_PARAMS_DEFAULT
)) {
475 ret
= r
->ops
->set_header(r
, "Content-Disposition: %.*s", buf
.used
, buf
.data
);
479 php_http_buffer_dtor(&buf
);
480 zval_ptr_dtor(zoption
);
483 if (ret
!= SUCCESS
) {
487 if ((zoption
= get_option(options
, ZEND_STRL("contentEncoding")))) {
488 zend_long ce
= zval_get_long(zoption
);
490 HashTable
*result
= NULL
;
492 zval_ptr_dtor(zoption
);
494 case PHP_HTTP_CONTENT_ENCODING_GZIP
:
495 array_init(&zsupported
);
496 add_next_index_stringl(&zsupported
, ZEND_STRL("none"));
497 add_next_index_stringl(&zsupported
, ZEND_STRL("gzip"));
498 add_next_index_stringl(&zsupported
, ZEND_STRL("deflate"));
500 if ((result
= php_http_negotiate_encoding(Z_ARRVAL(zsupported
), request
))) {
501 zend_string
*key_str
= NULL
;
502 zend_ulong index
= 0;
504 zend_hash_internal_pointer_reset(result
);
505 if (HASH_KEY_IS_STRING
== zend_hash_get_current_key(result
, &key_str
, &index
)) {
506 if (zend_string_equals_literal(key_str
, "gzip")) {
507 if (!(r
->content
.encoder
= php_http_encoding_stream_init(NULL
, php_http_encoding_stream_get_deflate_ops(), PHP_HTTP_DEFLATE_TYPE_GZIP
))) {
509 } else if (SUCCESS
== (ret
= r
->ops
->set_header(r
, "Content-Encoding: gzip"))) {
510 r
->content
.encoding
= estrndup(key_str
->val
, key_str
->len
);
512 } else if (zend_string_equals_literal(key_str
, "deflate")) {
513 if (!(r
->content
.encoder
= php_http_encoding_stream_init(NULL
, php_http_encoding_stream_get_deflate_ops(), PHP_HTTP_DEFLATE_TYPE_ZLIB
))) {
515 } else if (SUCCESS
== (ret
= r
->ops
->set_header(r
, "Content-Encoding: deflate"))) {
516 r
->content
.encoding
= estrndup(key_str
->val
, key_str
->len
);
519 ret
= r
->ops
->del_header(r
, ZEND_STRL("Content-Encoding"));
522 if (SUCCESS
== ret
) {
523 ret
= r
->ops
->add_header(r
, "Vary: Accept-Encoding");
527 zend_hash_destroy(result
);
528 FREE_HASHTABLE(result
);
531 zval_dtor(&zsupported
);
534 case PHP_HTTP_CONTENT_ENCODING_NONE
:
536 ret
= r
->ops
->del_header(r
, ZEND_STRL("Content-Encoding"));
541 if (SUCCESS
!= ret
) {
545 if (php_http_env_response_is_cacheable(r
, request
)) {
546 switch (php_http_env_is_response_cached_by_etag(options
, ZEND_STRL("If-None-Match"), request
)) {
547 case PHP_HTTP_CACHE_MISS
:
550 case PHP_HTTP_CACHE_NO
:
551 if (PHP_HTTP_CACHE_HIT
!= php_http_env_is_response_cached_by_last_modified(options
, ZEND_STRL("If-Modified-Since"), request
)) {
556 case PHP_HTTP_CACHE_HIT
:
557 ret
= r
->ops
->set_status(r
, 304);
562 if ((zoption
= get_option(options
, ZEND_STRL("etag")))) {
563 zend_string
*zs
= zval_get_string(zoption
);
565 zval_ptr_dtor(zoption
);
566 if (*zs
->val
!= '"' && strncmp(zs
->val
, "W/\"", 3)) {
567 ret
= r
->ops
->set_header(r
, "ETag: \"%s\"", zs
->val
);
569 ret
= r
->ops
->set_header(r
, "ETag: %s", zs
->val
);
571 zend_string_release(zs
);
573 if ((zoption
= get_option(options
, ZEND_STRL("lastModified") TSRMLS_CC
))) {
574 zend_long lm
= zval_get_long(zoption
);
576 zval_ptr_dtor(zoption
);
578 zend_string
*date
= php_format_date(ZEND_STRL(PHP_HTTP_DATE_FORMAT
), lm
, 0);
580 ret
= r
->ops
->set_header(r
, "Last-Modified: %s", date
->val
);
581 zend_string_release(date
);
591 static ZEND_RESULT_CODE
php_http_env_response_send_body(php_http_env_response_t
*r
)
593 ZEND_RESULT_CODE ret
= SUCCESS
;
595 php_http_message_body_t
*body
;
601 if ((body
= get_body(&r
->options
))) {
602 if ((zoption
= get_option(&r
->options
, ZEND_STRL("throttleDelay")))) {
603 r
->throttle
.delay
= zval_get_double(zoption
);
604 zval_ptr_dtor(zoption
);
606 if ((zoption
= get_option(&r
->options
, ZEND_STRL("throttleChunk") TSRMLS_CC
))) {
607 r
->throttle
.chunk
= zval_get_long(zoption
);
608 zval_ptr_dtor(zoption
);
611 if (r
->range
.status
== PHP_HTTP_RANGE_OK
) {
612 if (zend_hash_num_elements(&r
->range
.values
) == 1) {
614 zval
*range
, *begin
, *end
;
616 if ( 1 == php_http_array_list(&r
->range
.values
, 1, &range
)
617 && 2 == php_http_array_list(Z_ARRVAL_P(range
), 2, &begin
, &end
)
620 ret
= php_http_message_body_to_callback(body
, (php_http_pass_callback_t
) php_http_env_response_send_data
, r
, Z_LVAL_P(begin
), Z_LVAL_P(end
) - Z_LVAL_P(begin
) + 1);
621 if (ret
== SUCCESS
) {
622 ret
= php_http_env_response_send_done(r
);
624 zend_hash_destroy(&r
->range
.values
);
626 /* this should never happen */
627 zend_hash_destroy(&r
->range
.values
);
628 r
->ops
->set_status(r
, 500);
633 /* send multipart/byte-ranges message */
636 ZEND_HASH_FOREACH_VAL(&r
->range
.values
, chunk
)
640 if (2 == php_http_array_list(Z_ARRVAL_P(chunk
), 2, &begin
, &end
)) {
641 php_http_buffer_appendf(r
->buffer
,
644 "Content-Type: %s" PHP_HTTP_CRLF
645 "Content-Range: bytes %ld-%ld/%zu" PHP_HTTP_CRLF PHP_HTTP_CRLF
,
648 r
->content
.type
? r
->content
.type
: "application/octet-stream",
653 ret
= php_http_message_body_to_callback(body
, (php_http_pass_callback_t
) php_http_env_response_send_data
, r
, Z_LVAL_P(begin
), Z_LVAL_P(end
) - Z_LVAL_P(begin
) + 1);
656 ZEND_HASH_FOREACH_END();
658 if (ret
== SUCCESS
) {
659 php_http_buffer_appendf(r
->buffer
, PHP_HTTP_CRLF
"--%s--", r
->range
.boundary
);
660 ret
= php_http_env_response_send_done(r
);
662 zend_hash_destroy(&r
->range
.values
);
666 ret
= php_http_message_body_to_callback(body
, (php_http_pass_callback_t
) php_http_env_response_send_data
, r
, 0, 0);
667 if (ret
== SUCCESS
) {
668 ret
= php_http_env_response_send_done(r
);
675 ZEND_RESULT_CODE
php_http_env_response_send(php_http_env_response_t
*r
)
677 php_http_message_t
*request
;
678 php_http_message_body_t
*body
;
680 request
= get_request(&r
->options
);
682 /* check for ranges */
683 if ((body
= get_body(&r
->options
))) {
684 r
->content
.length
= php_http_message_body_size(body
);
686 if (SUCCESS
!= r
->ops
->set_header(r
, "Accept-Ranges: bytes")) {
689 ZEND_INIT_SYMTABLE_EX(&r
->range
.values
, 0, 0);
690 r
->range
.status
= php_http_env_get_request_ranges(&r
->range
.values
, r
->content
.length
, request
);
692 switch (r
->range
.status
) {
693 case PHP_HTTP_RANGE_NO
:
694 zend_hash_destroy(&r
->range
.values
);
697 case PHP_HTTP_RANGE_ERR
:
698 if (php_http_env_got_request_header(ZEND_STRL("If-Range"), request
)) {
699 r
->range
.status
= PHP_HTTP_RANGE_NO
;
700 zend_hash_destroy(&r
->range
.values
);
703 zend_hash_destroy(&r
->range
.values
);
704 if (SUCCESS
!= r
->ops
->set_status(r
, 416)) {
707 if (SUCCESS
!= r
->ops
->set_header(r
, "Content-Range: bytes */%zu", r
->content
.length
)) {
713 case PHP_HTTP_RANGE_OK
:
714 if (PHP_HTTP_CACHE_MISS
== php_http_env_is_response_cached_by_etag(&r
->options
, ZEND_STRL("If-Range"), request
)
715 || PHP_HTTP_CACHE_MISS
== php_http_env_is_response_cached_by_last_modified(&r
->options
, ZEND_STRL("If-Range"), request
)
717 r
->range
.status
= PHP_HTTP_RANGE_NO
;
718 zend_hash_destroy(&r
->range
.values
);
721 if (PHP_HTTP_CACHE_MISS
== php_http_env_is_response_cached_by_etag(&r
->options
, ZEND_STRL("If-Match"), request
)
722 || PHP_HTTP_CACHE_MISS
== php_http_env_is_response_cached_by_last_modified(&r
->options
, ZEND_STRL("If-Unmodified-Since"), request
)
723 || PHP_HTTP_CACHE_MISS
== php_http_env_is_response_cached_by_last_modified(&r
->options
, ZEND_STRL("Unless-Modified-Since"), request
)
726 zend_hash_destroy(&r
->range
.values
);
727 if (SUCCESS
!= r
->ops
->set_status(r
, 412)) {
738 if (SUCCESS
!= php_http_env_response_send_head(r
, request
)) {
739 php_error_docref(NULL
, E_WARNING
, "Failed to send response headers");
743 if (SUCCESS
!= php_http_env_response_send_body(r
)) {
744 php_error_docref(NULL
, E_WARNING
, "Failed to send response body");
748 if (SUCCESS
!= r
->ops
->finish(r
)) {
749 php_error_docref(NULL
, E_WARNING
, "Failed to finish response");
756 static long php_http_env_response_sapi_get_status(php_http_env_response_t
*r
)
758 return php_http_env_get_response_code();
760 static ZEND_RESULT_CODE
php_http_env_response_sapi_set_status(php_http_env_response_t
*r
, long http_code
)
762 return php_http_env_set_response_code(http_code
);
764 static ZEND_RESULT_CODE
php_http_env_response_sapi_set_protocol_version(php_http_env_response_t
*r
, php_http_version_t
*v
)
767 return php_http_env_set_response_protocol_version(v
);
769 static ZEND_RESULT_CODE
php_http_env_response_sapi_set_header(php_http_env_response_t
*r
, const char *fmt
, ...)
771 ZEND_RESULT_CODE ret
;
775 ret
= php_http_env_set_response_header_va(0, 1, fmt
, args
);
780 static ZEND_RESULT_CODE
php_http_env_response_sapi_add_header(php_http_env_response_t
*r
, const char *fmt
, ...)
782 ZEND_RESULT_CODE ret
;
786 ret
= php_http_env_set_response_header_va(0, 0, fmt
, args
);
791 static ZEND_RESULT_CODE
php_http_env_response_sapi_del_header(php_http_env_response_t
*r
, const char *header_str
, size_t header_len
)
793 return php_http_env_set_response_header_value(0, header_str
, header_len
, NULL
, 1);
795 static ZEND_RESULT_CODE
php_http_env_response_sapi_write(php_http_env_response_t
*r
, const char *data_str
, size_t data_len
)
797 if (0 < PHPWRITE(data_str
, data_len
)) {
802 static ZEND_RESULT_CODE
php_http_env_response_sapi_flush(php_http_env_response_t
*r
)
804 if (php_output_get_level()) {
805 php_output_flush_all();
807 if (!(php_output_get_status() & PHP_OUTPUT_IMPLICITFLUSH
)) {
813 static ZEND_RESULT_CODE
php_http_env_response_sapi_finish(php_http_env_response_t
*r
)
818 static php_http_env_response_ops_t php_http_env_response_sapi_ops
= {
821 php_http_env_response_sapi_get_status
,
822 php_http_env_response_sapi_set_status
,
823 php_http_env_response_sapi_set_protocol_version
,
824 php_http_env_response_sapi_set_header
,
825 php_http_env_response_sapi_add_header
,
826 php_http_env_response_sapi_del_header
,
827 php_http_env_response_sapi_write
,
828 php_http_env_response_sapi_flush
,
829 php_http_env_response_sapi_finish
832 php_http_env_response_ops_t
*php_http_env_response_get_sapi_ops(void)
834 return &php_http_env_response_sapi_ops
;
837 typedef struct php_http_env_response_stream_ctx
{
839 php_http_version_t version
;
846 } php_http_env_response_stream_ctx_t
;
848 static ZEND_RESULT_CODE
php_http_env_response_stream_init(php_http_env_response_t
*r
, void *init_arg
)
850 php_http_env_response_stream_ctx_t
*ctx
;
852 ctx
= ecalloc(1, sizeof(*ctx
));
854 ctx
->stream
= init_arg
;
855 ++GC_REFCOUNT(ctx
->stream
->res
);
856 ZEND_INIT_SYMTABLE(&ctx
->header
);
857 php_http_version_init(&ctx
->version
, 1, 1);
858 ctx
->status_code
= 200;
864 static void php_http_env_response_stream_dtor(php_http_env_response_t
*r
)
866 php_http_env_response_stream_ctx_t
*ctx
= r
->ctx
;
868 zend_hash_destroy(&ctx
->header
);
869 zend_list_delete(ctx
->stream
->res
);
873 static void php_http_env_response_stream_header(php_http_env_response_stream_ctx_t
*ctx
, HashTable
*header
)
877 ZEND_HASH_FOREACH_VAL(header
, val
)
879 if (Z_TYPE_P(val
) == IS_ARRAY
) {
880 php_http_env_response_stream_header(ctx
, Z_ARRVAL_P(val
));
882 zend_string
*zs
= zval_get_string(val
);
884 php_stream_write(ctx
->stream
, zs
->val
, zs
->len
);
885 php_stream_write_string(ctx
->stream
, PHP_HTTP_CRLF
);
886 zend_string_release(zs
);
889 ZEND_HASH_FOREACH_END();
891 static ZEND_RESULT_CODE
php_http_env_response_stream_start(php_http_env_response_stream_ctx_t
*ctx
)
893 if (ctx
->started
|| ctx
->finished
) {
897 php_stream_printf(ctx
->stream TSRMLS_CC
, "HTTP/%u.%u %ld %s" PHP_HTTP_CRLF
, ctx
->version
.major
, ctx
->version
.minor
, ctx
->status_code
, php_http_env_get_response_status_for_code(ctx
->status_code
));
898 php_http_env_response_stream_header(ctx
, &ctx
->header
);
899 php_stream_write_string(ctx
->stream
, PHP_HTTP_CRLF
);
903 static long php_http_env_response_stream_get_status(php_http_env_response_t
*r
)
905 php_http_env_response_stream_ctx_t
*ctx
= r
->ctx
;
907 return ctx
->status_code
;
909 static ZEND_RESULT_CODE
php_http_env_response_stream_set_status(php_http_env_response_t
*r
, long http_code
)
911 php_http_env_response_stream_ctx_t
*stream_ctx
= r
->ctx
;
913 if (stream_ctx
->started
|| stream_ctx
->finished
) {
917 stream_ctx
->status_code
= http_code
;
921 static ZEND_RESULT_CODE
php_http_env_response_stream_set_protocol_version(php_http_env_response_t
*r
, php_http_version_t
*v
)
923 php_http_env_response_stream_ctx_t
*stream_ctx
= r
->ctx
;
925 if (stream_ctx
->started
|| stream_ctx
->finished
) {
929 memcpy(&stream_ctx
->version
, v
, sizeof(stream_ctx
->version
));
933 static ZEND_RESULT_CODE
php_http_env_response_stream_set_header_ex(php_http_env_response_t
*r
, zend_bool replace
, const char *fmt
, va_list argv
)
935 php_http_env_response_stream_ctx_t
*stream_ctx
= r
->ctx
;
936 char *header_end
, *header_str
= NULL
;
937 size_t header_len
= 0;
938 zval zheader
, *zheader_ptr
;
940 if (stream_ctx
->started
|| stream_ctx
->finished
) {
944 header_len
= vspprintf(&header_str
, 0, fmt
, argv
);
946 if (!(header_end
= strchr(header_str
, ':'))) {
953 if (!replace
&& (zheader_ptr
= zend_hash_str_find(&stream_ctx
->header
, header_str
, header_end
- header_str
))) {
954 convert_to_array(zheader_ptr
);
956 return add_next_index_str(zheader_ptr
, php_http_cs2zs(header_str
, header_len
));
958 ZVAL_STR(&zheader
, php_http_cs2zs(header_str
, header_len
));
960 if (SUCCESS
!= zend_hash_str_update(&stream_ctx
->header
, header_str
, header_end
- header_str
, &zheader
)) {
968 static ZEND_RESULT_CODE
php_http_env_response_stream_set_header(php_http_env_response_t
*r
, const char *fmt
, ...)
970 ZEND_RESULT_CODE ret
;
974 ret
= php_http_env_response_stream_set_header_ex(r
, 1, fmt
, argv
);
979 static ZEND_RESULT_CODE
php_http_env_response_stream_add_header(php_http_env_response_t
*r
, const char *fmt
, ...)
981 ZEND_RESULT_CODE ret
;
985 ret
= php_http_env_response_stream_set_header_ex(r
, 0, fmt
, argv
);
990 static ZEND_RESULT_CODE
php_http_env_response_stream_del_header(php_http_env_response_t
*r
, const char *header_str
, size_t header_len
)
992 php_http_env_response_stream_ctx_t
*stream_ctx
= r
->ctx
;
994 if (stream_ctx
->started
|| stream_ctx
->finished
) {
998 zend_hash_str_del(&stream_ctx
->header
, header_str
, header_len
);
1001 static ZEND_RESULT_CODE
php_http_env_response_stream_write(php_http_env_response_t
*r
, const char *data_str
, size_t data_len
)
1003 php_http_env_response_stream_ctx_t
*stream_ctx
= r
->ctx
;
1005 if (stream_ctx
->finished
) {
1008 if (!stream_ctx
->started
) {
1009 if (SUCCESS
!= php_http_env_response_stream_start(stream_ctx
)) {
1014 if (data_len
!= php_stream_write(stream_ctx
->stream
, data_str
, data_len
)) {
1020 static ZEND_RESULT_CODE
php_http_env_response_stream_flush(php_http_env_response_t
*r
)
1022 php_http_env_response_stream_ctx_t
*stream_ctx
= r
->ctx
;
1024 if (stream_ctx
->finished
) {
1027 if (!stream_ctx
->started
) {
1028 if (SUCCESS
!= php_http_env_response_stream_start(stream_ctx
)) {
1033 return php_stream_flush(stream_ctx
->stream
);
1035 static ZEND_RESULT_CODE
php_http_env_response_stream_finish(php_http_env_response_t
*r
)
1037 php_http_env_response_stream_ctx_t
*stream_ctx
= r
->ctx
;
1039 if (stream_ctx
->finished
) {
1042 if (!stream_ctx
->started
) {
1043 if (SUCCESS
!= php_http_env_response_stream_start(stream_ctx
)) {
1048 stream_ctx
->finished
= 1;
1053 static php_http_env_response_ops_t php_http_env_response_stream_ops
= {
1054 php_http_env_response_stream_init
,
1055 php_http_env_response_stream_dtor
,
1056 php_http_env_response_stream_get_status
,
1057 php_http_env_response_stream_set_status
,
1058 php_http_env_response_stream_set_protocol_version
,
1059 php_http_env_response_stream_set_header
,
1060 php_http_env_response_stream_add_header
,
1061 php_http_env_response_stream_del_header
,
1062 php_http_env_response_stream_write
,
1063 php_http_env_response_stream_flush
,
1064 php_http_env_response_stream_finish
1067 php_http_env_response_ops_t
*php_http_env_response_get_stream_ops(void)
1069 return &php_http_env_response_stream_ops
;
1072 #define PHP_HTTP_ENV_RESPONSE_OBJECT_INIT(obj) \
1074 if (!obj->message) { \
1075 obj->message = php_http_message_init_env(NULL, PHP_HTTP_RESPONSE); \
1079 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse___construct
, 0, 0, 0)
1080 ZEND_END_ARG_INFO();
1081 static PHP_METHOD(HttpEnvResponse
, __construct
)
1083 php_http_message_object_t
*obj
;
1085 php_http_expect(SUCCESS
== zend_parse_parameters_none(), invalid_arg
, return);
1087 obj
= PHP_HTTP_OBJ(NULL
, getThis());
1089 php_http_expect(obj
->message
= php_http_message_init_env(obj
->message
, PHP_HTTP_RESPONSE
), unexpected_val
, return);
1092 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse___invoke
, 0, 0, 1)
1093 ZEND_ARG_INFO(0, ob_string
)
1094 ZEND_ARG_INFO(0, ob_flags
)
1095 ZEND_END_ARG_INFO();
1096 static PHP_METHOD(HttpEnvResponse
, __invoke
)
1100 zend_long ob_flags
= 0;
1102 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "s|l", &ob_str
, &ob_len
, &ob_flags
)) {
1103 php_http_message_object_t
*obj
= PHP_HTTP_OBJ(NULL
, getThis());
1105 PHP_HTTP_ENV_RESPONSE_OBJECT_INIT(obj
);
1107 php_http_message_object_init_body_object(obj
);
1108 php_http_message_body_append(obj
->message
->body
, ob_str
, ob_len
);
1113 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setEnvRequest
, 0, 0, 1)
1114 ZEND_ARG_OBJ_INFO(0, env_request
, http
\\Message
, 1)
1115 ZEND_END_ARG_INFO();
1116 static PHP_METHOD(HttpEnvResponse
, setEnvRequest
)
1118 zval
*env_req
= NULL
;
1120 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "|O", &env_req
, php_http_message_class_entry
), invalid_arg
, return);
1122 set_option(getThis(), ZEND_STRL("request"), IS_OBJECT
, env_req
, 0);
1123 RETVAL_ZVAL_FAST(getThis());
1126 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setContentType
, 0, 0, 1)
1127 ZEND_ARG_INFO(0, content_type
)
1128 ZEND_END_ARG_INFO();
1129 static PHP_METHOD(HttpEnvResponse
, setContentType
)
1131 char *ct_str
= NULL
;
1134 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "s!", &ct_str
, &ct_len
), invalid_arg
, return);
1136 set_option(getThis(), ZEND_STRL("contentType"), IS_STRING
, ct_str
, ct_len
);
1137 RETVAL_ZVAL_FAST(getThis());
1140 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setContentDisposition
, 0, 0, 1)
1141 ZEND_ARG_ARRAY_INFO(0, disposition_params
, 1)
1142 ZEND_END_ARG_INFO();
1143 static PHP_METHOD(HttpEnvResponse
, setContentDisposition
)
1147 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zdisposition
), invalid_arg
, return);
1149 zend_update_property(Z_OBJCE_P(getThis()), getThis(), ZEND_STRL("contentDisposition"), zdisposition
);
1150 RETVAL_ZVAL_FAST(getThis());
1153 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setContentEncoding
, 0, 0, 1)
1154 ZEND_ARG_INFO(0, content_encoding
)
1155 ZEND_END_ARG_INFO();
1156 static PHP_METHOD(HttpEnvResponse
, setContentEncoding
)
1160 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "l", &ce
), invalid_arg
, return);
1162 set_option(getThis(), ZEND_STRL("contentEncoding"), IS_LONG
, &ce
, 0);
1163 RETVAL_ZVAL_FAST(getThis());
1166 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setCacheControl
, 0, 0, 1)
1167 ZEND_ARG_INFO(0, cache_control
)
1168 ZEND_END_ARG_INFO();
1169 static PHP_METHOD(HttpEnvResponse
, setCacheControl
)
1171 char *cc_str
= NULL
;
1174 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "s!", &cc_str
, &cc_len
), invalid_arg
, return);
1176 set_option(getThis(), ZEND_STRL("cacheControl"), IS_STRING
, cc_str
, cc_len
);
1177 RETVAL_ZVAL_FAST(getThis());
1180 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setLastModified
, 0, 0, 1)
1181 ZEND_ARG_INFO(0, last_modified
)
1182 ZEND_END_ARG_INFO();
1183 static PHP_METHOD(HttpEnvResponse
, setLastModified
)
1185 zend_long last_modified
;
1187 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "l", &last_modified
), invalid_arg
, return);
1189 set_option(getThis(), ZEND_STRL("lastModified"), IS_LONG
, &last_modified
, 0);
1190 RETVAL_ZVAL_FAST(getThis());
1193 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_isCachedByLastModified
, 0, 0, 0)
1194 ZEND_ARG_INFO(0, header_name
)
1195 ZEND_END_ARG_INFO();
1196 static PHP_METHOD(HttpEnvResponse
, isCachedByLastModified
)
1198 char *header_name_str
= NULL
;
1199 size_t header_name_len
= 0;
1201 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "|s!", &header_name_str
, &header_name_len
)) {
1202 if (!header_name_str
|| !header_name_len
) {
1203 header_name_str
= "If-Modified-Since";
1204 header_name_len
= lenof("If-Modified-Since");
1207 RETURN_LONG(php_http_env_is_response_cached_by_last_modified(getThis(), header_name_str
, header_name_len
, get_request(getThis())));
1211 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setEtag
, 0, 0, 1)
1212 ZEND_ARG_INFO(0, etag
)
1213 ZEND_END_ARG_INFO();
1214 static PHP_METHOD(HttpEnvResponse
, setEtag
)
1216 char *etag_str
= NULL
;
1217 size_t etag_len
= 0;
1219 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "s!", &etag_str
, &etag_len
), invalid_arg
, return);
1221 set_option(getThis(), ZEND_STRL("etag"), IS_STRING
, etag_str
, etag_len
);
1222 RETVAL_ZVAL_FAST(getThis());
1225 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_isCachedByEtag
, 0, 0, 0)
1226 ZEND_ARG_INFO(0, header_name
)
1227 ZEND_END_ARG_INFO();
1228 static PHP_METHOD(HttpEnvResponse
, isCachedByEtag
)
1230 char *header_name_str
= NULL
;
1231 size_t header_name_len
= 0;
1233 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC
, "|s!", &header_name_str
, &header_name_len
)) {
1234 if (!header_name_str
|| !header_name_len
) {
1235 header_name_str
= "If-None-Match";
1236 header_name_len
= lenof("If-None-Match");
1238 RETURN_LONG(php_http_env_is_response_cached_by_etag(getThis(), header_name_str
, header_name_len
, get_request(getThis())));
1242 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setThrottleRate
, 0, 0, 1)
1243 ZEND_ARG_INFO(0, chunk_size
)
1244 ZEND_ARG_INFO(0, delay
)
1245 ZEND_END_ARG_INFO();
1246 static PHP_METHOD(HttpEnvResponse
, setThrottleRate
)
1248 zend_long chunk_size
;
1251 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "l|d", &chunk_size
, &delay
), invalid_arg
, return);
1253 set_option(getThis(), ZEND_STRL("throttleDelay"), IS_DOUBLE
, &delay
, 0);
1254 set_option(getThis(), ZEND_STRL("throttleChunk"), IS_LONG
, &chunk_size
, 0);
1255 RETVAL_ZVAL_FAST(getThis());
1258 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setCookie
, 0, 0, 1)
1259 ZEND_ARG_INFO(0, cookie
)
1260 ZEND_END_ARG_INFO();
1261 static PHP_METHOD(HttpEnvResponse
, setCookie
)
1263 zval
*zcookie_new
, tmp
;
1265 zend_error_handling zeh
;
1266 php_http_cookie_list_t
*list
= NULL
;
1268 php_http_expect(SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "z", &zcookie_new
), invalid_arg
, return);
1270 zend_replace_error_handling(EH_THROW
, php_http_exception_unexpected_val_class_entry
, &zeh
);
1271 switch (Z_TYPE_P(zcookie_new
)) {
1273 if (instanceof_function(Z_OBJCE_P(zcookie_new
), php_http_cookie_class_entry
)) {
1274 Z_ADDREF_P(zcookie_new
);
1279 list
= php_http_cookie_list_from_struct(NULL
, zcookie_new
);
1281 ZVAL_OBJ(zcookie_new
, &php_http_cookie_object_new_ex(php_http_cookie_class_entry
, list
)->zo
);
1285 zs
= zval_get_string(zcookie_new
);
1286 list
= php_http_cookie_list_parse(NULL
, zs
->val
, zs
->len
, 0, NULL
);
1288 ZVAL_OBJ(zcookie_new
, &php_http_cookie_object_new_ex(php_http_cookie_class_entry
, list
)->zo
);
1290 zend_restore_error_handling(&zeh
);
1292 set_cookie(getThis(), zcookie_new
);
1293 zval_ptr_dtor(zcookie_new
);
1295 RETVAL_ZVAL_FAST(getThis());
1298 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_send
, 0, 0, 0)
1299 ZEND_ARG_INFO(0, stream
)
1300 ZEND_END_ARG_INFO();
1301 static PHP_METHOD(HttpEnvResponse
, send
)
1303 zval
*zstream
= NULL
;
1304 php_stream
*s
= NULL
;
1306 if (SUCCESS
== zend_parse_parameters(ZEND_NUM_ARGS(), "|r", &zstream
)) {
1307 /* first flush the output layer to avoid conflicting headers and output;
1308 * also, ob_start($thisEnvResponse) might have been called */
1309 php_output_end_all();
1312 php_http_env_response_t
*r
;
1314 php_stream_from_zval(s
, zstream
);
1315 r
= php_http_env_response_init(NULL
, getThis(), php_http_env_response_get_stream_ops(), s
);
1320 RETVAL_BOOL(SUCCESS
== php_http_env_response_send(r
));
1321 php_http_env_response_free(&r
);
1323 php_http_env_response_t r
;
1325 if (!php_http_env_response_init(&r
, getThis(), NULL
, NULL
)) {
1329 RETVAL_BOOL(SUCCESS
== php_http_env_response_send(&r
));
1330 php_http_env_response_dtor(&r
);
1335 static zend_function_entry php_http_env_response_methods
[] = {
1336 PHP_ME(HttpEnvResponse
, __construct
, ai_HttpEnvResponse___construct
, ZEND_ACC_PUBLIC
|ZEND_ACC_CTOR
)
1337 PHP_ME(HttpEnvResponse
, __invoke
, ai_HttpEnvResponse___invoke
, ZEND_ACC_PUBLIC
)
1338 PHP_ME(HttpEnvResponse
, setEnvRequest
, ai_HttpEnvResponse_setEnvRequest
, ZEND_ACC_PUBLIC
)
1339 PHP_ME(HttpEnvResponse
, setCookie
, ai_HttpEnvResponse_setCookie
, ZEND_ACC_PUBLIC
)
1340 PHP_ME(HttpEnvResponse
, setContentType
, ai_HttpEnvResponse_setContentType
, ZEND_ACC_PUBLIC
)
1341 PHP_ME(HttpEnvResponse
, setContentDisposition
, ai_HttpEnvResponse_setContentDisposition
, ZEND_ACC_PUBLIC
)
1342 PHP_ME(HttpEnvResponse
, setContentEncoding
, ai_HttpEnvResponse_setContentEncoding
, ZEND_ACC_PUBLIC
)
1343 PHP_ME(HttpEnvResponse
, setCacheControl
, ai_HttpEnvResponse_setCacheControl
, ZEND_ACC_PUBLIC
)
1344 PHP_ME(HttpEnvResponse
, setLastModified
, ai_HttpEnvResponse_setLastModified
, ZEND_ACC_PUBLIC
)
1345 PHP_ME(HttpEnvResponse
, isCachedByLastModified
, ai_HttpEnvResponse_isCachedByLastModified
, ZEND_ACC_PUBLIC
)
1346 PHP_ME(HttpEnvResponse
, setEtag
, ai_HttpEnvResponse_setEtag
, ZEND_ACC_PUBLIC
)
1347 PHP_ME(HttpEnvResponse
, isCachedByEtag
, ai_HttpEnvResponse_isCachedByEtag
, ZEND_ACC_PUBLIC
)
1348 PHP_ME(HttpEnvResponse
, setThrottleRate
, ai_HttpEnvResponse_setThrottleRate
, ZEND_ACC_PUBLIC
)
1349 PHP_ME(HttpEnvResponse
, send
, ai_HttpEnvResponse_send
, ZEND_ACC_PUBLIC
)
1350 EMPTY_FUNCTION_ENTRY
1353 zend_class_entry
*php_http_env_response_class_entry
;
1355 PHP_MINIT_FUNCTION(http_env_response
)
1357 zend_class_entry ce
= {0};
1359 INIT_NS_CLASS_ENTRY(ce
, "http\\Env", "Response", php_http_env_response_methods
);
1360 php_http_env_response_class_entry
= zend_register_internal_class_ex(&ce
, php_http_message_class_entry
);
1362 zend_declare_class_constant_long(php_http_env_response_class_entry
, ZEND_STRL("CONTENT_ENCODING_NONE"), PHP_HTTP_CONTENT_ENCODING_NONE
);
1363 zend_declare_class_constant_long(php_http_env_response_class_entry
, ZEND_STRL("CONTENT_ENCODING_GZIP"), PHP_HTTP_CONTENT_ENCODING_GZIP
);
1365 zend_declare_class_constant_long(php_http_env_response_class_entry
, ZEND_STRL("CACHE_NO"), PHP_HTTP_CACHE_NO
);
1366 zend_declare_class_constant_long(php_http_env_response_class_entry
, ZEND_STRL("CACHE_HIT"), PHP_HTTP_CACHE_HIT
);
1367 zend_declare_class_constant_long(php_http_env_response_class_entry
, ZEND_STRL("CACHE_MISS"), PHP_HTTP_CACHE_MISS
);
1369 zend_declare_property_null(php_http_env_response_class_entry
, ZEND_STRL("request"), ZEND_ACC_PROTECTED
);
1370 zend_declare_property_null(php_http_env_response_class_entry
, ZEND_STRL("cookies"), ZEND_ACC_PROTECTED
);
1371 zend_declare_property_null(php_http_env_response_class_entry
, ZEND_STRL("contentType"), ZEND_ACC_PROTECTED
);
1372 zend_declare_property_null(php_http_env_response_class_entry
, ZEND_STRL("contentDisposition"), ZEND_ACC_PROTECTED
);
1373 zend_declare_property_null(php_http_env_response_class_entry
, ZEND_STRL("contentEncoding"), ZEND_ACC_PROTECTED
);
1374 zend_declare_property_null(php_http_env_response_class_entry
, ZEND_STRL("cacheControl"), ZEND_ACC_PROTECTED
);
1375 zend_declare_property_null(php_http_env_response_class_entry
, ZEND_STRL("etag"), ZEND_ACC_PROTECTED
);
1376 zend_declare_property_null(php_http_env_response_class_entry
, ZEND_STRL("lastModified"), ZEND_ACC_PROTECTED
);
1377 zend_declare_property_null(php_http_env_response_class_entry
, ZEND_STRL("throttleDelay"), ZEND_ACC_PROTECTED
);
1378 zend_declare_property_null(php_http_env_response_class_entry
, ZEND_STRL("throttleChunk"), ZEND_ACC_PROTECTED
);
1389 * vim600: noet sw=4 ts=4 fdm=marker
1390 * vim<600: noet sw=4 ts=4