rack-content_disposition_helper 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 65bb8f8c0b81289e8992dddcdc32ddf7be95aebbadf8c981a4c11a193670f6f1
4
- data.tar.gz: 07f5d4a25e13bd83dc705513720c7b0835f7d29b0b794aab7a840b497232e672
3
+ metadata.gz: b3087bac2c96ea49d1175a3b7af9e6517156d120dc242243ea3b5c1c4c2843b4
4
+ data.tar.gz: 27b2a444a205e29a1ed225bd6a9dfb6aa612a30067f043f8088c60dcd4e06da8
5
5
  SHA512:
6
- metadata.gz: 9a3884c9d2a6f6e757596cdf6354e02cf1fb7bf21454b8dfb0a27112f713ecb3998df85d90eb9114daa74215a0df6712f0d2344f5194234c7b2972a738b0d21e
7
- data.tar.gz: 5e78b8f97f0b1939177f7229524cae99f566034431454f3776aaeabb38aa29c4dcc293346a4ae12ea45f1287156f38d51ee4b0c514d87c7f2e6a9f58894600dc
6
+ metadata.gz: 07cdcdf7d605a140b507955245c849486251ed39565fa0ad85dc9ccd1955fee721af8578c556cce5c35bb0fe9aa1880c17cdfce7186dc5501fae18f1bd4c1c1b
7
+ data.tar.gz: 9de09768d3f5d21e3c87f168a5c7aa6c5bf7f5c9600b6d2a96478912d0ae4a19b036c9ae147ec78931f150b9e6c59fc988ab386f70b1a247082e6a075f88b30e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
- ## [Unreleased]
1
+ # Unreleased
2
2
 
3
- ## [0.1.0] - 2022/03/24
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
+ [![GitHub Actions](https://github.com/hana-da/rack-content_disposition_helper/actions/workflows/test.yml/badge.svg)](https://github.com/hana-da/rack-content_disposition_helper/actions/workflows/test.yml)
2
+ [![Maintainability](https://api.codeclimate.com/v1/badges/27559fca466cbad7698d/maintainability)](https://codeclimate.com/github/hana-da/rack-content_disposition_helper/maintainability)
3
+ [![Gem Version](https://badge.fury.io/rb/rack-content_disposition_helper.svg)](https://badge.fury.io/rb/rack-content_disposition_helper)
4
+ [![GitHub](https://img.shields.io/github/license/hana-da/rack-content_disposition_helper)](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 ContentDisposition
7
+ class Converter
8
8
  LIMIT = 254
9
9
  FILENAME_ASTERISK_PREFIX = "filename*=UTF-8''"
10
10
 
11
- attr_reader :value, :parts
11
+ attr_reader :original_value, :parts
12
12
 
13
13
  def initialize(original_value)
14
- @value = original_value
15
- @parts = value&.split
14
+ @original_value = original_value
15
+ @parts = original_value&.split
16
16
  end
17
17
 
18
- def long?
19
- return nil unless value
18
+ def length_limit_exceeded?
19
+ return nil unless original_value
20
20
 
21
- value.length > LIMIT
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 raw_filename_value
29
- return unless disposition
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rack
4
4
  class ContentDispositionHelper
5
- VERSION = '0.1.0'
5
+ VERSION = '0.2.0'
6
6
  end
7
7
  end
@@ -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/content_disposition'
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
- content_disposition = ContentDisposition.new(headers['Content-Disposition'])
20
+ converter = Converter.new(headers['Content-Disposition'])
21
21
 
22
- if content_disposition.long? && user_agent.safari?
23
- headers = headers.merge('Content-Disposition' => content_disposition.raw_filename_value)
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.1.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-03-24 00:00:00.000000000 Z
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/content_disposition.rb
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.6.9
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.0.3.1
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.