mynyml-rack-accept-media-types 0.5.1 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -22,7 +22,7 @@ end
22
22
 
23
23
  spec = Gem::Specification.new do |s|
24
24
  s.name = 'rack-accept-media-types'
25
- s.version = '0.5.1'
25
+ s.version = '0.6'
26
26
  s.summary = "Rack convenience middleware for simplified handling of Accept header."
27
27
  s.description = "Rack convenience middleware for simplified handling of Accept header."
28
28
  s.author = "Martin Aumont"
@@ -36,3 +36,21 @@ example do
36
36
  types.prefered
37
37
  #=> "application/xml"
38
38
  end
39
+
40
+ # no accept header means client accepts all types (rfc2616-sec14.1)
41
+ env = {'HTTP_ACCEPT' => nil}
42
+ example do
43
+ types = Rack::AcceptMediaTypes.new(env['HTTP_ACCEPT'])
44
+ #=> ["*/*"]
45
+ types.prefered
46
+ #=> "*/*"
47
+ end
48
+
49
+ # to avoid getting a wildcard media-range, pass an empty string instead
50
+ env = {'HTTP_ACCEPT' => nil}
51
+ example do
52
+ types = Rack::AcceptMediaTypes.new(env['HTTP_ACCEPT'] || '')
53
+ #=> []
54
+ types.prefered
55
+ #=> nil
56
+ end
@@ -30,8 +30,19 @@ module Rack
30
30
  #
31
31
  class AcceptMediaTypes < Array
32
32
 
33
+ #--
34
+ # NOTE
35
+ # Reason for special handling of nil accept header:
36
+ #
37
+ # "If no Accept header field is present, then it is assumed that the client
38
+ # accepts all media types."
39
+ #
33
40
  def initialize(header)
34
- replace(order(header.split(',')))
41
+ if header.nil?
42
+ replace(['*/*'])
43
+ else
44
+ replace(order(header.split(',')))
45
+ end
35
46
  end
36
47
 
37
48
  # The client's prefered media type.
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-accept-media-types
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: "0.6"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Aumont
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-06 00:00:00 -04:00
12
+ date: 2009-06-08 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -53,6 +53,21 @@ class AcceptMediaTypesTest < Test::Unit::TestCase
53
53
  header = 'text/html;q=0.5;token=value,text/plain'
54
54
  assert_equal %w( text/plain text/html ), Accept.new(header)
55
55
  end
56
+
57
+ test "nil accept header" do
58
+ header = nil
59
+ assert_equal %w( */* ), Accept.new(header)
60
+ end
61
+
62
+ test "empty accept header" do
63
+ header = ''
64
+ assert_equal [], Accept.new(header)
65
+ end
66
+
67
+ test "all accepted types are invalid" do
68
+ header = 'text/html;q=2,application/xml;q=0'
69
+ assert_equal [], Accept.new(header)
70
+ end
56
71
  end
57
72
 
58
73
  __END__
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mynyml-rack-accept-media-types
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: "0.6"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Aumont
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-05 21:00:00 -07:00
12
+ date: 2009-06-07 21:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15