diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2021-01-24 12:30:27 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2021-01-24 12:30:41 -0700 |
commit | 5b02197c3b928beb7b2de297df05a299ff188765 (patch) | |
tree | 951395f805f1688e222291893d658d61f65ed711 | |
parent | 7c523ab1153bb8cc4b31378ebe0563ef9813bdab (diff) | |
download | mailscripts-5b02197c3b928beb7b2de297df05a299ff188765.tar.gz |
gmi2email: handle redirects
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
-rwxr-xr-x | gmi2email | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -182,8 +182,16 @@ sub gemini_fetch { ); print $cl "$uri\r\n"; - my ($status, $meta) = <$cl> =~ /^([0-9]+) (.+)/; - 20 <= $status and $status < 30 or die "gemini error: $status $meta"; + my ($status, $meta) = <$cl> =~ /^([0-9]+) (\V+)/; + if (30 <= $status and $status < 40) { + $opts{orig_uri} = $uri unless $opts{redirects}; + die "too many redirects while fetching $opts{orig_uri}" + if $opts{redirects} and $opts{redirects} > 5; + $opts{redirects}++; + return gemini_fetch($meta, %opts); + } elsif ($status < 20 or $status >= 40) { + die "gemini error: $status $meta"; + } if ($meta =~ "^text/gemini") { my @lines; |