Permalink
Browse files

Moved Negotiator.append_vary_header to Utils.append_vary_header

  • Loading branch information...
1 parent 1b27a7a commit 711c928f33d8d829ca5cbd862f1a6a35876c1784 @dkubb committed Oct 18, 2009
Showing with 56 additions and 49 deletions.
  1. +1 −0 lib/rack/conneg.rb
  2. +1 −48 lib/rack/conneg/negotiator.rb
  3. +1 −1 lib/rack/conneg/path.rb
  4. +53 −0 lib/rack/conneg/utils.rb
View
@@ -16,3 +16,4 @@ class Conneg
require 'rack/conneg/negotiator'
require 'rack/conneg/path'
require 'rack/conneg/static'
+require 'rack/conneg/utils'
@@ -67,7 +67,7 @@ def pass(env = @request.env)
def call
path = select_variant
response = path && path.mime_type ? serve_path(path) : NOT_ACCEPTABLE
- self.class.append_vary_header(response[1], 'Accept')
+ Utils.append_vary_header(response[1], 'Accept')
response
end
@@ -100,53 +100,6 @@ def serve_path(path)
[ status, headers, body ]
end
- # Append client header names used to negotiate the response to Vary
- #
- # @param [Hash] headers
- # the Rack response headers
- # @param [Array<String>] *names
- # the client headers used to negotiate the response
- #
- # @return [undefined]
- #
- # @api private
- def self.append_vary_header(headers, *names)
- vary = split_header(headers['Vary'])
- return if vary.include?('*')
- headers['Vary'] = join_header(vary | names)
- end
-
- # Split the header value into an Array
- #
- # @param [#to_s] header
- # the header value to split
- #
- # @return [Array<String>]
- # the header values
- #
- # @api private
- def self.split_header(header)
- header.to_s.delete(' ').split(',')
- end
-
- # Join the header values into a String
- #
- # @param [Array<String>] values
- # the header values to join
- #
- # @return [String]
- # the header value
- #
- # @api private
- def self.join_header(values)
- values.join(',')
- end
-
- class << self
- private :split_header
- private :join_header
- end
-
end
end
end
View
@@ -148,7 +148,7 @@ def pattern
#
# @api private
def self.normalize_path_info(path_info)
- "/#{Utils.unescape(path_info.to_s).gsub(/\A\//, '')}"
+ "/#{Rack::Utils.unescape(path_info.to_s).gsub(/\A\//, '')}"
end
end
View
@@ -0,0 +1,53 @@
+module Rack
+ class Conneg
+ class Utils
+
+ # Append client header names used to negotiate the response to Vary
+ #
+ # @param [Hash] headers
+ # the Rack response headers
+ # @param [Array<String>] *names
+ # the client headers used to negotiate the response
+ #
+ # @return [undefined]
+ #
+ # @api private
+ def self.append_vary_header(headers, *names)
+ vary = split_header(headers['Vary'])
+ return if vary.include?('*')
+ headers['Vary'] = join_header(vary | names)
+ end
+
+ # Split the header value into an Array
+ #
+ # @param [#to_s] header
+ # the header value to split
+ #
+ # @return [Array<String>]
+ # the header values
+ #
+ # @api private
+ def self.split_header(header)
+ header.to_s.delete(' ').split(',')
+ end
+
+ # Join the header values into a String
+ #
+ # @param [Array<String>] values
+ # the header values to join
+ #
+ # @return [String]
+ # the header value
+ #
+ # @api private
+ def self.join_header(values)
+ values.join(',')
+ end
+
+ class << self
+ private :split_header
+ private :join_header
+ end
+ end
+ end
+end

0 comments on commit 711c928

Please sign in to comment.