rack-content_disposition_helper 0.1.0 → 0.2.0
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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3087bac2c96ea49d1175a3b7af9e6517156d120dc242243ea3b5c1c4c2843b4
|
4
|
+
data.tar.gz: 27b2a444a205e29a1ed225bd6a9dfb6aa612a30067f043f8088c60dcd4e06da8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07cdcdf7d605a140b507955245c849486251ed39565fa0ad85dc9ccd1955fee721af8578c556cce5c35bb0fe9aa1880c17cdfce7186dc5501fae18f1bd4c1c1b
|
7
|
+
data.tar.gz: 9de09768d3f5d21e3c87f168a5c7aa6c5bf7f5c9600b6d2a96478912d0ae4a19b036c9ae147ec78931f150b9e6c59fc988ab386f70b1a247082e6a075f88b30e
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
|
-
|
1
|
+
# Unreleased
|
2
2
|
|
3
|
-
|
3
|
+
# 0.2.0 - 2022/04/04
|
4
|
+
|
5
|
+
## Breaking Changes:
|
6
|
+
|
7
|
+
- Rename Rack::ContentDispositionHelper::ContentDisposition to Rack::ContentDispositionHelper::Converter
|
8
|
+
- Rename Rack::ContentDispositionHelper::Converter#long? to Rack::ContentDispositionHelper::Converter#length_limit_exceeded?
|
9
|
+
- Rename Rack::ContentDispositionHelper::Converter#raw_filename_value to Rack::ContentDispositionHelper::Converter#convert
|
10
|
+
- Rename Rack::ContentDispositionHelper::Converter#value to Rack::ContentDispositionHelper::Converter#original_value
|
11
|
+
- Drop support for Ruby 2.6
|
12
|
+
|
13
|
+
## Enhancement:
|
14
|
+
|
15
|
+
- Rack::ContentDispositionHelper::Converter#convert now returns the original value if the `filename*` directive does not exist
|
16
|
+
|
17
|
+
# 0.1.0 - 2022/03/24
|
4
18
|
|
5
19
|
- Initial release.
|
data/README.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
[](https://github.com/hana-da/rack-content_disposition_helper/actions/workflows/test.yml)
|
2
|
+
[](https://codeclimate.com/github/hana-da/rack-content_disposition_helper/maintainability)
|
3
|
+
[](https://badge.fury.io/rb/rack-content_disposition_helper)
|
4
|
+
[](https://github.com/hana-da/rack-content_disposition_helper/blob/main/MIT-LICENSE)
|
5
|
+
|
1
6
|
# Rack::ContentDispositionHelper
|
2
7
|
|
3
8
|
Rack::ContentDispositionHelper is Rack middleware that rewrites the decoded `filename*` directive in the Content-Disposition response header as the value of the `filename` directive.
|
@@ -47,6 +52,8 @@ For Sinatra and other Rack apps, add this to config.ru:
|
|
47
52
|
|
48
53
|
```ruby
|
49
54
|
# config.ru
|
55
|
+
|
56
|
+
# Bundler.require or require 'rack/content_disposition_helper'
|
50
57
|
use Rack::ContentDispositionHelper
|
51
58
|
```
|
52
59
|
|
@@ -4,35 +4,35 @@ require 'cgi'
|
|
4
4
|
|
5
5
|
module Rack
|
6
6
|
class ContentDispositionHelper
|
7
|
-
class
|
7
|
+
class Converter
|
8
8
|
LIMIT = 254
|
9
9
|
FILENAME_ASTERISK_PREFIX = "filename*=UTF-8''"
|
10
10
|
|
11
|
-
attr_reader :
|
11
|
+
attr_reader :original_value, :parts
|
12
12
|
|
13
13
|
def initialize(original_value)
|
14
|
-
@
|
15
|
-
@parts =
|
14
|
+
@original_value = original_value
|
15
|
+
@parts = original_value&.split
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
19
|
-
return nil unless
|
18
|
+
def length_limit_exceeded?
|
19
|
+
return nil unless original_value
|
20
20
|
|
21
|
-
|
21
|
+
original_value.length > LIMIT
|
22
22
|
end
|
23
23
|
|
24
24
|
def disposition
|
25
25
|
parts&.first
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
29
|
-
return
|
28
|
+
def convert
|
29
|
+
return original_value if !disposition || !raw_filename
|
30
30
|
|
31
31
|
"#{disposition} filename=\"#{raw_filename}\""
|
32
32
|
end
|
33
33
|
|
34
34
|
def raw_filename
|
35
|
-
filename_asterisk&.then { |v| CGI.unescape(v).delete_prefix!(FILENAME_ASTERISK_PREFIX) }
|
35
|
+
@raw_filename ||= filename_asterisk&.then { |v| CGI.unescape(v).delete_prefix!(FILENAME_ASTERISK_PREFIX) }
|
36
36
|
end
|
37
37
|
|
38
38
|
def filename_asterisk
|
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'rack/content_disposition_helper/version'
|
4
4
|
|
5
5
|
require 'rack/content_disposition_helper/user_agent'
|
6
|
-
require 'rack/content_disposition_helper/
|
6
|
+
require 'rack/content_disposition_helper/converter'
|
7
7
|
|
8
8
|
require 'rack/content_disposition_helper/railtie' if defined?(::Rails::Railtie)
|
9
9
|
|
@@ -17,10 +17,10 @@ module Rack
|
|
17
17
|
status_code, headers, body = @app.call(env)
|
18
18
|
|
19
19
|
user_agent = UserAgent.new(env)
|
20
|
-
|
20
|
+
converter = Converter.new(headers['Content-Disposition'])
|
21
21
|
|
22
|
-
if
|
23
|
-
headers = headers.merge('Content-Disposition' =>
|
22
|
+
if converter.length_limit_exceeded? && user_agent.safari?
|
23
|
+
headers = headers.merge('Content-Disposition' => converter.convert)
|
24
24
|
end
|
25
25
|
|
26
26
|
[status_code, headers, body]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-content_disposition_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- hana-da
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-04-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -42,7 +42,7 @@ files:
|
|
42
42
|
- MIT-LICENSE
|
43
43
|
- README.md
|
44
44
|
- lib/rack/content_disposition_helper.rb
|
45
|
-
- lib/rack/content_disposition_helper/
|
45
|
+
- lib/rack/content_disposition_helper/converter.rb
|
46
46
|
- lib/rack/content_disposition_helper/railtie.rb
|
47
47
|
- lib/rack/content_disposition_helper/user_agent.rb
|
48
48
|
- lib/rack/content_disposition_helper/version.rb
|
@@ -54,7 +54,7 @@ metadata:
|
|
54
54
|
homepage_uri: https://github.com/hana-da/rack-content_disposition_helper
|
55
55
|
source_code_uri: https://github.com/hana-da/rack-content_disposition_helper
|
56
56
|
bug_tracker_uri: https://github.com/hana-da/rack-content_disposition_helper/issues
|
57
|
-
changelog_uri: https://github.com/hana-da/rack-content_disposition_helper/CHANGELOG.md
|
57
|
+
changelog_uri: https://github.com/hana-da/rack-content_disposition_helper/blob/main/CHANGELOG.md
|
58
58
|
post_install_message:
|
59
59
|
rdoc_options: []
|
60
60
|
require_paths:
|
@@ -63,14 +63,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
63
63
|
requirements:
|
64
64
|
- - ">="
|
65
65
|
- !ruby/object:Gem::Version
|
66
|
-
version: 2.
|
66
|
+
version: '2.7'
|
67
67
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
68
|
requirements:
|
69
69
|
- - ">="
|
70
70
|
- !ruby/object:Gem::Version
|
71
71
|
version: '0'
|
72
72
|
requirements: []
|
73
|
-
rubygems_version: 3.
|
73
|
+
rubygems_version: 3.3.10
|
74
74
|
signing_key:
|
75
75
|
specification_version: 4
|
76
76
|
summary: Rack middleware that modifies Content-Disposition response header.
|