deltacloud-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@apache.org
Subject [1/13] git commit: Core: Removed obsoleted accept_media_type helper
Date Tue, 24 Jul 2012 07:39:46 GMT
Updated Branches:
  refs/heads/master ea4e35841 -> bf14ec917


Core: Removed obsoleted accept_media_type helper


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

Branch: refs/heads/master
Commit: bf14ec9170da5b952305a10bebc9eb0829a5cd2e
Parents: e650177
Author: Michal Fojtik <mfojtik@redhat.com>
Authored: Tue Jul 24 09:36:22 2012 +0200
Committer: Michal fojtik <mfojtik@redhat.com>
Committed: Tue Jul 24 09:38:05 2012 +0200

----------------------------------------------------------------------
 server/lib/sinatra.rb                    |    1 -
 server/lib/sinatra/accept_media_types.rb |  154 -------------------------
 2 files changed, 0 insertions(+), 155 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltacloud/blob/bf14ec91/server/lib/sinatra.rb
----------------------------------------------------------------------
diff --git a/server/lib/sinatra.rb b/server/lib/sinatra.rb
index 13197f5..73b63b0 100644
--- a/server/lib/sinatra.rb
+++ b/server/lib/sinatra.rb
@@ -18,5 +18,4 @@ require_relative 'sinatra/rack_date'
 require_relative 'sinatra/rack_etag'
 require_relative 'sinatra/rack_matrix_params'
 require_relative 'sinatra/rack_driver_select'
-require_relative 'sinatra/accept_media_types'
 require_relative 'sinatra/rack_accept'

http://git-wip-us.apache.org/repos/asf/deltacloud/blob/bf14ec91/server/lib/sinatra/accept_media_types.rb
----------------------------------------------------------------------
diff --git a/server/lib/sinatra/accept_media_types.rb b/server/lib/sinatra/accept_media_types.rb
deleted file mode 100644
index 728b00b..0000000
--- a/server/lib/sinatra/accept_media_types.rb
+++ /dev/null
@@ -1,154 +0,0 @@
-#
-# Based on https://github.com/mynyml/rack-accept-media-types
-# Commit 3d0f38882a466cc72043
-#
-# Original license:
-# Copyright (C) 2009 Martin Aumont (mynyml)
-#
-# Permission is hereby granted, free of charge, to any person obtaining a
-# copy of this software and associated documentation files (the
-# "Software"), to deal in the Software without restriction, including
-# without limitation the rights to use, copy, modify, merge, publish,
-# distribute, sublicense, and/or sell copies of the Software, and to permit
-# persons to whom the Software is furnished to do so, subject to the
-# following conditions:
-#
-# The above copyright notice and this permission notice shall be included
-# in all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
-# NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
-# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
-# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
-# USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-module Rack
-  class Request
-    # The media types of the HTTP_ACCEPT header ordered according to their
-    # "quality" (preference level), without any media type parameters.
-    #
-    # ===== Examples
-    #
-    #   env['HTTP_ACCEPT']  #=> 'application/xml;q=0.8,text/html,text/plain;q=0.9'
-    #
-    #   req = Rack::Request.new(env)
-    #   req.accept_media_types          #=> ['text/html', 'text/plain', 'application/xml']
-    #   req.accept_media_types.prefered #=>  'text/html'
-    #
-    # For more information, see:
-    # * Acept header:   http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
-    # * Quality values: http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.9
-    #
-    # ===== Returns
-    # AcceptMediaTypes:: ordered list of accept header's media types
-    #
-    def accept_media_types
-       @accept_media_types ||= Rack::AcceptMediaTypes.new(@env['HTTP_ACCEPT'])
-    end
-  end
-
-  # AcceptMediaTypes is intended for wrapping env['HTTP_ACCEPT'].
-  #
-  # It allows ordering of its values (accepted media types) according to their
-  # "quality" (preference level).
-  #
-  # This wrapper is typically used to determine the request's prefered media
-  # type (see example below).
-  #
-  # ===== Examples
-  #
-  #   env['HTTP_ACCEPT']  #=> 'application/xml;q=0.8,text/html,text/plain;q=0.9'
-  #
-  #   types = Rack::AcceptMediaTypes.new(env['HTTP_ACCEPT'])
-  #   types               #=> ['text/html', 'text/plain', 'application/xml']
-  #   types.prefered      #=>  'text/html'
-  #
-  # ===== Notes
-  #
-  # For simplicity, media type parameters are striped, as they are seldom used
-  # in practice. Users who need them are excepted to parse the Accept header
-  # manually.
-  #
-  # ===== References
-  #
-  # HTTP 1.1 Specs:
-  # * http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
-  # * http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.9
-  #
-  class AcceptMediaTypes < Array
-
-    #--
-    # NOTE
-    # Reason for special handling of nil accept header:
-    #
-    # "If no Accept header field is present, then it is assumed that the client
-    # accepts all media types."
-    #
-    def initialize(header)
-      if header.nil?
-        replace(['*/*'])
-      else
-        replace(order(header.gsub(/ /, '').split(/,/)))
-      end
-    end
-
-    # The client's prefered media type.
-    def prefered
-      first
-    end
-
-    private
-
-    # Order media types by quality values, remove invalid types, and return media ranges.
-    #
-    def order(types) #:nodoc:
-      types.map {|type| AcceptMediaType.new(type) }.reverse.sort.reverse.select {|type| type.valid?
}.map {|type| type.range }
-    end
-
-    # http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1
-    #
-    class AcceptMediaType #:nodoc:
-      include Comparable
-
-      # media-range = ( "*/*"
-      #               | ( type "/" "*" )
-      #               | ( type "/" subtype )
-      #               ) *( ";" parameter )
-      attr_accessor :range
-
-      # qvalue = ( "0" [ "." 0*3DIGIT ] )
-      #        | ( "1" [ "." 0*3("0") ] )
-      attr_accessor :quality
-
-      def initialize(type)
-        self.range, *params = type.split(';')
-        self.quality = extract_quality(params)
-      end
-
-      def <=>(type)
-        self.quality <=> type.quality
-      end
-
-      # "A weight is normalized to a real number in the range 0 through 1,
-      # where 0 is the minimum and 1 the maximum value. If a parameter has a
-      # quality value of 0, then content with this parameter is `not
-      # acceptable' for the client."
-      #
-      def valid?
-        self.quality.between?(0.1, 1)
-      end
-
-      private
-        # Extract value from 'q=FLOAT' parameter if present, otherwise assume 1
-        #
-        # "The default value is q=1."
-        #
-        def extract_quality(params)
-          q = params.detect {|p| p.match(/q=\d\.?\d{0,3}/) }
-          q ? q.split('=').last.to_f : 1.0
-        end
-    end
-  end
-end


Mime
View raw message