Skip to content

Commit

Permalink
Generalize 'Link' header parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
ivailop committed Feb 16, 2021
1 parent 7d57eda commit 7fef469
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/sawyer/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,13 @@ 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(';').map do |param|
param.match(/rel="?(\w+)/) { |m| name = m[1] }
break if name
end

[name.to_sym, Relation.from_link(@agent, name, :href => href)]
end
Expand Down

0 comments on commit 7fef469

Please sign in to comment.