Rather than just creating a handler for the base mime-type (e.g. "text/yaml") we
create some synonyms where appropriate (e.g. "text/x-yaml", "application/yaml",
etc.)

Signed-off-by: Markus Roberts <[email protected]>
---
 lib/puppet/network/format_handler.rb |    6 ++++++
 lib/puppet/network/formats.rb        |    8 ++++----
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/lib/puppet/network/format_handler.rb 
b/lib/puppet/network/format_handler.rb
index d378ad6..b94a4f9 100644
--- a/lib/puppet/network/format_handler.rb
+++ b/lib/puppet/network/format_handler.rb
@@ -37,6 +37,12 @@ module Puppet::Network::FormatHandler
     instance
   end
 
+  def self.create_serialized_formats(name,options = {},&block)
+    ["application/x-#{name}", "application/#{name}", "text/x-#{name}", 
"text/#{name}"].each { |mime_type|
+      create name, {:mime => mime_type}.update(options), &block
+    }
+  end
+
   def self.extended(klass)
     klass.extend(ClassMethods)
 
diff --git a/lib/puppet/network/formats.rb b/lib/puppet/network/formats.rb
index 8a61ee6..4ca3240 100644
--- a/lib/puppet/network/formats.rb
+++ b/lib/puppet/network/formats.rb
@@ -1,6 +1,6 @@
 require 'puppet/network/format_handler'
 
-Puppet::Network::FormatHandler.create(:yaml, :mime => "text/yaml") do
+Puppet::Network::FormatHandler.create_serialized_formats(:yaml) do
   # Yaml doesn't need the class name; it's serialized.
   def intern(klass, text)
     YAML.load(text)
@@ -29,7 +29,7 @@ end
 # This is a "special" format which is used for the moment only when sending 
facts
 # as REST GET parameters (see Puppet::Configurer::FactHandler).
 # This format combines a yaml serialization, then zlib compression and base64 
encoding.
-Puppet::Network::FormatHandler.create(:b64_zlib_yaml, :mime => 
"text/b64_zlib_yaml") do
+Puppet::Network::FormatHandler.create_serialized_formats(:b64_zlib_yaml) do
   require 'base64'
 
   def use_zlib?
@@ -127,7 +127,7 @@ Puppet::Network::FormatHandler.create(:raw, :mime => 
"application/x-raw", :weigh
   end
 end
 
-Puppet::Network::FormatHandler.create(:pson, :mime => "text/pson", :weight => 
10, :required_methods => [:render_method, :intern_method]) do
+Puppet::Network::FormatHandler.create_serialized_formats(:pson, :weight => 10, 
:required_methods => [:render_method, :intern_method]) do
   confine :true => Puppet.features.pson?
 
   def intern(klass, text)
@@ -159,4 +159,4 @@ Puppet::Network::FormatHandler.create(:pson, :mime => 
"text/pson", :weight => 10
 end
 
 # This is really only ever going to be used for Catalogs.
-Puppet::Network::FormatHandler.create(:dot, :mime => "text/dot", 
:required_methods => [:render_method])
+Puppet::Network::FormatHandler.create_serialized_formats(:dot, 
:required_methods => [:render_method])
-- 
1.7.0.4

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en.

Reply via email to