diff --git a/lib/sawyer/response.rb b/lib/sawyer/response.rb index 684aca1..3a5ba80 100644 --- a/lib/sawyer/response.rb +++ b/lib/sawyer/response.rb @@ -24,7 +24,7 @@ def initialize(agent, res, options = {}) def data @data ||= begin - return(body) unless (headers[:content_type] =~ /json|msgpack/) + return(body) unless (headers[:content_type] =~ /json|msgpack/) process_data(agent.decode_body(body)) end end @@ -48,8 +48,12 @@ def process_data(data) # # Returns an array of Relations def process_rels - links = ( @headers["Link"] || "" ).split(', ').map do |link| - href, name = link.match(/<(.*?)>; rel="(\w+)"/).captures + links = ( @headers["Link"] || "" ).split(',').map do |link| + href, params = link.match(/<(.*?)>(.*)/).captures + name = nil + params.split(';').find do |param| + param.match(/rel="?(\w+)/) { |m| name = m[1] } + end [name.to_sym, Relation.from_link(@agent, name, :href => href)] end