From 8df9853e5908002ec334720a7311b2879ef3f271 Mon Sep 17 00:00:00 2001 From: guilherme silveira Date: Sat, 12 Dec 2009 17:07:58 -0200 Subject: [PATCH] media type support with charset --- lib/restfulie/media_type.rb | 1 + spec/media_type_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/lib/restfulie/media_type.rb b/lib/restfulie/media_type.rb index 60b880c2..aba6354b 100644 --- a/lib/restfulie/media_type.rb +++ b/lib/restfulie/media_type.rb @@ -50,6 +50,7 @@ def self.register(name, who) # TODO rename to type for mt def self.media_type(name) + name = name[/[^;]*/] raise UnsupportedContentType.new("unsupported content type '#{name}'") if media_types[name].nil? media_types[name] end diff --git a/spec/media_type_spec.rb b/spec/media_type_spec.rb index b6139b6d..df76bacc 100644 --- a/spec/media_type_spec.rb +++ b/spec/media_type_spec.rb @@ -11,6 +11,14 @@ class City end Restfulie::MediaType.media_type('vnd/caelum_city+xml').should eql(City) end + + it "should be able to locate with encoding" do + class City + extend Restfulie::MediaTypeControl + media_type 'vnd/caelum_city+xml' + end + Restfulie::MediaType.media_type('vnd/caelum_city+xml; charset=UTF-8').should eql(City) + end it "should throw an exception if not found" do lambda {Restfulie::MediaType.media_type('vnd/caelum_unknown_city+xml')}.should raise_error(Restfulie::UnsupportedContentType)