etag test & fixes; set default etag mode for temp streams to crc32(b)
[m6w6/ext-http] / php_http_message_body.c
index 8faf0a4d5bb21a622952aeab51bc9a009ee3149e..7019de30e763498b2e946ffd5df3ee00d80920bf 100644 (file)
@@ -123,8 +123,12 @@ PHP_HTTP_API char *php_http_message_body_etag(php_http_message_body_t *body)
        } else {
                php_http_etag_t *etag = php_http_etag_init(PHP_HTTP_G->env.etag_mode TSRMLS_CC);
 
-               php_http_message_body_to_callback(body, (php_http_pass_callback_t) php_http_etag_update, etag, 0, 0);
-               return php_http_etag_finish(etag);
+               if (etag) {
+                       php_http_message_body_to_callback(body, (php_http_pass_callback_t) php_http_etag_update, etag, 0, 0);
+                       return php_http_etag_finish(etag);
+               } else {
+                       return NULL;
+               }
        }
 }
 
@@ -251,8 +255,6 @@ PHP_HTTP_API STATUS php_http_message_body_add_field(php_http_message_body_t *bod
 
 PHP_HTTP_API STATUS php_http_message_body_add_file(php_http_message_body_t *body, const char *name, const char *ctype, const char *path, php_stream *in)
 {
-       php_stream_statbuf ssb = {{0}};
-       php_stream_filter *tef = NULL;
        char *safe_name, *path_dup = estrdup(path);
        TSRMLS_FETCH_FROM_CTX(body->ts);
 
@@ -262,38 +264,14 @@ PHP_HTTP_API STATUS php_http_message_body_add_file(php_http_message_body_t *body
        php_http_message_body_appendf(
                body,
                "Content-Disposition: attachment; name=\"%s\"; filename=\"%s\"" PHP_HTTP_CRLF
-               "Content-Type: %s" PHP_HTTP_CRLF,
+               "Content-Transfer-Encoding: binary" PHP_HTTP_CRLF
+               "Content-Type: %s" PHP_HTTP_CRLF
+               PHP_HTTP_CRLF,
                safe_name, basename(path_dup), ctype
        );
-
-       if (SUCCESS == php_stream_stat(in, &ssb)) {
-               php_http_message_body_appendf(
-                       body,
-                       "Content-Length: %zu" PHP_HTTP_CRLF
-                       "" PHP_HTTP_CRLF,
-                       ssb.sb.st_size
-               );
-       } else {
-               php_http_message_body_append(
-                       body,
-                       ZEND_STRL(
-                               "Transfer-Encoding: chunked" PHP_HTTP_CRLF
-                               "" PHP_HTTP_CRLF
-                       )
-               );
-
-               if ((tef = php_http_filter_factory.create_filter("http.chunked_encode", NULL, 0 TSRMLS_CC))) {
-                       php_stream_filter_append(&in->readfilters, tef);
-               }
-       }
-
        php_stream_copy_to_stream_ex(in, php_http_message_body_stream(body), PHP_STREAM_COPY_ALL, NULL);
        BOUNDARY_CLOSE(body);
 
-       if (tef) {
-               php_stream_filter_remove(tef, 1 TSRMLS_CC);
-       }
-
        efree(safe_name);
        efree(path_dup);
 
@@ -312,7 +290,7 @@ static inline char *format_key(uint type, char *str, ulong num, const char *pref
        } else if (type == HASH_KEY_IS_STRING) {
                new_key = estrdup(str);
        } else {
-               estrdup("");
+               new_key = estrdup("");
        }
 
        return new_key;