Skip to content

Commit

Permalink
Fixes YAML serialization/deserialization for Faraday::Utils::Headers
Browse files Browse the repository at this point in the history
Fixes #690
  • Loading branch information
iMacTia committed Jul 11, 2017
1 parent 375ea71 commit e609e69
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
18 changes: 10 additions & 8 deletions lib/faraday/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,22 @@ def self.from(value)
new(value)
end

def self.allocate
new_self = super
new_self.initialize_names
new_self
end

def initialize(hash = nil)
super()
@names = {}
self.update(hash || {})
end

def initialize_names
@names = {}
end

# on dup/clone, we need to duplicate @names hash
def initialize_copy(other)
super
Expand Down Expand Up @@ -115,14 +125,6 @@ def parse(header_string)
}
end

def init_with(coder)
@names = coder['names']
end

def encode_with(coder)
coder['names'] = @names
end

protected

def names
Expand Down
2 changes: 2 additions & 0 deletions test/utils_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ def test_headers_yaml_roundtrip

assert result.include?('user-agent'), 'Unable to hydrate to a correct Headers'
assert result.include?('content-type'), 'Unable to hydrate to a correct Headers'
assert result['user-agent'] == 'safari', 'Unable to access rehydrated Headers'
assert result['content-type'] == 'text/html', 'Unable to access rehydrated Headers'
end
end

0 comments on commit e609e69

Please sign in to comment.