only consider 2xx cacheable
[m6w6/ext-http] / php_http_env_response.c
index 0bcc21d9127ee025c2f7026b7fa7288bb28d495f..be7effa3eaf1b4859d447fbc9821171180a09e15 100644 (file)
@@ -229,8 +229,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)
 {
        TSRMLS_FETCH_FROM_CTX(r->ts);
+       long status = r->ops->get_status(r);
 
-       if (r->ops->get_status(r) >= 400) {
+       if (status && status / 100 != 2) {
                return 0;
        }
 
@@ -263,7 +264,7 @@ static size_t output(void *context, char *buf, size_t len TSRMLS_DC)
 }
 
 #define php_http_env_response_send_done(r) php_http_env_response_send_data((r), NULL, 0)
-static STATUS php_http_env_response_send_data(php_http_env_response_t *r, const char *buf, size_t len)
+static ZEND_RESULT_CODE php_http_env_response_send_data(php_http_env_response_t *r, const char *buf, size_t len)
 {
        size_t chunks_sent, chunk = r->throttle.chunk ? r->throttle.chunk : PHP_HTTP_SENDBUF_SIZE;
        TSRMLS_FETCH_FROM_CTX(r->ts);
@@ -351,9 +352,9 @@ void php_http_env_response_free(php_http_env_response_t **r)
        }
 }
 
-static STATUS php_http_env_response_send_head(php_http_env_response_t *r, php_http_message_t *request)
+static ZEND_RESULT_CODE php_http_env_response_send_head(php_http_env_response_t *r, php_http_message_t *request)
 {
-       STATUS ret = SUCCESS;
+       ZEND_RESULT_CODE ret = SUCCESS;
        zval *zoption, *options = r->options;
        TSRMLS_FETCH_FROM_CTX(r->ts);
 
@@ -608,9 +609,9 @@ static STATUS php_http_env_response_send_head(php_http_env_response_t *r, php_ht
        return ret;
 }
 
-static STATUS php_http_env_response_send_body(php_http_env_response_t *r)
+static ZEND_RESULT_CODE php_http_env_response_send_body(php_http_env_response_t *r)
 {
-       STATUS ret = SUCCESS;
+       ZEND_RESULT_CODE ret = SUCCESS;
        zval *zoption;
        php_http_message_body_t *body;
        TSRMLS_FETCH_FROM_CTX(r->ts);
@@ -696,7 +697,7 @@ static STATUS php_http_env_response_send_body(php_http_env_response_t *r)
        return ret;
 }
 
-STATUS php_http_env_response_send(php_http_env_response_t *r)
+ZEND_RESULT_CODE php_http_env_response_send(php_http_env_response_t *r)
 {
        php_http_message_t *request;
        php_http_message_body_t *body;
@@ -784,21 +785,21 @@ static long php_http_env_response_sapi_get_status(php_http_env_response_t *r)
 
        return php_http_env_get_response_code(TSRMLS_C);
 }
-static STATUS php_http_env_response_sapi_set_status(php_http_env_response_t *r, long http_code)
+static ZEND_RESULT_CODE php_http_env_response_sapi_set_status(php_http_env_response_t *r, long http_code)
 {
        TSRMLS_FETCH_FROM_CTX(r->ts);
 
        return php_http_env_set_response_code(http_code TSRMLS_CC);
 }
-static STATUS php_http_env_response_sapi_set_protocol_version(php_http_env_response_t *r, php_http_version_t *v)
+static ZEND_RESULT_CODE php_http_env_response_sapi_set_protocol_version(php_http_env_response_t *r, php_http_version_t *v)
 {
        TSRMLS_FETCH_FROM_CTX(r->ts);
 
        return php_http_env_set_response_protocol_version(v TSRMLS_CC);
 }
-static STATUS php_http_env_response_sapi_set_header(php_http_env_response_t *r, const char *fmt, ...)
+static ZEND_RESULT_CODE php_http_env_response_sapi_set_header(php_http_env_response_t *r, const char *fmt, ...)
 {
-       STATUS ret;
+       ZEND_RESULT_CODE ret;
        va_list args;
        TSRMLS_FETCH_FROM_CTX(r->ts);
 
@@ -808,9 +809,9 @@ static STATUS php_http_env_response_sapi_set_header(php_http_env_response_t *r,
 
        return ret;
 }
-static STATUS php_http_env_response_sapi_add_header(php_http_env_response_t *r, const char *fmt, ...)
+static ZEND_RESULT_CODE php_http_env_response_sapi_add_header(php_http_env_response_t *r, const char *fmt, ...)
 {
-       STATUS ret;
+       ZEND_RESULT_CODE ret;
        va_list args;
        TSRMLS_FETCH_FROM_CTX(r->ts);
 
@@ -820,13 +821,13 @@ static STATUS php_http_env_response_sapi_add_header(php_http_env_response_t *r,
 
        return ret;
 }
-static STATUS php_http_env_response_sapi_del_header(php_http_env_response_t *r, const char *header_str, size_t header_len)
+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)
 {
        TSRMLS_FETCH_FROM_CTX(r->ts);
 
        return php_http_env_set_response_header_value(0, header_str, header_len, NULL, 1 TSRMLS_CC);
 }
-static STATUS php_http_env_response_sapi_write(php_http_env_response_t *r, const char *data_str, size_t data_len)
+static ZEND_RESULT_CODE php_http_env_response_sapi_write(php_http_env_response_t *r, const char *data_str, size_t data_len)
 {
        TSRMLS_FETCH_FROM_CTX(r->ts);
 
@@ -835,7 +836,7 @@ static STATUS php_http_env_response_sapi_write(php_http_env_response_t *r, const
        }
        return FAILURE;
 }
-static STATUS php_http_env_response_sapi_flush(php_http_env_response_t *r)
+static ZEND_RESULT_CODE php_http_env_response_sapi_flush(php_http_env_response_t *r)
 {
        TSRMLS_FETCH_FROM_CTX(r->ts);
 
@@ -853,7 +854,7 @@ static STATUS php_http_env_response_sapi_flush(php_http_env_response_t *r)
 
        return SUCCESS;
 }
-static STATUS php_http_env_response_sapi_finish(php_http_env_response_t *r)
+static ZEND_RESULT_CODE php_http_env_response_sapi_finish(php_http_env_response_t *r)
 {
        return SUCCESS;
 }
@@ -891,7 +892,7 @@ typedef struct php_http_env_response_stream_ctx {
        unsigned chunked:1;
 } php_http_env_response_stream_ctx_t;
 
-static STATUS php_http_env_response_stream_init(php_http_env_response_t *r, void *init_arg)
+static ZEND_RESULT_CODE php_http_env_response_stream_init(php_http_env_response_t *r, void *init_arg)
 {
        php_http_env_response_stream_ctx_t *ctx;
        size_t buffer_size = 0x1000;
@@ -956,7 +957,7 @@ static void php_http_env_response_stream_header(php_http_env_response_stream_ctx
                }
        }
 }
-static STATUS php_http_env_response_stream_start(php_http_env_response_stream_ctx_t *ctx TSRMLS_DC)
+static ZEND_RESULT_CODE php_http_env_response_stream_start(php_http_env_response_stream_ctx_t *ctx TSRMLS_DC)
 {
        php_http_buffer_t header_buf;
 
@@ -1003,7 +1004,7 @@ static long php_http_env_response_stream_get_status(php_http_env_response_t *r)
 
        return ctx->status_code;
 }
-static STATUS php_http_env_response_stream_set_status(php_http_env_response_t *r, long http_code)
+static ZEND_RESULT_CODE php_http_env_response_stream_set_status(php_http_env_response_t *r, long http_code)
 {
        php_http_env_response_stream_ctx_t *stream_ctx = r->ctx;
 
@@ -1015,7 +1016,7 @@ static STATUS php_http_env_response_stream_set_status(php_http_env_response_t *r
 
        return SUCCESS;
 }
-static STATUS php_http_env_response_stream_set_protocol_version(php_http_env_response_t *r, php_http_version_t *v)
+static ZEND_RESULT_CODE php_http_env_response_stream_set_protocol_version(php_http_env_response_t *r, php_http_version_t *v)
 {
        php_http_env_response_stream_ctx_t *stream_ctx = r->ctx;
 
@@ -1027,7 +1028,7 @@ static STATUS php_http_env_response_stream_set_protocol_version(php_http_env_res
 
        return SUCCESS;
 }
-static STATUS php_http_env_response_stream_set_header_ex(php_http_env_response_t *r, zend_bool replace, const char *fmt, va_list argv)
+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)
 {
        php_http_env_response_stream_ctx_t *stream_ctx = r->ctx;
        char *header_end, *header_str = NULL;
@@ -1064,9 +1065,9 @@ static STATUS php_http_env_response_stream_set_header_ex(php_http_env_response_t
                return SUCCESS;
        }
 }
-static STATUS php_http_env_response_stream_set_header(php_http_env_response_t *r, const char *fmt, ...)
+static ZEND_RESULT_CODE php_http_env_response_stream_set_header(php_http_env_response_t *r, const char *fmt, ...)
 {
-       STATUS ret;
+       ZEND_RESULT_CODE ret;
        va_list argv;
 
        va_start(argv, fmt);
@@ -1075,9 +1076,9 @@ static STATUS php_http_env_response_stream_set_header(php_http_env_response_t *r
 
        return ret;
 }
-static STATUS php_http_env_response_stream_add_header(php_http_env_response_t *r, const char *fmt, ...)
+static ZEND_RESULT_CODE php_http_env_response_stream_add_header(php_http_env_response_t *r, const char *fmt, ...)
 {
-       STATUS ret;
+       ZEND_RESULT_CODE ret;
        va_list argv;
 
        va_start(argv, fmt);
@@ -1086,7 +1087,7 @@ static STATUS php_http_env_response_stream_add_header(php_http_env_response_t *r
 
        return ret;
 }
-static STATUS php_http_env_response_stream_del_header(php_http_env_response_t *r, const char *header_str, size_t header_len)
+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)
 {
        php_http_env_response_stream_ctx_t *stream_ctx = r->ctx;
 
@@ -1097,7 +1098,7 @@ static STATUS php_http_env_response_stream_del_header(php_http_env_response_t *r
        zend_hash_del(&stream_ctx->header, header_str, header_len + 1);
        return SUCCESS;
 }
-static STATUS php_http_env_response_stream_write(php_http_env_response_t *r, const char *data_str, size_t data_len)
+static ZEND_RESULT_CODE php_http_env_response_stream_write(php_http_env_response_t *r, const char *data_str, size_t data_len)
 {
        php_http_env_response_stream_ctx_t *stream_ctx = r->ctx;
        TSRMLS_FETCH_FROM_CTX(r->ts);
@@ -1117,7 +1118,7 @@ static STATUS php_http_env_response_stream_write(php_http_env_response_t *r, con
 
        return SUCCESS;
 }
-static STATUS php_http_env_response_stream_flush(php_http_env_response_t *r)
+static ZEND_RESULT_CODE php_http_env_response_stream_flush(php_http_env_response_t *r)
 {
        php_http_env_response_stream_ctx_t *stream_ctx = r->ctx;
        TSRMLS_FETCH_FROM_CTX(r->ts);
@@ -1133,7 +1134,7 @@ static STATUS php_http_env_response_stream_flush(php_http_env_response_t *r)
 
        return php_stream_flush(stream_ctx->stream);
 }
-static STATUS php_http_env_response_stream_finish(php_http_env_response_t *r)
+static ZEND_RESULT_CODE php_http_env_response_stream_finish(php_http_env_response_t *r)
 {
        php_http_env_response_stream_ctx_t *ctx = r->ctx;
        TSRMLS_FETCH_FROM_CTX(r->ts);