rack-contrib 1.8.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rack-contrib might be problematic. Click here for more details.

Files changed (42) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +17 -10
  3. data/lib/rack/contrib.rb +3 -3
  4. data/lib/rack/contrib/access.rb +6 -4
  5. data/lib/rack/contrib/backstage.rb +3 -1
  6. data/lib/rack/contrib/bounce_favicon.rb +2 -0
  7. data/lib/rack/contrib/callbacks.rb +2 -0
  8. data/lib/rack/contrib/common_cookies.rb +16 -11
  9. data/lib/rack/contrib/config.rb +3 -15
  10. data/lib/rack/contrib/cookies.rb +2 -0
  11. data/lib/rack/contrib/csshttprequest.rb +10 -6
  12. data/lib/rack/contrib/deflect.rb +34 -32
  13. data/lib/rack/contrib/enforce_valid_encoding.rb +2 -0
  14. data/lib/rack/contrib/evil.rb +2 -0
  15. data/lib/rack/contrib/expectation_cascade.rb +3 -1
  16. data/lib/rack/contrib/garbagecollector.rb +2 -0
  17. data/lib/rack/contrib/host_meta.rb +2 -0
  18. data/lib/rack/contrib/json_body_parser.rb +85 -0
  19. data/lib/rack/contrib/jsonp.rb +8 -6
  20. data/lib/rack/contrib/lazy_conditional_get.rb +9 -0
  21. data/lib/rack/contrib/lighttpd_script_name_fix.rb +2 -0
  22. data/lib/rack/contrib/locale.rb +65 -30
  23. data/lib/rack/contrib/mailexceptions.rb +4 -2
  24. data/lib/rack/contrib/nested_params.rb +6 -121
  25. data/lib/rack/contrib/not_found.rb +3 -1
  26. data/lib/rack/contrib/post_body_content_type_parser.rb +49 -4
  27. data/lib/rack/contrib/printout.rb +2 -0
  28. data/lib/rack/contrib/proctitle.rb +2 -0
  29. data/lib/rack/contrib/profiler.rb +6 -1
  30. data/lib/rack/contrib/relative_redirect.rb +10 -5
  31. data/lib/rack/contrib/response_cache.rb +22 -11
  32. data/lib/rack/contrib/response_headers.rb +2 -0
  33. data/lib/rack/contrib/route_exceptions.rb +2 -0
  34. data/lib/rack/contrib/runtime.rb +3 -30
  35. data/lib/rack/contrib/signals.rb +6 -0
  36. data/lib/rack/contrib/simple_endpoint.rb +3 -1
  37. data/lib/rack/contrib/static_cache.rb +17 -8
  38. data/lib/rack/contrib/time_zone.rb +2 -0
  39. data/lib/rack/contrib/try_static.rb +2 -0
  40. metadata +50 -32
  41. data/lib/rack/contrib/accept_format.rb +0 -66
  42. data/lib/rack/contrib/sendfile.rb +0 -138
@@ -1,66 +0,0 @@
1
- module Rack
2
- #
3
- # CAUTION: THIS MIDDLEWARE IS DEPRECATED. DO NOT USE IT.
4
- #
5
- # This middleware is slated for removal as of rack-contrib 2.0.0, because
6
- # it is terribad. Applications should *always* use the `Accept` header to
7
- # detect response formats (when it is available), rather than ignoring
8
- # that and instead examining the extension of the request. We recommend
9
- # using the `rack-accept` gem for handling the `Accept` family of entity
10
- # request headers.
11
- #
12
- # A Rack middleware for automatically adding a <tt>format</tt> token at the end of the request path
13
- # when there is none. It can detect formats passed in the HTTP_ACCEPT header to populate this token.
14
- #
15
- # e.g.:
16
- # GET /some/resource HTTP/1.1
17
- # Accept: application/json
18
- # ->
19
- # GET /some/resource.json HTTP/1.1
20
- # Accept: application/json
21
- #
22
- # You can add custom types with this kind of function (taken from sinatra):
23
- # def mime(ext, type)
24
- # ext = ".#{ext}" unless ext.to_s[0] == ?.
25
- # Rack::Mime::MIME_TYPES[ext.to_s] = type
26
- # end
27
- # and then:
28
- # mime :json, 'application/json'
29
- #
30
- # Note: it does not take into account multiple media types in the Accept header.
31
- # The first media type takes precedence over all the others.
32
- #
33
- # MIT-License - Cyril Rohr
34
- #
35
- class AcceptFormat
36
- def self.deprecation_acknowledged
37
- @deprecation_acknowledged
38
- end
39
-
40
- def self.acknowledge_deprecation
41
- @deprecation_acknowledged = true
42
- end
43
-
44
- def initialize(app, default_extention = '.html')
45
- unless self.class.deprecation_acknowledged
46
- warn "Rack::AcceptFormat is DEPRECATED and will be removed in rack-contrib 2.0.0"
47
- warn "Please see this middleware's documentation for more info."
48
- end
49
- @ext = default_extention.to_s.strip
50
- @ext = ".#{@ext}" unless @ext[0] == ?.
51
- @app = app
52
- end
53
-
54
- def call(env)
55
- req = Rack::Request.new(env)
56
-
57
- if ::File.extname(req.path_info).empty?
58
- accept = env['HTTP_ACCEPT'].to_s.scan(/[^;,\s]*\/[^;,\s]*/)[0].to_s
59
- extension = Rack::Mime::MIME_TYPES.invert[accept] || @ext
60
- req.path_info = req.path_info.chomp('/') << "#{extension}"
61
- end
62
-
63
- @app.call(env)
64
- end
65
- end
66
- end
@@ -1,138 +0,0 @@
1
- require 'rack/file'
2
-
3
- warn "rack-contrib deprecation warning: the rack-contrib version of Rack::Sendfile is deprecated and will be removed in rack-contrib 2.0. Please use the Rack::Sendfile from Rack 2.x instead."
4
-
5
- module Rack
6
-
7
- #
8
- # The Sendfile middleware intercepts responses whose body is being
9
- # served from a file and replaces it with a server specific X-Sendfile
10
- # header. The web server is then responsible for writing the file contents
11
- # to the client. This can dramatically reduce the amount of work required
12
- # by the Ruby backend and takes advantage of the web servers optimized file
13
- # delivery code.
14
- #
15
- # In order to take advantage of this middleware, the response body must
16
- # respond to +to_path+ and the request must include an X-Sendfile-Type
17
- # header. Rack::File and other components implement +to_path+ so there's
18
- # rarely anything you need to do in your application. The X-Sendfile-Type
19
- # header is typically set in your web servers configuration. The following
20
- # sections attempt to document
21
- #
22
- # === Nginx
23
- #
24
- # Nginx supports the X-Accel-Redirect header. This is similar to X-Sendfile
25
- # but requires parts of the filesystem to be mapped into a private URL
26
- # hierarachy.
27
- #
28
- # The following example shows the Nginx configuration required to create
29
- # a private "/files/" area, enable X-Accel-Redirect, and pass the special
30
- # X-Sendfile-Type and X-Accel-Mapping headers to the backend:
31
- #
32
- # location /files/ {
33
- # internal;
34
- # alias /var/www/;
35
- # }
36
- #
37
- # location / {
38
- # proxy_redirect false;
39
- #
40
- # proxy_set_header Host $host;
41
- # proxy_set_header X-Real-IP $remote_addr;
42
- # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
43
- #
44
- # proxy_set_header X-Sendfile-Type X-Accel-Redirect
45
- # proxy_set_header X-Accel-Mapping /files/=/var/www/;
46
- #
47
- # proxy_pass http://127.0.0.1:8080/;
48
- # }
49
- #
50
- # Note that the X-Sendfile-Type header must be set exactly as shown above. The
51
- # X-Accel-Mapping header should specify the name of the private URL pattern,
52
- # followed by an equals sign (=), followed by the location on the file system
53
- # that it maps to. The middleware performs a simple substitution on the
54
- # resulting path.
55
- #
56
- # See Also: http://wiki.codemongers.com/NginxXSendfile
57
- #
58
- # === lighttpd
59
- #
60
- # Lighttpd has supported some variation of the X-Sendfile header for some
61
- # time, although only recent version support X-Sendfile in a reverse proxy
62
- # configuration.
63
- #
64
- # $HTTP["host"] == "example.com" {
65
- # proxy-core.protocol = "http"
66
- # proxy-core.balancer = "round-robin"
67
- # proxy-core.backends = (
68
- # "127.0.0.1:8000",
69
- # "127.0.0.1:8001",
70
- # ...
71
- # )
72
- #
73
- # proxy-core.allow-x-sendfile = "enable"
74
- # proxy-core.rewrite-request = (
75
- # "X-Sendfile-Type" => (".*" => "X-Sendfile")
76
- # )
77
- # }
78
- #
79
- # See Also: http://redmine.lighttpd.net/wiki/lighttpd/Docs:ModProxyCore
80
- #
81
- # === Apache
82
- #
83
- # X-Sendfile is supported under Apache 2.x using a separate module:
84
- #
85
- # http://tn123.ath.cx/mod_xsendfile/
86
- #
87
- # Once the module is compiled and installed, you can enable it using
88
- # XSendFile config directive:
89
- #
90
- # RequestHeader Set X-Sendfile-Type X-Sendfile
91
- # ProxyPassReverse / http://localhost:8001/
92
- # XSendFile on
93
-
94
- class Sendfile
95
- def initialize(app, variation=nil)
96
- @app = app
97
- @variation = variation
98
- end
99
-
100
- def call(env)
101
- status, headers, body = @app.call(env)
102
- if body.respond_to?(:to_path)
103
- case type = variation(env)
104
- when 'X-Accel-Redirect'
105
- path = ::File.expand_path(body.to_path)
106
- if url = map_accel_path(env, path)
107
- headers[type] = url
108
- body = []
109
- else
110
- env['rack.errors'] << "X-Accel-Mapping header missing"
111
- end
112
- when 'X-Sendfile', 'X-Lighttpd-Send-File'
113
- path = ::File.expand_path(body.to_path)
114
- headers[type] = path
115
- body = []
116
- when '', nil
117
- else
118
- env['rack.errors'] << "Unknown x-sendfile variation: '#{variation}'.\n"
119
- end
120
- end
121
- [status, headers, body]
122
- end
123
-
124
- private
125
- def variation(env)
126
- @variation ||
127
- env['sendfile.type'] ||
128
- env['HTTP_X_SENDFILE_TYPE']
129
- end
130
-
131
- def map_accel_path(env, file)
132
- if mapping = env['HTTP_X_ACCEL_MAPPING']
133
- internal, external = mapping.split('=', 2).map{ |p| p.strip }
134
- file.sub(/^#{internal}/i, external)
135
- end
136
- end
137
- end
138
- end