Skip to content

Instantly share code, notes, and snippets.

@skaji
Last active February 21, 2021 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skaji/9bce98ff9a6e701bc9042a17ed6d9a19 to your computer and use it in GitHub Desktop.
Save skaji/9bce98ff9a6e701bc9042a17ed6d9a19 to your computer and use it in GitHub Desktop.

The following script test.pl downloads 02packages.details.txt.gz from cpan.metacpan.org 5 times with HTTP::Tiny->mirror.

#!/usr/bin/env perl
use strict;
use warnings;

use HTTP::Tiny;
use IO::Socket::SSL;

my $http = HTTP::Tiny->new;

my $url = "https://cpan.metacpan.org/modules/02packages.details.txt.gz";
# my $url = "https://www.cpan.org/modules/02packages.details.txt.gz";
my $file = "02packages.details.txt.gz";
unlink $file;

for my $times (1..5) {
    my $res = $http->mirror($url => $file);
    warn "$times: $res->{status} $res->{reason}";
}

I expect that the first download returns 200 OK, and the others return 304 Not Modified:

❯ perl test.pl
1: 200 OK at test.pl line 17.
2: 304 Not Modified at test.pl line 17.
3: 304 Not Modified at test.pl line 17.
4: 304 Not Modified at test.pl line 17.
5: 304 Not Modified at test.pl line 17.

But, actually it returns 200 OK several times:

❯ perl test.pl
1:  200 OK at test.pl line 17.
2:  304 Not Modified at test.pl line 17.
3:  200 OK at test.pl line 17.
4:  200 OK at test.pl line 17.
5:  200 OK at test.pl line 17.

Can you check cpan.metacpan.org or fastly setting?

Please note that if I change the url to www.cpan.org, it returns expected responses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment