rack-accept-default 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rack-accept-default.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (C) 2012 Tatsuhiko Miyagawa
2
+
3
+ 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:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ 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.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # Rack::AcceptDefault
2
+
3
+ Rack::AcceptDefault is a tiny piece of middleware that sets default `Accept:` header when it isn't present, to work around Rails 3.x issues.
4
+
5
+ ## Installation
6
+
7
+ ### rubygems
8
+
9
+ ```
10
+ gem install rack-accept-default
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ ```
16
+ require 'rack-accept-default`
17
+ use Rack::AcceptDefault
18
+ ```
19
+
20
+ ## Why
21
+
22
+ Rails default MIME negotiation (in ActionPack) handles requests without `Accept:` headers as *invalid*, and assume it wants the HTML view. This assumption is wrong per RFC 2616 HTTP/1.1 specification.
23
+
24
+ > If no Accept header field is present, then it is assumed that the client accepts all media types
25
+
26
+ Rack::AcceptDefault is a piece of Rack middleware that provides a convenient way to work around this problem, by setting the `*/*` value to the `Accept` header when it is not present.
27
+
28
+ ## License
29
+
30
+ MIT License.
31
+
32
+ ## Copyright
33
+
34
+ Copyright 2012- Tatsuhiko Miyagawa
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1 @@
1
+ require 'rack/accept_default'
@@ -0,0 +1,15 @@
1
+ module Rack
2
+ class AcceptDefault
3
+ def initialize(app, default='*/*')
4
+ @app = app
5
+ @default = default
6
+ end
7
+
8
+ def call(env)
9
+ unless env.key?('HTTP_ACCEPT')
10
+ env['HTTP_ACCEPT'] = @default
11
+ end
12
+ @app.call(env)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ module Rack
2
+ module AcceptDefaultVersion
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "rack/accept_default/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "rack-accept-default"
7
+ s.version = Rack::AcceptDefaultVersion::VERSION
8
+ s.authors = ["Tatsuhiko Miyagawa"]
9
+ s.email = ["miyagawa@bulknews.net"]
10
+ s.homepage = "https://github.com/miyagawa/rack-accept-default"
11
+ s.summary = "Set default value for Accept: header when it is not present"
12
+ s.description = "A tiny piece of Rack middleware to set the default Accept: header"
13
+
14
+ s.rubyforge_project = "rack-accept-default"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ s.add_development_dependency "rake"
23
+ s.add_development_dependency "rack-test"
24
+ s.add_development_dependency "rspec"
25
+ s.add_runtime_dependency "rack"
26
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rack::AcceptDefault do
4
+ include Rack::Test::Methods
5
+
6
+ def app
7
+ rack_app = lambda { |env| [200, {"Content-Type" => "text/plain"}, [ env["HTTP_ACCEPT"] ]] }
8
+ Rack::AcceptDefault.new(rack_app)
9
+ end
10
+
11
+ it "should set */* as a default header" do
12
+ get '/'
13
+ last_response.should be_ok
14
+ last_response.body.should == '*/*'
15
+ end
16
+
17
+ it "should not override given Accept header" do
18
+ get '/', {}, { 'HTTP_ACCEPT' => "application/json" }
19
+ last_response.should be_ok
20
+ last_response.body.should == 'application/json'
21
+ end
22
+ end
@@ -0,0 +1,6 @@
1
+ require 'rack-accept-default'
2
+ require 'rack/test'
3
+ require 'rspec'
4
+
5
+ RSpec.configure do |config|
6
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-accept-default
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tatsuhiko Miyagawa
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-05 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &70147026020780 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70147026020780
25
+ - !ruby/object:Gem::Dependency
26
+ name: rack-test
27
+ requirement: &70147026020060 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *70147026020060
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec
38
+ requirement: &70147026019640 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70147026019640
47
+ - !ruby/object:Gem::Dependency
48
+ name: rack
49
+ requirement: &70147026019140 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *70147026019140
58
+ description: ! 'A tiny piece of Rack middleware to set the default Accept: header'
59
+ email:
60
+ - miyagawa@bulknews.net
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - .gitignore
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - lib/rack-accept-default.rb
71
+ - lib/rack/accept_default.rb
72
+ - lib/rack/accept_default/version.rb
73
+ - rack-accept-default.gemspec
74
+ - spec/rack/accept_default_spec.rb
75
+ - spec/spec_helper.rb
76
+ homepage: https://github.com/miyagawa/rack-accept-default
77
+ licenses: []
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project: rack-accept-default
96
+ rubygems_version: 1.8.15
97
+ signing_key:
98
+ specification_version: 3
99
+ summary: ! 'Set default value for Accept: header when it is not present'
100
+ test_files:
101
+ - spec/rack/accept_default_spec.rb
102
+ - spec/spec_helper.rb
103
+ has_rdoc: