X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=php_http_env_response.c;h=9bc3f5bc394e743f3759dd0ee0da869b893266c1;hp=5b4682084278d460c6672caafa745177fd289c9a;hb=8840a33028d28fa4f351b08b7502c1642c758af5;hpb=95c6c900d04096d332c422e3f597186b7184c5ab diff --git a/php_http_env_response.c b/php_http_env_response.c index 5b46820..9bc3f5b 100644 --- a/php_http_env_response.c +++ b/php_http_env_response.c @@ -207,7 +207,9 @@ php_http_cache_status_t php_http_env_is_response_cached_by_last_modified(zval *o static zend_bool php_http_env_response_is_cacheable(php_http_env_response_t *r, php_http_message_t *request) { - if (r->ops->get_status(r) >= 400) { + long status = r->ops->get_status(r); + + if (status && status / 100 != 2) { return 0; } @@ -1094,7 +1096,7 @@ static ZEND_RESULT_CODE php_http_env_response_stream_finish(php_http_env_respons 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->chunked_filter = php_stream_filter_remove(ctx->chunked_filter, 1); } ctx->finished = 1; @@ -1156,8 +1158,15 @@ static PHP_METHOD(HttpEnvResponse, __invoke) 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 (!obj->body) { + php_http_message_object_init_body_object(obj); + } + + if (ob_flags & PHP_OUTPUT_HANDLER_CLEAN) { + php_stream_truncate_set_size(php_http_message_body_stream(obj->message->body), 0); + } else { + php_http_message_body_append(obj->message->body, ob_str, ob_len); + } RETURN_TRUE; } } @@ -1172,7 +1181,7 @@ static PHP_METHOD(HttpEnvResponse, setEnvRequest) php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|O", &env_req, php_http_message_class_entry), invalid_arg, return); set_option(getThis(), ZEND_STRL("request"), IS_OBJECT, env_req, 0); - RETVAL_ZVAL_FAST(getThis()); + RETVAL_ZVAL(getThis(), 1, 0); } ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setContentType, 0, 0, 1) @@ -1186,7 +1195,7 @@ static PHP_METHOD(HttpEnvResponse, setContentType) php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s!", &ct_str, &ct_len), invalid_arg, return); set_option(getThis(), ZEND_STRL("contentType"), IS_STRING, ct_str, ct_len); - RETVAL_ZVAL_FAST(getThis()); + RETVAL_ZVAL(getThis(), 1, 0); } ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setContentDisposition, 0, 0, 1) @@ -1199,7 +1208,7 @@ static PHP_METHOD(HttpEnvResponse, setContentDisposition) php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "a", &zdisposition), invalid_arg, return); zend_update_property(Z_OBJCE_P(getThis()), getThis(), ZEND_STRL("contentDisposition"), zdisposition); - RETVAL_ZVAL_FAST(getThis()); + RETVAL_ZVAL(getThis(), 1, 0); } ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setContentEncoding, 0, 0, 1) @@ -1212,7 +1221,7 @@ static PHP_METHOD(HttpEnvResponse, setContentEncoding) php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "l", &ce), invalid_arg, return); set_option(getThis(), ZEND_STRL("contentEncoding"), IS_LONG, &ce, 0); - RETVAL_ZVAL_FAST(getThis()); + RETVAL_ZVAL(getThis(), 1, 0); } ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setCacheControl, 0, 0, 1) @@ -1226,7 +1235,7 @@ static PHP_METHOD(HttpEnvResponse, setCacheControl) php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s!", &cc_str, &cc_len), invalid_arg, return); set_option(getThis(), ZEND_STRL("cacheControl"), IS_STRING, cc_str, cc_len); - RETVAL_ZVAL_FAST(getThis()); + RETVAL_ZVAL(getThis(), 1, 0); } ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setLastModified, 0, 0, 1) @@ -1239,7 +1248,7 @@ static PHP_METHOD(HttpEnvResponse, setLastModified) php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "l", &last_modified), invalid_arg, return); set_option(getThis(), ZEND_STRL("lastModified"), IS_LONG, &last_modified, 0); - RETVAL_ZVAL_FAST(getThis()); + RETVAL_ZVAL(getThis(), 1, 0); } ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_isCachedByLastModified, 0, 0, 0) @@ -1271,7 +1280,7 @@ static PHP_METHOD(HttpEnvResponse, setEtag) php_http_expect(SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "s!", &etag_str, &etag_len), invalid_arg, return); set_option(getThis(), ZEND_STRL("etag"), IS_STRING, etag_str, etag_len); - RETVAL_ZVAL_FAST(getThis()); + RETVAL_ZVAL(getThis(), 1, 0); } ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_isCachedByEtag, 0, 0, 0) @@ -1282,7 +1291,7 @@ static PHP_METHOD(HttpEnvResponse, isCachedByEtag) char *header_name_str = NULL; size_t header_name_len = 0; - if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|s!", &header_name_str, &header_name_len)) { + if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS(), "|s!", &header_name_str, &header_name_len)) { if (!header_name_str || !header_name_len) { header_name_str = "If-None-Match"; header_name_len = lenof("If-None-Match"); @@ -1304,7 +1313,7 @@ static PHP_METHOD(HttpEnvResponse, setThrottleRate) set_option(getThis(), ZEND_STRL("throttleDelay"), IS_DOUBLE, &delay, 0); set_option(getThis(), ZEND_STRL("throttleChunk"), IS_LONG, &chunk_size, 0); - RETVAL_ZVAL_FAST(getThis()); + RETVAL_ZVAL(getThis(), 1, 0); } ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_setCookie, 0, 0, 1) @@ -1330,7 +1339,7 @@ static PHP_METHOD(HttpEnvResponse, setCookie) case IS_ARRAY: list = php_http_cookie_list_from_struct(NULL, zcookie_new); zcookie_new = &tmp; - ZVAL_OBJECT(zcookie_new, &php_http_cookie_object_new_ex(php_http_cookie_class_entry, list)->zo, 1); + ZVAL_OBJECT(zcookie_new, &php_http_cookie_object_new_ex(php_http_cookie_class_entry, list)->zo, 0); break; default: @@ -1338,14 +1347,14 @@ static PHP_METHOD(HttpEnvResponse, setCookie) list = php_http_cookie_list_parse(NULL, zs->val, zs->len, 0, NULL); zend_string_release(zs); zcookie_new = &tmp; - ZVAL_OBJECT(zcookie_new, &php_http_cookie_object_new_ex(php_http_cookie_class_entry, list)->zo, 1); + ZVAL_OBJECT(zcookie_new, &php_http_cookie_object_new_ex(php_http_cookie_class_entry, list)->zo, 0); } zend_restore_error_handling(&zeh); set_cookie(getThis(), zcookie_new); zval_ptr_dtor(zcookie_new); - RETVAL_ZVAL_FAST(getThis()); + RETVAL_ZVAL(getThis(), 1, 0); } ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnvResponse_send, 0, 0, 0)