httpdisk 0.5.2 → 1.0.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.
@@ -1,5 +1,5 @@
1
- require 'find'
2
- require 'json'
1
+ require "find"
2
+ require "json"
3
3
 
4
4
  module HTTPDisk
5
5
  module Grep
@@ -13,25 +13,22 @@ module HTTPDisk
13
13
  # Enumerate file paths one at a time. Returns true if matches were found.
14
14
  def run
15
15
  paths.each do
16
- begin
17
- run_one(_1)
18
- rescue StandardError => e
19
- if ENV['HTTPDISK_DEBUG']
20
- $stderr.puts
21
- $stderr.puts e.class
22
- $stderr.puts e.backtrace.join("\n")
23
- end
24
- raise CliError, "#{e.message[0, 70]} (#{_1})"
16
+ run_one(_1)
17
+ rescue => e
18
+ if ENV["HTTPDISK_DEBUG"]
19
+ $stderr.puts
20
+ warn e.class
21
+ warn e.backtrace.join("\n")
25
22
  end
23
+ raise CliError, "#{e.message[0, 70]} (#{_1})"
26
24
  end
27
25
  success
28
26
  end
29
27
 
30
28
  def run_one(path)
31
- # read payload & body
32
- payload = Zlib::GzipReader.open(path, encoding: 'ASCII-8BIT') do
33
- Payload.read(_1)
34
- end
29
+ payload = read_payload(path)
30
+ return if !payload
31
+
35
32
  body = prepare_body(payload)
36
33
 
37
34
  # collect all_matches
@@ -51,37 +48,48 @@ module HTTPDisk
51
48
  def paths
52
49
  # roots
53
50
  roots = options[:roots]
54
- roots = ['.'] if roots.empty?
51
+ roots = ["."] if roots.empty?
55
52
 
56
53
  # find files in roots
57
54
  paths = roots.flat_map { Find.find(_1).to_a }.sort
58
55
  paths = paths.select { File.file?(_1) }
59
56
 
60
57
  # strip default './'
61
- paths = paths.map { _1.gsub(%r{^\./}, '') } if options[:roots].empty?
58
+ paths = paths.map { _1.gsub(%r{^\./}, "") } if options[:roots].empty?
62
59
  paths
63
60
  end
64
61
 
62
+ def read_payload(path)
63
+ if HTTPDisk::Cache.new(compress: true).send(:compressed?, path)
64
+ Zlib::GzipReader.open(path, encoding: "ASCII-8BIT") { Payload.read(_1) }
65
+ else
66
+ File.open(path, "rb") { Payload.read(_1) }
67
+ end
68
+ rescue
69
+ puts "httpdisk: #{path} not in httpdisk format, skipping" if !options[:silent]
70
+ nil
71
+ end
72
+
65
73
  # convert raw body into something palatable for pattern matching
66
74
  def prepare_body(payload)
67
75
  body = payload.body
68
76
 
69
- if content_type = payload.headers['Content-Type']
77
+ if (content_type = payload.headers["Content-Type"])
70
78
  # Mismatches between Content-Type and body.encoding are fatal, so make
71
79
  # an effort to align them.
72
- if charset = content_type[/charset=([^;]+)/, 1]
80
+ if (charset = content_type[/charset=([^;]+)/, 1])
73
81
  encoding = begin
74
82
  Encoding.find(charset)
75
- rescue StandardError
83
+ rescue
76
84
  nil
77
85
  end
78
86
  if encoding && body.encoding != encoding
79
- body.force_encoding(encoding)
87
+ body = body.dup.force_encoding(encoding)
80
88
  end
81
89
  end
82
90
 
83
91
  # pretty print json for easier searching
84
- if content_type =~ /\bjson\b/
92
+ if /\bjson\b/.match?(content_type)
85
93
  body = JSON.pretty_generate(JSON.parse(body))
86
94
  end
87
95
  end
@@ -96,12 +104,11 @@ module HTTPDisk
96
104
 
97
105
  # printer for output
98
106
  def printer
99
- @printer ||= case
100
- when options[:silent]
107
+ @printer ||= if options[:silent]
101
108
  Grep::SilentPrinter.new
102
- when options[:count]
109
+ elsif options[:count]
103
110
  Grep::CountPrinter.new($stdout)
104
- when options[:head] || $stdout.tty?
111
+ elsif options[:head] || $stdout.tty?
105
112
  Grep::HeaderPrinter.new($stdout, options[:head])
106
113
  else
107
114
  Grep::TersePrinter.new($stdout)
@@ -1,7 +1,7 @@
1
1
  module HTTPDisk
2
2
  module Grep
3
3
  class Printer
4
- GREP_COLOR = '37;45'.freeze
4
+ GREP_COLOR = "37;45"
5
5
 
6
6
  attr_reader :output
7
7
 
@@ -9,7 +9,8 @@ module HTTPDisk
9
9
  @output = output
10
10
  end
11
11
 
12
- def print(path, payload, all_matches); end
12
+ def print(path, payload, all_matches)
13
+ end
13
14
 
14
15
  protected
15
16
 
@@ -18,7 +19,7 @@ module HTTPDisk
18
19
  #
19
20
 
20
21
  def grep_color
21
- @grep_color ||= (ENV['GREP_COLOR'] || GREP_COLOR)
22
+ @grep_color ||= ENV["GREP_COLOR"] || GREP_COLOR
22
23
  end
23
24
 
24
25
  def print_matches(matches)
@@ -30,7 +31,7 @@ module HTTPDisk
30
31
  result << s[ii..._1.begin(0)]
31
32
  result << "\e["
32
33
  result << grep_color
33
- result << 'm'
34
+ result << "m"
34
35
  result << _1[0]
35
36
  result << "\e[0m"
36
37
  ii = _1.end(0)
@@ -1,41 +1,39 @@
1
1
  module HTTPDisk
2
2
  class Payload
3
- class << self
4
- def read(f, peek: false)
5
- Payload.new.tap do |p|
6
- # comment
7
- p.comment = f.gets[/^# (.*)/, 1]
8
-
9
- # status line
10
- m = f.gets.match(/^HTTPDISK (\d+) (.*)$/)
11
- p.status, p.reason_phrase = m[1].to_i, m[2]
12
-
13
- # headers
14
- while (line = f.gets.chomp) && !line.empty?
15
- key, value = line.split(': ', 2)
16
- p.headers[key] = value
17
- end
18
-
19
- # body (if not peeking)
20
- p.body = f.read if !peek
3
+ def self.read(f, peek: false)
4
+ Payload.new.tap do |p|
5
+ # comment
6
+ p.comment = f.gets[/^# (.*)/, 1]
7
+
8
+ # status line
9
+ m = f.gets.match(/^HTTPDISK (\d+) (.*)$/)
10
+ p.status, p.reason_phrase = m[1].to_i, m[2]
11
+
12
+ # headers
13
+ while (line = f.gets.chomp) && !line.empty?
14
+ key, value = line.split(": ", 2)
15
+ p.headers[key] = value
21
16
  end
17
+
18
+ # body (if not peeking)
19
+ p.body = f.read if !peek
22
20
  end
21
+ end
23
22
 
24
- def from_response(response)
25
- Payload.new.tap do
26
- _1.body = response.body
27
- _1.headers = response.headers
28
- _1.reason_phrase = response.reason_phrase
29
- _1.status = response.status
30
- end
23
+ def self.from_response(response)
24
+ Payload.new.tap do
25
+ _1.body = response.body
26
+ _1.headers = response.headers
27
+ _1.reason_phrase = response.reason_phrase
28
+ _1.status = response.status
31
29
  end
32
30
  end
33
31
 
34
32
  attr_accessor :body, :comment, :headers, :reason_phrase, :status
35
33
 
36
34
  def initialize
37
- @body = ''
38
- @comment = ''
35
+ @body = ""
36
+ @comment = ""
39
37
  @headers = Faraday::Utils::Headers.new
40
38
  end
41
39
 
@@ -1,4 +1,4 @@
1
- require 'slop'
1
+ require "slop"
2
2
 
3
3
  module Slop
4
4
  # Custom duration type for Slop, used for --expires. Raises aggressively
@@ -11,13 +11,13 @@ module Slop
11
11
  d: 24 * 60 * 60,
12
12
  w: 7 * 24 * 60 * 60,
13
13
  y: 365 * 7 * 24 * 60 * 60,
14
- }.freeze
14
+ }
15
15
 
16
16
  def call(value)
17
17
  m = value.match(/^(\d+)([smhdwy])?$/)
18
18
  raise Slop::Error, "invalid --expires #{value.inspect}" if !m
19
19
 
20
- num, unit = m[1].to_i, (m[2] || 's').to_sym
20
+ num, unit = m[1].to_i, (m[2] || "s").to_sym
21
21
  num * UNITS[unit]
22
22
  end
23
23
  end
@@ -32,10 +32,10 @@ module HTTPDisk
32
32
 
33
33
  %i[array boolean float hash integer string symbol].each do |method|
34
34
  define_method(method) do |flag, foptions = {}|
35
- on(flag, { type: method }.merge(foptions))
35
+ on(flag, {type: method}.merge(foptions))
36
36
  end
37
37
  end
38
- alias bool boolean
38
+ alias_method :bool, :boolean
39
39
 
40
40
  #
41
41
  # return parsed options
@@ -70,9 +70,7 @@ module HTTPDisk
70
70
 
71
71
  protected
72
72
 
73
- def defaults
74
- flags.map { |flag, foptions| [flag, foptions[:default]] }.to_h.compact
75
- end
73
+ def defaults = flags.transform_values { _1[:default] }.compact
76
74
 
77
75
  # does value match valid?
78
76
  def valid?(value, types)
@@ -96,9 +94,9 @@ module HTTPDisk
96
94
  def error_message(flag, value, valid)
97
95
  classes = valid.compact.map do
98
96
  s = _1.to_s
99
- s = s.downcase if s =~ /\b(Array|Float|Hash|Integer|String|Symbol)\b/
97
+ s = s.downcase if /\b(Array|Float|Hash|Integer|String|Symbol)\b/.match?(s)
100
98
  s
101
- end.join('/')
99
+ end.join("/")
102
100
  "expected :#{flag} to be #{classes}, not #{value.inspect}"
103
101
  end
104
102
  end
@@ -1,3 +1,3 @@
1
1
  module HTTPDisk
2
- VERSION = '0.5.2'.freeze
2
+ VERSION = "1.0.1"
3
3
  end
data/lib/httpdisk.rb CHANGED
@@ -1,17 +1,17 @@
1
- require 'httpdisk/cache_key'
2
- require 'httpdisk/cache'
3
- require 'httpdisk/client'
4
- require 'httpdisk/error'
5
- require 'httpdisk/payload'
6
- require 'httpdisk/slop_duration'
7
- require 'httpdisk/sloptions'
8
- require 'httpdisk/version'
1
+ require "httpdisk/cache_key"
2
+ require "httpdisk/cache"
3
+ require "httpdisk/client"
4
+ require "httpdisk/error"
5
+ require "httpdisk/payload"
6
+ require "httpdisk/slop_duration"
7
+ require "httpdisk/sloptions"
8
+ require "httpdisk/version"
9
9
 
10
10
  # cli
11
- require 'httpdisk/cli/args'
12
- require 'httpdisk/cli/main'
11
+ require "httpdisk/cli/args"
12
+ require "httpdisk/cli/main"
13
13
 
14
14
  # grep
15
- require 'httpdisk/grep/args'
16
- require 'httpdisk/grep/main'
17
- require 'httpdisk/grep/printer'
15
+ require "httpdisk/grep/args"
16
+ require "httpdisk/grep/main"
17
+ require "httpdisk/grep/printer"
data/mise.toml ADDED
@@ -0,0 +1,9 @@
1
+ [env]
2
+ _.path = ['{{config_root}}/bin']
3
+
4
+ [hooks]
5
+ postinstall = ['bundle install']
6
+
7
+ [tools]
8
+ just = "latest"
9
+ ruby = "3.4"
metadata CHANGED
@@ -1,15 +1,42 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: httpdisk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Doppelt
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2021-07-05 00:00:00.000000000 Z
10
+ date: 2026-04-07 00:00:00.000000000 Z
12
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: base64
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '0.3'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '0.3'
26
+ - !ruby/object:Gem::Dependency
27
+ name: cgi
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '0.5'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '0.5'
13
40
  - !ruby/object:Gem::Dependency
14
41
  name: content-type
15
42
  requirement: !ruby/object:Gem::Requirement
@@ -30,14 +57,14 @@ dependencies:
30
57
  requirements:
31
58
  - - "~>"
32
59
  - !ruby/object:Gem::Version
33
- version: '1.4'
60
+ version: '2.14'
34
61
  type: :runtime
35
62
  prerelease: false
36
63
  version_requirements: !ruby/object:Gem::Requirement
37
64
  requirements:
38
65
  - - "~>"
39
66
  - !ruby/object:Gem::Version
40
- version: '1.4'
67
+ version: '2.14'
41
68
  - !ruby/object:Gem::Dependency
42
69
  name: faraday-cookie_jar
43
70
  requirement: !ruby/object:Gem::Requirement
@@ -53,33 +80,47 @@ dependencies:
53
80
  - !ruby/object:Gem::Version
54
81
  version: '0.0'
55
82
  - !ruby/object:Gem::Dependency
56
- name: faraday_middleware
83
+ name: faraday-follow_redirects
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '0.5'
89
+ type: :runtime
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '0.5'
96
+ - !ruby/object:Gem::Dependency
97
+ name: ostruct
57
98
  requirement: !ruby/object:Gem::Requirement
58
99
  requirements:
59
100
  - - "~>"
60
101
  - !ruby/object:Gem::Version
61
- version: '1.0'
102
+ version: '0.6'
62
103
  type: :runtime
63
104
  prerelease: false
64
105
  version_requirements: !ruby/object:Gem::Requirement
65
106
  requirements:
66
107
  - - "~>"
67
108
  - !ruby/object:Gem::Version
68
- version: '1.0'
109
+ version: '0.6'
69
110
  - !ruby/object:Gem::Dependency
70
111
  name: slop
71
112
  requirement: !ruby/object:Gem::Requirement
72
113
  requirements:
73
114
  - - "~>"
74
115
  - !ruby/object:Gem::Version
75
- version: '4.8'
116
+ version: '4.10'
76
117
  type: :runtime
77
118
  prerelease: false
78
119
  version_requirements: !ruby/object:Gem::Requirement
79
120
  requirements:
80
121
  - - "~>"
81
122
  - !ruby/object:Gem::Version
82
- version: '4.8'
123
+ version: '4.10'
83
124
  description: httpdisk works with faraday to aggressively cache responses on disk.
84
125
  email: amd@gurge.com
85
126
  executables:
@@ -90,9 +131,10 @@ extra_rdoc_files: []
90
131
  files:
91
132
  - ".github/workflows/test.yml"
92
133
  - ".gitignore"
134
+ - ".justfile"
93
135
  - ".rubocop.yml"
136
+ - AGENTS.md
94
137
  - Gemfile
95
- - Gemfile.lock
96
138
  - LICENSE
97
139
  - README.md
98
140
  - Rakefile
@@ -115,11 +157,12 @@ files:
115
157
  - lib/httpdisk/sloptions.rb
116
158
  - lib/httpdisk/version.rb
117
159
  - logo.svg
160
+ - mise.toml
118
161
  homepage: http://github.com/gurgeous/httpdisk
119
162
  licenses:
120
163
  - MIT
121
- metadata: {}
122
- post_install_message:
164
+ metadata:
165
+ rubygems_mfa_required: 'true'
123
166
  rdoc_options: []
124
167
  require_paths:
125
168
  - lib
@@ -127,15 +170,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
127
170
  requirements:
128
171
  - - ">="
129
172
  - !ruby/object:Gem::Version
130
- version: 2.7.0
173
+ version: 3.2.0
131
174
  required_rubygems_version: !ruby/object:Gem::Requirement
132
175
  requirements:
133
176
  - - ">="
134
177
  - !ruby/object:Gem::Version
135
178
  version: '0'
136
179
  requirements: []
137
- rubygems_version: 3.1.4
138
- signing_key:
180
+ rubygems_version: 3.6.2
139
181
  specification_version: 4
140
182
  summary: httpdisk - disk cache for faraday
141
183
  test_files: []
data/Gemfile.lock DELETED
@@ -1,101 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- httpdisk (0.5.2)
5
- content-type (~> 0.0)
6
- faraday (~> 1.4)
7
- faraday-cookie_jar (~> 0.0)
8
- faraday_middleware (~> 1.0)
9
- slop (~> 4.8)
10
-
11
- GEM
12
- remote: https://rubygems.org/
13
- specs:
14
- addressable (2.7.0)
15
- public_suffix (>= 2.0.2, < 5.0)
16
- ast (2.4.2)
17
- coderay (1.1.3)
18
- content-type (0.0.1)
19
- parslet (~> 1.5)
20
- crack (0.4.5)
21
- rexml
22
- domain_name (0.5.20190701)
23
- unf (>= 0.0.5, < 1.0.0)
24
- faraday (1.5.0)
25
- faraday-em_http (~> 1.0)
26
- faraday-em_synchrony (~> 1.0)
27
- faraday-excon (~> 1.1)
28
- faraday-httpclient (~> 1.0.1)
29
- faraday-net_http (~> 1.0)
30
- faraday-net_http_persistent (~> 1.1)
31
- faraday-patron (~> 1.0)
32
- multipart-post (>= 1.2, < 3)
33
- ruby2_keywords (>= 0.0.4)
34
- faraday-cookie_jar (0.0.7)
35
- faraday (>= 0.8.0)
36
- http-cookie (~> 1.0.0)
37
- faraday-em_http (1.0.0)
38
- faraday-em_synchrony (1.0.0)
39
- faraday-excon (1.1.0)
40
- faraday-httpclient (1.0.1)
41
- faraday-net_http (1.0.1)
42
- faraday-net_http_persistent (1.1.0)
43
- faraday-patron (1.0.0)
44
- faraday_middleware (1.0.0)
45
- faraday (~> 1.0)
46
- hashdiff (1.0.1)
47
- http-cookie (1.0.4)
48
- domain_name (~> 0.5)
49
- method_source (1.0.0)
50
- minitest (5.14.4)
51
- mocha (1.11.2)
52
- multipart-post (2.1.1)
53
- parallel (1.20.1)
54
- parser (3.0.1.1)
55
- ast (~> 2.4.1)
56
- parslet (1.8.2)
57
- pry (0.13.1)
58
- coderay (~> 1.1)
59
- method_source (~> 1.0)
60
- public_suffix (4.0.6)
61
- rainbow (3.0.0)
62
- rake (13.0.3)
63
- regexp_parser (2.1.1)
64
- rexml (3.2.5)
65
- rubocop (1.13.0)
66
- parallel (~> 1.10)
67
- parser (>= 3.0.0.0)
68
- rainbow (>= 2.2.2, < 4.0)
69
- regexp_parser (>= 1.8, < 3.0)
70
- rexml
71
- rubocop-ast (>= 1.2.0, < 2.0)
72
- ruby-progressbar (~> 1.7)
73
- unicode-display_width (>= 1.4.0, < 3.0)
74
- rubocop-ast (1.5.0)
75
- parser (>= 3.0.1.1)
76
- ruby-progressbar (1.11.0)
77
- ruby2_keywords (0.0.4)
78
- slop (4.9.1)
79
- unf (0.1.4)
80
- unf_ext
81
- unf_ext (0.0.7.7)
82
- unicode-display_width (2.0.0)
83
- webmock (3.12.2)
84
- addressable (>= 2.3.6)
85
- crack (>= 0.3.2)
86
- hashdiff (>= 0.4.0, < 2.0.0)
87
-
88
- PLATFORMS
89
- ruby
90
-
91
- DEPENDENCIES
92
- httpdisk!
93
- minitest
94
- mocha
95
- pry
96
- rake
97
- rubocop (~> 1.13.0)
98
- webmock
99
-
100
- BUNDLED WITH
101
- 2.1.4