fix env response
authorMichael Wallner <mike@php.net>
Wed, 21 Jan 2015 22:28:50 +0000 (23:28 +0100)
committerMichael Wallner <mike@php.net>
Wed, 21 Jan 2015 22:28:50 +0000 (23:28 +0100)
php_http_env.c
php_http_env_response.c
tests/envresponse004.phpt

index 632562c38a91dc0d1cff50e613824e7d44c27c9b..1e34fd10674d455e62317248d224cb8376e7a7a9 100644 (file)
@@ -415,6 +415,9 @@ static void grab_header(void *data, void *arg)
        && !strncmp(header->header, args->name_str, args->name_len)
        ) {
                args->value_ptr = &header->header[args->name_len + 1];
+               while (PHP_HTTP_IS_CTYPE(space, *args->value_ptr)) {
+                       ++args->value_ptr;
+               }
        }
 }
 
@@ -777,15 +780,15 @@ ZEND_END_ARG_INFO();
 static PHP_METHOD(HttpEnv, setResponseHeader)
 {
        char *header_name_str;
-       int header_name_len;
+       size_t header_name_len;
        zval *header_value = NULL;
-       long code = 0;
+       zend_long code = 0;
        zend_bool replace_header = 1;
 
        if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "s|z!lb", &header_name_str, &header_name_len, &header_value, &code, &replace_header)) {
                return;
        }
-       RETURN_BOOL(SUCCESS == php_http_env_set_response_header_value(code, header_name_str, header_name_len, header_value, replace_header TSRMLS_CC));
+       RETURN_BOOL(SUCCESS == php_http_env_set_response_header_value(code, header_name_str, header_name_len, header_value, replace_header));
 }
 
 ZEND_BEGIN_ARG_INFO_EX(ai_HttpEnv_setResponseCode, 0, 0, 1)
index 08993bd4be15d09d688ce54f0e02471436b9db37..0b195b6a7abdc7545e06931233916449bb48592f 100644 (file)
@@ -148,7 +148,7 @@ php_http_cache_status_t php_http_env_is_response_cached_by_etag(zval *options, c
                return ret;
        }
 
-       if ((zetag = get_option(options, ZEND_STRL("etag")))) {
+       if ((zetag = get_option(options, ZEND_STRL("etag"))) && Z_TYPE_P(zetag) != IS_NULL) {
                zend_string *zs = zval_get_string(zetag);
                etag = estrndup(zs->val, zs->len);
                zend_string_release(zs);
@@ -458,23 +458,19 @@ static ZEND_RESULT_CODE php_http_env_response_send_head(php_http_env_response_t
                }
 
                if ((zoption = get_option(options, ZEND_STRL("contentDisposition")))) {
-                       php_http_buffer_t buf;
 
-                       if (Z_TYPE_P(zoption) != IS_ARRAY) {
-                               zval *tmp = zoption;
-                               SEPARATE_ZVAL(tmp);
-                               convert_to_array(tmp);
-                               zoption = tmp;
-                       }
+                       if (Z_TYPE_P(zoption) == IS_ARRAY) {
+                               php_http_buffer_t buf;
 
-                       php_http_buffer_init(&buf);
-                       if (php_http_params_to_string(&buf, Z_ARRVAL_P(zoption), ZEND_STRL(","), ZEND_STRL(";"), ZEND_STRL("="), PHP_HTTP_PARAMS_DEFAULT)) {
-                               if (buf.used) {
-                                       ret = r->ops->set_header(r, "Content-Disposition: %.*s", buf.used, buf.data);
+                               php_http_buffer_init(&buf);
+                               if (php_http_params_to_string(&buf, Z_ARRVAL_P(zoption), ZEND_STRL(","), ZEND_STRL(";"), ZEND_STRL("="), PHP_HTTP_PARAMS_DEFAULT)) {
+                                       if (buf.used) {
+                                               ret = r->ops->set_header(r, "Content-Disposition: %.*s", buf.used, buf.data);
+                                       }
                                }
-                       }
 
-                       php_http_buffer_dtor(&buf);
+                               php_http_buffer_dtor(&buf);
+                       }
                        zval_ptr_dtor(zoption);
                }
 
@@ -934,6 +930,8 @@ static ZEND_RESULT_CODE php_http_env_response_stream_set_header_ex(php_http_env_
        char *header_end, *header_str = NULL;
        size_t header_len = 0;
        zval zheader, *zheader_ptr;
+       zend_string *header_key;
+       ZEND_RESULT_CODE rv;
 
        if (stream_ctx->started || stream_ctx->finished) {
                return FAILURE;
@@ -946,22 +944,21 @@ static ZEND_RESULT_CODE php_http_env_response_stream_set_header_ex(php_http_env_
                return FAILURE;
        }
 
-       *header_end = '\0';
+       header_key = zend_string_init(header_str, header_end - header_str, 0);
 
-       if (!replace && (zheader_ptr = zend_hash_str_find(&stream_ctx->header, header_str, header_end - header_str))) {
+       if (!replace && (zheader_ptr = zend_hash_find(&stream_ctx->header, header_key))) {
                convert_to_array(zheader_ptr);
-               *header_end = ':';
-               return add_next_index_str(zheader_ptr, php_http_cs2zs(header_str, header_len));
+               rv = add_next_index_str(zheader_ptr, php_http_cs2zs(header_str, header_len));
        } else {
                ZVAL_STR(&zheader, php_http_cs2zs(header_str, header_len));
 
-               if (SUCCESS != zend_hash_str_update(&stream_ctx->header, header_str, header_end - header_str, &zheader)) {
-                       return FAILURE;
-               }
-
-               *header_end = ':';
-               return SUCCESS;
+               rv = zend_hash_update(&stream_ctx->header, header_key, &zheader)
+                       ? SUCCESS : FAILURE;
        }
+
+       zend_string_release(header_key);
+
+       return rv;
 }
 static ZEND_RESULT_CODE php_http_env_response_stream_set_header(php_http_env_response_t *r, const char *fmt, ...)
 {
@@ -1282,6 +1279,7 @@ static PHP_METHOD(HttpEnvResponse, setCookie)
        default:
                zs = zval_get_string(zcookie_new);
                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);
        }
index deee3f2081b8d397fafb4a6a77259d46fb276862..da5801d06ac3f8bcfea5674cea1fe9f6ab4ca73d 100644 (file)
@@ -20,6 +20,7 @@ echo "bar";
 
 ob_end_flush();
 $r->send();
+?>
 --EXPECTHEADERS--
 Accept-Ranges: bytes
 Cache-Control: public,must-revalidate,max-age=0