Skip to content

HTTP header are not case insensitive #14339

@Findus23

Description

@Findus23

I am currently setting up a test-instance for my workshop and I try to be pedantic and not skip over potential bugs when doing so.

Currently I am really confused by the GeoIP downloader (I think I saw the same bug for the initial download on my real instance, but the updater works):

When I try to initially download the free geoip2 database, I just get the generic General_DownloadFail_HttpRequestFail error.

Adding a print_r($expectedFileSizeResult); shows the source of the issue:

matomo/core/Http.php

Lines 737 to 745 in 07adf0a

$expectedFileSize = 0;
if (isset($expectedFileSizeResult['headers']['Content-Length'])) {
$expectedFileSize = (int)$expectedFileSizeResult['headers']['Content-Length'];
}
if ($expectedFileSize == 0) {
Log::info("HEAD request for '%s' failed, got following: %s", $url, print_r($expectedFileSizeResult, true));
throw new Exception(Piwik::translate('General_DownloadFail_HttpRequestFail'));
}

Array
(
    [status] => 200
    [headers] => Array
        (
            [date] => Thu, 11 Apr 2019 16:29:34 GMT
            [content-type] => application/gzip
            [content-length] => 29444833
            [set-cookie] => __cfduid=d5e7c2e5b339a937a45385e60f1a69d7c1555000174; expires=Fri, 10-Apr-20 16:29:34 GMT; path=/; domain=.geolite.maxmind.com; HttpOnly
            [content-disposition] => attachment; filename=GeoLite2-City_20190409.tar.gz
            [last-modified] => Mon, 08 Apr 2019 12:07:23 GMT
            [cf-cache-status] => HIT
            [expires] => Thu, 11 Apr 2019 20:29:34 GMT
            [cache-control] => public, max-age=14400
            [accept-ranges] => bytes
            [expect-ct] => max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
            [server] => cloudflare
            [cf-ray] => 4c5e57111a0dbef8-FRA
        )

    [data] => 
)

Cloudflare only returns lowercase HTTP headers, but Matomo only checks for 'Content-Length' and therefore the download fails.

Interestingly fixing this, the download still doesn't work as I just get an unhelpful Failed sending HTTP request here:

matomo/core/Http.php

Lines 581 to 586 in 07adf0a

} elseif ($response === false) {
$errstr = curl_error($ch);
if ($errstr != '') {
throw new Exception('curl_exec: ' . $errstr
. '. Hostname requested was: ' . UrlHelper::getHostFromUrl($aUrl));
}

I'm also a bit clueless why I am the first one to come across this issue. Am I missing something?

Metadata

Metadata

Assignees

Labels

EnhancementFor new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc.not-in-changelogFor issues or pull requests that should not be included in our release changelog on matomo.org.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions