deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mar...@apache.org
Subject [2/2] git commit: CIMI - strictly enforce only xml or json as content-type for message bodies
Date Tue, 11 Dec 2012 14:31:50 GMT
CIMI - strictly enforce only xml or json as content-type for message bodies


Project: http://git-wip-us.apache.org/repos/asf/deltacloud/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltacloud/commit/ab1f43c8
Tree: http://git-wip-us.apache.org/repos/asf/deltacloud/tree/ab1f43c8
Diff: http://git-wip-us.apache.org/repos/asf/deltacloud/diff/ab1f43c8

Branch: refs/heads/master
Commit: ab1f43c8ed7c58a7a2d308841667e5c013c6ebc5
Parents: a6626df
Author: marios <marios@redhat.com>
Authored: Wed Dec 5 15:26:20 2012 +0200
Committer: marios <marios@redhat.com>
Committed: Tue Dec 11 16:30:44 2012 +0200

----------------------------------------------------------------------
 server/lib/cimi/helpers/cimi_helper.rb |    9 ++++++---
 server/lib/cimi/models/errors.rb       |    8 ++++++++
 2 files changed, 14 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/ab1f43c8/server/lib/cimi/helpers/cimi_helper.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/helpers/cimi_helper.rb b/server/lib/cimi/helpers/cimi_helper.rb
index 713aeab..8fad786 100644
--- a/server/lib/cimi/helpers/cimi_helper.rb
+++ b/server/lib/cimi/helpers/cimi_helper.rb
@@ -61,12 +61,15 @@ module CIMI
 
     def grab_content_type(request_content_type, request_body)
       case request_content_type
-        when /xml$/i then :xml
-        when /json$/i then :json
-        else guess_content_type(request_body)
+        when /xml$/ then :xml
+        when /json$/ then :json
+        else raise CIMI::Model::UnsupportedMediaType.new("Unsupported content type - only
xml and json supported by CIMI")
+        #guess_content_type(request_body)
       end
     end
 
+    #not being used - was called from above grab_content_type
+    #decided to reject anything not xml || json
     def guess_content_type(request_body)
       xml = json = false
       body = request_body.read

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/ab1f43c8/server/lib/cimi/models/errors.rb
----------------------------------------------------------------------
diff --git a/server/lib/cimi/models/errors.rb b/server/lib/cimi/models/errors.rb
index 7c090ed..2d14144 100644
--- a/server/lib/cimi/models/errors.rb
+++ b/server/lib/cimi/models/errors.rb
@@ -33,6 +33,14 @@ module CIMI::Model
     end
   end
 
+  class UnsupportedMediaType < StandardError
+    attr_accessor :code
+    def initialize(msg="")
+      super(msg)
+      self.code=415
+    end
+  end
+
   class NotImplemented < StandardError
     attr_accessor :code
 


Mime
View raw message