- send a content-length header if we send the full plain data
[m6w6/ext-http] / http_send_api.c
index 59b67d48155d6a26ec22bc941bf965e2f9e68c43..9f1105204fb34ae900ff041bda674f93e5f0ff6b 100644 (file)
@@ -152,10 +152,10 @@ static STATUS _http_send_chunk(const void *data, size_t begin, size_t end, http_
 PHP_HTTP_API STATUS _http_send_header_ex(const char *name, size_t name_len, const char *value, size_t value_len, zend_bool replace TSRMLS_DC)
 {
        STATUS ret;
-       size_t header_len = 1 + lenof(": ") + name_len + value_len;
-       char *header = emalloc(header_len);
+       size_t header_len = sizeof(": ") + name_len + value_len;
+       char *header = emalloc(header_len + 1);
 
-       header[header_len - 1] = '\0';
+       header[header_len] = '\0';
        snprintf(header, header_len, "%s: %s", name, value);
        ret = http_send_header_string_ex(header, replace);
        efree(header);
@@ -221,9 +221,6 @@ PHP_HTTP_API STATUS _http_send_etag(const char *etag, size_t etag_len TSRMLS_DC)
 /* {{{ STATUS http_send_content_type(char *, size_t) */
 PHP_HTTP_API STATUS _http_send_content_type(const char *content_type, size_t ct_len TSRMLS_DC)
 {
-       STATUS status;
-       char *ct_header;
-
        if (!strchr(content_type, '/')) {
                http_error_ex(HE_WARNING, HTTP_E_INVALID_PARAM, "Content-Type '%s' doesn't seem to consist of a primary and a secondary part", content_type);
                return FAILURE;
@@ -368,7 +365,8 @@ PHP_HTTP_API STATUS _http_send(const void *data_ptr, size_t data_size, http_send
        /* Range Request - only send ranges if entity hasn't changed */
        if (    range_status == RANGE_OK &&
                        http_match_etag_ex("HTTP_IF_MATCH", HTTP_G(send).unquoted_etag, 0) &&
-                       http_match_last_modified_ex("HTTP_IF_UNMODIFIED_SINCE", HTTP_G(send).last_modified, 0)) {
+                       http_match_last_modified_ex("HTTP_IF_UNMODIFIED_SINCE", HTTP_G(send).last_modified, 0) &&
+                       http_match_last_modified_ex("HTTP_UNLESS_MODIFIED_SINCE", HTTP_G(send).last_modified, 0)) {
                STATUS result = http_send_ranges(&ranges, data_ptr, data_size, data_mode);
                zend_hash_destroy(&ranges);
                return result;
@@ -396,6 +394,13 @@ PHP_HTTP_API STATUS _http_send(const void *data_ptr, size_t data_size, http_send
                return http_cache_exit_ex(http_date(HTTP_G(send).last_modified), 0, 1);
        }
 
+       /* emit a content-length header */
+       if (!php_ob_handler_used("ob_gzhandler" TSRMLS_CC)) {
+               char *cl;
+               spprintf(&cl, 0, "Content-Length: %lu", (unsigned long) data_size);
+               http_send_header_string(cl);
+               efree(cl);
+       }
        /* send full entity */
        return http_send_chunk(data_ptr, 0, data_size, data_mode);
 }