Browse files

Combine Unshorten into TwitPicThumb - Unshorten causing infinite loop.

  • Loading branch information...
1 parent 02e4068 commit 89f073d77a95a06c8b86ddff80c96afeabbfa711 @sjohnston committed Aug 28, 2011
Showing with 19 additions and 1 deletion.
  1. +19 −1 lib/Text/AutoLink/Plugin/TwitPicThumb.pm
View
20 lib/Text/AutoLink/Plugin/TwitPicThumb.pm
@@ -3,12 +3,15 @@ use strict;
use warnings;
use base qw(Text::AutoLink::Plugin::HTTP);
+use LWP::UserAgent ();
+my $ua = LWP::UserAgent->new;
+
sub linkfy
{
my $self = shift;
my %args = @_;
- my $url = $args{href};
+ my $url = $self->unshorten($args{href});
my ($id) = $url =~ /https?:\/\/twitpic.com\/([a-z0-9]+)/;
if ($id) {
$self->SUPER::linkfy(href => "http://twitpic.com/$id", img => "http://twitpic.com/show/thumb/$id");
@@ -18,6 +21,21 @@ sub linkfy
}
}
+sub unshorten
+{
+ my $self = shift;
+ my $url = shift;
+
+ my $request = HTTP::Request->new(HEAD => $url);
+ my $response = $ua->request($request);
+
+ if ($response->redirects) {
+ return $response->request->uri;
+ }
+
+ return $url;
+}
+
1;
=head1 NAME

0 comments on commit 89f073d

Please sign in to comment.