Created
August 1, 2014 22:16
-
-
Save anonymous/cb6a2910ec41624ae2aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/Mojo/Message.pm b/lib/Mojo/Message.pm | |
index 0d7a4c3..841296b 100644 | |
--- a/lib/Mojo/Message.pm | |
+++ b/lib/Mojo/Message.pm | |
@@ -9,7 +9,7 @@ use Mojo::JSON 'j'; | |
use Mojo::JSON::Pointer; | |
use Mojo::Parameters; | |
use Mojo::Upload; | |
-use Mojo::Util 'decode'; | |
+use Mojo::Util qw(decode split_header); | |
has content => sub { Mojo::Content::Single->new }; | |
has default_charset => 'UTF-8'; | |
@@ -139,6 +139,19 @@ sub json { | |
return $pointer ? Mojo::JSON::Pointer->new($data)->get($pointer) : $data; | |
} | |
+sub links { | |
+ my $self = shift; | |
+ | |
+ my $links = {}; | |
+ for my $link (@{split_header $self->headers->link // ''}) { | |
+ my $target = defined $link->[1] ? join '=', @$link[0,1] : $link->[0]; | |
+ next unless $target =~ /^<(.+)>$/ && (my $rel = {@$link}->{rel}); | |
+ $links->{$rel} = $1; | |
+ } | |
+ | |
+ return $links; | |
+} | |
+ | |
sub param { shift->body_params->param(@_) } | |
sub parse { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment