Carry #579: Faraday::Utils::Headers YAML can be serialized (#634)

* Bootstrap method that fixes deserializing with YAML

* YAML encoding of Header

* Utils.rb: Avoid relying on the #names method
This commit is contained in:
Olle Jonsson 2016-11-23 11:55:24 +01:00 committed by Mattia
parent 347d15b2ec
commit 0f17254d4a
2 changed files with 18 additions and 0 deletions

View File

@ -108,6 +108,14 @@ module Faraday
} }
end end
def init_with(coder)
@names = coder['names']
end
def encode_with(coder)
coder['names'] = @names
end
protected protected
def names def names

View File

@ -63,5 +63,15 @@ class TestUtils < Faraday::TestCase
Faraday::Utils.default_uri_parser = old_parser Faraday::Utils.default_uri_parser = old_parser
end end
end end
# YAML parsing
def test_headers_yaml_roundtrip
headers = Faraday::Utils::Headers.new('User-Agent' => 'safari', 'Content-type' => 'text/html')
result = YAML.load(headers.to_yaml)
assert result.include?('user-agent'), 'Unable to hydrate to a correct Headers'
assert result.include?('content-type'), 'Unable to hydrate to a correct Headers'
end
end end