rack-accept-header-updater 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.1.1
@@ -27,12 +27,14 @@ module Rack
27
27
 
28
28
  def initialize(app, options = {})
29
29
  @app = app
30
+ @options = options
30
31
  end
31
32
 
32
33
  def call(env)
33
34
  req = Rack::Request.new(env)
34
35
  unless (ext = ::File.extname(req.path_info)).empty?
35
- if (mime_type = Rack::Mime::MIME_TYPES[ext.downcase])
36
+ ignore_middleware = (@options[:except] || []).detect{ |except| env['PATH_INFO'] =~ except }
37
+ if !ignore_middleware && (mime_type = Rack::Mime::MIME_TYPES[ext.downcase])
36
38
  env['HTTP_ACCEPT'] = [mime_type, env['HTTP_ACCEPT']].join(",")
37
39
  req.path_info.gsub!(/#{ext}$/, '')
38
40
  end
@@ -1,15 +1,15 @@
1
1
  # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rack-accept-header-updater}
8
- s.version = "1.1.0"
8
+ s.version = "1.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Cyril Rohr"]
12
- s.date = %q{2009-10-22}
12
+ s.date = %q{2009-12-07}
13
13
  s.description = %q{A Rack middleware for automatically removing file extensions from URIs, and update the Accept HTTP Header accordingly.}
14
14
  s.email = %q{cyril.rohr@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -48,3 +48,4 @@ Gem::Specification.new do |s|
48
48
  else
49
49
  end
50
50
  end
51
+
@@ -42,5 +42,12 @@ describe Rack::AcceptHeaderUpdater do
42
42
  status, headers, body = Rack::AcceptHeaderUpdater.new(app).call(request)
43
43
  body.should == ["*/*|/some/resource.x.y"]
44
44
  end
45
+ it "should do nothing if the :except option contains a regexp that matches the request's path" do
46
+ mime :json, 'application/json'
47
+ app = lambda { |env| [200, {'Content-Type' => 'text/plain'}, [[env['HTTP_ACCEPT'], env['PATH_INFO']].join("|")]] }
48
+ request = Rack::MockRequest.env_for("/some/resource.json", :input => "foo=bar", 'HTTP_ACCEPT' => '*/*')
49
+ status, headers, body = Rack::AcceptHeaderUpdater.new(app, :except => [/\.json$/]).call(request)
50
+ body.should == ["*/*|/some/resource.json"]
51
+ end
45
52
  end
46
53
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-accept-header-updater
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyril Rohr
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-22 00:00:00 +02:00
12
+ date: 2009-12-07 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15