mirror of
https://github.com/rest-client/rest-client.git
synced 2022-11-09 13:49:40 -05:00
beautify headers (:content_type => 'text/html')
This commit is contained in:
parent
7d0161d7ec
commit
92a25a7a10
2 changed files with 20 additions and 3 deletions
|
@ -270,7 +270,14 @@ module RestClient
|
|||
end
|
||||
|
||||
def headers
|
||||
@headers ||= @net_http_res.to_hash
|
||||
@headers ||= self.class.beautify_headers(@net_http_res.to_hash)
|
||||
end
|
||||
|
||||
def self.beautify_headers(headers)
|
||||
headers.inject({}) do |out, (key, value)|
|
||||
out[key.gsub(/-/, '_').to_sym] = value.first
|
||||
out
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -356,9 +356,19 @@ describe RestClient do
|
|||
@response.code.should == 200
|
||||
end
|
||||
|
||||
it "beautifies the headers by turning the keys to symbols" do
|
||||
h = RestClient::Response.beautify_headers('content-type' => [ 'x' ])
|
||||
h.keys.first.should == :content_type
|
||||
end
|
||||
|
||||
it "beautifies the headers by turning the values to strings instead of one-element arrays" do
|
||||
h = RestClient::Response.beautify_headers('x' => [ 'text/html' ] )
|
||||
h.values.first.should == 'text/html'
|
||||
end
|
||||
|
||||
it "fetches the headers" do
|
||||
@net_http_res.should_receive(:to_hash).and_return('a' => ['b'])
|
||||
@response.headers['a'].should == ['b']
|
||||
@net_http_res.should_receive(:to_hash).and_return('content-type' => [ 'text/html' ])
|
||||
@response.headers.should == { :content_type => 'text/html' }
|
||||
end
|
||||
|
||||
it "can access the net http result directly" do
|
||||
|
|
Loading…
Reference in a new issue