Skip to content

Commit

Permalink
Generalize 'Link' header parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
ivailop authored Feb 16, 2021
1 parent 7d57eda commit 6174114
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/sawyer/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,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
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 6174114

Please sign in to comment.