baza.rb 0.11.0 → 0.11.2

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: c3f6b8fd3d4ae976677a1b3307a3c5c3279b61aae5469ffb0f113103dae1c8b5
4
- data.tar.gz: 6954c6b824ac00e1951b6dc43cc4ee0824739f7a73370599cd4ac5a1081a885d
3
+ metadata.gz: aece820f0bfcb187819d97ca24d4585f7831c6f48a1548bff802b7a504f760b5
4
+ data.tar.gz: 03d8f7403e8c590224d3bbdae1ed90ed7149d6210750718fa644b0d56807796a
5
5
  SHA512:
6
- metadata.gz: 5eccf68db6789c2e02861917eb036c6da42970182c2d92dfbf2d1c646c193e29479e2eadc11ca1eadf1cb3ea24bdfd95397f194771496a275d2d80b9dc641f4a
7
- data.tar.gz: d229ff82c8c01651d5dc5c46f62c4b373651624e91c8a126de8888ec098c30374fad72254c86998c4a5c5f16a9f6fb09e03c29be1fd6d0fd7f14855d64fbf6f8
6
+ metadata.gz: 61f1d9d1008111fe1e66c07f187e0de5f63ae1b9c1d905000e8588b37c82f43fbdaf4e6220553b0c131b68e500c1a2ce7219357bd97f745de1f88700a6869ffc
7
+ data.tar.gz: 05006bd92cc3e363b511237c44b5ba4b7048f5f2ab4c5e22d3bac9ee8188bb95fb6b7bc693b35ed44f94afc740b910fd96a732185a3e7a73865302d50a0b6db8
data/Gemfile CHANGED
@@ -18,6 +18,7 @@ gem 'rack', '~>3.1', require: false
18
18
  gem 'rackup', '~>2.2', require: false
19
19
  gem 'rake', '~>13.2', require: false
20
20
  gem 'random-port', '~>0.7', require: false
21
+ gem 'rdoc', '6.16.1', require: false # GPL
21
22
  gem 'rubocop', '~>1.73', require: false
22
23
  gem 'rubocop-minitest', '~>0.38', require: false
23
24
  gem 'rubocop-performance', '~>1.23', require: false
data/Gemfile.lock CHANGED
@@ -17,26 +17,28 @@ PATH
17
17
  GEM
18
18
  remote: https://rubygems.org/
19
19
  specs:
20
- addressable (2.8.7)
21
- public_suffix (>= 2.0.2, < 7.0)
20
+ addressable (2.8.8)
21
+ public_suffix (>= 2.0.2, < 8.0)
22
22
  ansi (1.5.0)
23
23
  ast (2.4.3)
24
24
  backtrace (0.4.1)
25
25
  base64 (0.3.0)
26
- bigdecimal (3.2.3)
26
+ bigdecimal (3.3.1)
27
27
  builder (3.3.0)
28
- crack (1.0.0)
28
+ crack (1.0.1)
29
29
  bigdecimal
30
30
  rexml
31
+ date (3.5.0)
31
32
  decoor (0.1.0)
32
33
  docile (1.4.1)
33
34
  elapsed (0.2.0)
34
35
  loog (~> 0.6)
35
36
  tago (~> 0.1)
36
37
  ellipsized (0.3.0)
38
+ erb (6.0.0)
37
39
  ethon (0.15.0)
38
40
  ffi (>= 1.15.0)
39
- factbase (0.16.7)
41
+ factbase (0.17.0)
40
42
  backtrace (~> 0.4)
41
43
  decoor (~> 0.1)
42
44
  ellipsized (~> 0.3)
@@ -47,7 +49,7 @@ GEM
47
49
  others (~> 0.1)
48
50
  tago (~> 0.1)
49
51
  yaml (~> 0.3)
50
- faraday (2.13.4)
52
+ faraday (2.14.0)
51
53
  faraday-net_http (>= 2.0, < 3.5)
52
54
  json
53
55
  logger
@@ -55,8 +57,8 @@ GEM
55
57
  faraday (>= 0.8)
56
58
  faraday-multipart (1.1.1)
57
59
  multipart-post (~> 2.0)
58
- faraday-net_http (3.4.1)
59
- net-http (>= 0.5.0)
60
+ faraday-net_http (3.4.2)
61
+ net-http (~> 0.5)
60
62
  faraday-retry (2.3.2)
61
63
  faraday (~> 2.0)
62
64
  ffi (1.17.2-arm64-darwin)
@@ -64,14 +66,14 @@ GEM
64
66
  ffi (1.17.2-x86_64-darwin)
65
67
  ffi (1.17.2-x86_64-linux-gnu)
66
68
  hashdiff (1.2.1)
67
- iri (0.11.2)
68
- json (2.15.0)
69
+ iri (0.11.3)
70
+ json (2.16.0)
69
71
  language_server-protocol (3.17.0.5)
70
72
  lint_roller (1.1.0)
71
73
  logger (1.7.0)
72
74
  loog (0.6.1)
73
75
  logger (~> 1.0)
74
- minitest (5.25.5)
76
+ minitest (5.26.2)
75
77
  minitest-reporters (1.7.1)
76
78
  ansi
77
79
  builder
@@ -80,9 +82,9 @@ GEM
80
82
  multipart-post (2.4.1)
81
83
  mustermann (3.0.4)
82
84
  ruby2_keywords (~> 0.0.1)
83
- net-http (0.6.0)
84
- uri
85
- nio4r (2.7.4)
85
+ net-http (0.8.0)
86
+ uri (>= 0.11.1)
87
+ nio4r (2.7.5)
86
88
  nokogiri (1.18.10-arm64-darwin)
87
89
  racc (~> 1.4)
88
90
  nokogiri (1.18.10-x64-mingw-ucrt)
@@ -96,21 +98,24 @@ GEM
96
98
  os (1.1.4)
97
99
  others (0.1.1)
98
100
  parallel (1.27.0)
99
- parser (3.3.9.0)
101
+ parser (3.3.10.0)
100
102
  ast (~> 2.4.1)
101
103
  racc
102
- prism (1.5.1)
103
- public_suffix (6.0.2)
104
- puma (7.0.3)
104
+ prism (1.6.0)
105
+ psych (5.2.6)
106
+ date
107
+ stringio
108
+ public_suffix (7.0.0)
109
+ puma (7.1.0)
105
110
  nio4r (~> 2.0)
106
- qbash (0.4.5)
111
+ qbash (0.4.8)
107
112
  backtrace (> 0)
108
113
  elapsed (> 0)
109
114
  loog (> 0)
110
115
  tago (> 0)
111
116
  racc (1.8.1)
112
- rack (3.2.1)
113
- rack-protection (4.1.1)
117
+ rack (3.2.4)
118
+ rack-protection (4.2.1)
114
119
  base64 (>= 0.1.0)
115
120
  logger (>= 1.6.0)
116
121
  rack (>= 3.0.0, < 4)
@@ -120,13 +125,17 @@ GEM
120
125
  rackup (2.2.1)
121
126
  rack (>= 3)
122
127
  rainbow (3.1.1)
123
- rake (13.3.0)
128
+ rake (13.3.1)
124
129
  random-port (0.7.6)
125
130
  tago (~> 0.0)
131
+ rdoc (6.16.1)
132
+ erb
133
+ psych (>= 4.0.0)
134
+ tsort
126
135
  regexp_parser (2.11.3)
127
136
  retries (0.0.5)
128
137
  rexml (3.4.4)
129
- rubocop (1.80.2)
138
+ rubocop (1.81.7)
130
139
  json (~> 2.3)
131
140
  language_server-protocol (~> 3.17.0.2)
132
141
  lint_roller (~> 1.1.0)
@@ -134,20 +143,20 @@ GEM
134
143
  parser (>= 3.3.0.2)
135
144
  rainbow (>= 2.2.2, < 4.0)
136
145
  regexp_parser (>= 2.9.3, < 3.0)
137
- rubocop-ast (>= 1.46.0, < 2.0)
146
+ rubocop-ast (>= 1.47.1, < 2.0)
138
147
  ruby-progressbar (~> 1.7)
139
148
  unicode-display_width (>= 2.4.0, < 4.0)
140
- rubocop-ast (1.47.1)
149
+ rubocop-ast (1.48.0)
141
150
  parser (>= 3.3.7.2)
142
151
  prism (~> 1.4)
143
152
  rubocop-minitest (0.38.2)
144
153
  lint_roller (~> 1.1)
145
154
  rubocop (>= 1.75.0, < 2.0)
146
155
  rubocop-ast (>= 1.38.0, < 2.0)
147
- rubocop-performance (1.26.0)
156
+ rubocop-performance (1.26.1)
148
157
  lint_roller (~> 1.1)
149
158
  rubocop (>= 1.75.0, < 2.0)
150
- rubocop-ast (>= 1.44.0, < 2.0)
159
+ rubocop-ast (>= 1.47.1, < 2.0)
151
160
  rubocop-rake (0.7.1)
152
161
  lint_roller (~> 1.1)
153
162
  rubocop (>= 1.72.1)
@@ -162,28 +171,30 @@ GEM
162
171
  simplecov (~> 0.19)
163
172
  simplecov-html (0.13.2)
164
173
  simplecov_json_formatter (0.1.4)
165
- sinatra (4.1.1)
174
+ sinatra (4.2.1)
166
175
  logger (>= 1.6.0)
167
176
  mustermann (~> 3.0)
168
177
  rack (>= 3.0.0, < 4)
169
- rack-protection (= 4.1.1)
178
+ rack-protection (= 4.2.1)
170
179
  rack-session (>= 2.0.0, < 3)
171
180
  tilt (~> 2.0)
172
- tago (0.2.0)
181
+ stringio (3.1.8)
182
+ tago (0.4.0)
173
183
  tilt (2.6.1)
174
- timeout (0.4.3)
184
+ timeout (0.4.4)
185
+ tsort (0.2.0)
175
186
  typhoeus (1.5.0)
176
187
  ethon (>= 0.9.0, < 0.16.0)
177
188
  unicode-display_width (3.2.0)
178
189
  unicode-emoji (~> 4.1)
179
190
  unicode-emoji (4.1.0)
180
- uri (1.0.3)
191
+ uri (1.1.1)
181
192
  wait_for (0.1.1)
182
- webmock (3.25.1)
193
+ webmock (3.26.1)
183
194
  addressable (>= 2.8.0)
184
195
  crack (>= 0.3.2)
185
196
  hashdiff (>= 0.4.0, < 2.0.0)
186
- webrick (1.9.1)
197
+ webrick (1.9.2)
187
198
  yaml (0.4.0)
188
199
  yard (0.9.37)
189
200
 
@@ -210,6 +221,7 @@ DEPENDENCIES
210
221
  rackup (~> 2.2)
211
222
  rake (~> 13.2)
212
223
  random-port (~> 0.7)
224
+ rdoc (= 6.16.1)
213
225
  rubocop (~> 1.73)
214
226
  rubocop-minitest (~> 0.38)
215
227
  rubocop-performance (~> 1.23)
data/Rakefile CHANGED
@@ -48,6 +48,7 @@ require 'yard'
48
48
  desc 'Build Yard documentation'
49
49
  YARD::Rake::YardocTask.new do |t|
50
50
  t.files = ['lib/**/*.rb']
51
+ t.options = ['--fail-on-warning']
51
52
  end
52
53
 
53
54
  require 'rubocop/rake_task'
@@ -13,5 +13,5 @@
13
13
  # Copyright:: Copyright (c) 2024-2025 Yegor Bugayenko
14
14
  # License:: MIT
15
15
  class BazaRb
16
- VERSION = '0.11.0'
16
+ VERSION = '0.11.2'
17
17
  end
data/lib/baza-rb.rb CHANGED
@@ -7,6 +7,7 @@ require 'base64'
7
7
  require 'elapsed'
8
8
  require 'fileutils'
9
9
  require 'iri'
10
+ require 'logger'
10
11
  require 'loog'
11
12
  require 'retries'
12
13
  require 'stringio'
@@ -78,7 +79,7 @@ class BazaRb
78
79
  # @raise [ServerFailure] If authentication fails or server returns an error
79
80
  def whoami
80
81
  nick = nil
81
- elapsed(@loog) do
82
+ elapsed(@loog, level: Logger::INFO) do
82
83
  ret = get(home.append('whoami'))
83
84
  nick = ret.body
84
85
  throw :"I know that I am @#{nick}, at #{@host}"
@@ -92,7 +93,7 @@ class BazaRb
92
93
  # @raise [ServerFailure] If authentication fails or server returns an error
93
94
  def balance
94
95
  z = nil
95
- elapsed(@loog) do
96
+ elapsed(@loog, level: Logger::INFO) do
96
97
  ret = get(home.append('account').append('balance'))
97
98
  z = ret.body.to_f
98
99
  throw :"The balance is Ƶ#{z}, at #{@host}"
@@ -102,7 +103,7 @@ class BazaRb
102
103
 
103
104
  # Push factbase to the server to create a new job.
104
105
  #
105
- # @param [String] name The unique name of the product on the server
106
+ # @param [String] pname The unique name of the product on the server
106
107
  # @param [String] data The binary data to push to the server (factbase content)
107
108
  # @param [Array<String>] meta List of metadata strings to attach to the job
108
109
  # @param [Integer] chunk_size Maximum size of one chunk
@@ -112,7 +113,7 @@ class BazaRb
112
113
  raise 'The "name" of the job may not be empty' if pname.empty?
113
114
  raise 'The "data" of the job is nil' if data.nil?
114
115
  raise 'The "meta" of the job is nil' if meta.nil?
115
- elapsed(@loog) do
116
+ elapsed(@loog, level: Logger::INFO) do
116
117
  Tempfile.open do |file|
117
118
  File.binwrite(file.path, data)
118
119
  upload(
@@ -137,7 +138,7 @@ class BazaRb
137
138
  raise 'The ID of the job is nil' if id.nil?
138
139
  raise 'The ID of the job must be a positive integer' unless id.positive?
139
140
  data = ''
140
- elapsed(@loog) do
141
+ elapsed(@loog, level: Logger::INFO) do
141
142
  Tempfile.open do |file|
142
143
  download(home.append('pull').append("#{id}.fb"), file.path)
143
144
  data = File.binread(file)
@@ -156,7 +157,7 @@ class BazaRb
156
157
  raise 'The ID of the job is nil' if id.nil?
157
158
  raise 'The ID of the job must be a positive integer' unless id.positive?
158
159
  fin = false
159
- elapsed(@loog) do
160
+ elapsed(@loog, level: Logger::INFO) do
160
161
  ret = get(home.append('finished').append(id))
161
162
  fin = ret.body == 'yes'
162
163
  throw :"The job ##{id} is #{'not yet ' unless fin}finished at #{@host}#{" (#{ret.body.inspect})" unless fin}"
@@ -173,7 +174,7 @@ class BazaRb
173
174
  raise 'The ID of the job is nil' if id.nil?
174
175
  raise 'The ID of the job must be a positive integer' unless id.positive?
175
176
  stdout = ''
176
- elapsed(@loog) do
177
+ elapsed(@loog, level: Logger::INFO) do
177
178
  ret = get(home.append('stdout').append("#{id}.txt"))
178
179
  stdout = ret.body
179
180
  throw :"The stdout of the job ##{id} has #{stdout.split("\n").count} lines"
@@ -190,7 +191,7 @@ class BazaRb
190
191
  raise 'The ID of the job is nil' if id.nil?
191
192
  raise 'The ID of the job must be a positive integer' unless id.positive?
192
193
  code = 0
193
- elapsed(@loog) do
194
+ elapsed(@loog, level: Logger::INFO) do
194
195
  ret = get(home.append('exit').append("#{id}.txt"))
195
196
  code = ret.body.to_i
196
197
  throw :"The exit code of the job ##{id} is #{code}"
@@ -207,7 +208,7 @@ class BazaRb
207
208
  raise 'The ID of the job is nil' if id.nil?
208
209
  raise 'The ID of the job must be a positive integer' unless id.positive?
209
210
  verdict = ''
210
- elapsed(@loog) do
211
+ elapsed(@loog, level: Logger::INFO) do
211
212
  ret = get(home.append('jobs').append(id).append('verified.txt'))
212
213
  verdict = ret.body
213
214
  throw :"The verdict of the job ##{id} is #{verdict.inspect}"
@@ -225,7 +226,7 @@ class BazaRb
225
226
  raise 'The "pname" of the product is nil' if pname.nil?
226
227
  raise 'The "pname" of the product may not be empty' if pname.empty?
227
228
  raise 'The "owner" of the lock is nil' if owner.nil?
228
- elapsed(@loog) do
229
+ elapsed(@loog, level: Logger::INFO) do
229
230
  ret = post(
230
231
  home.append('lock').append(pname),
231
232
  { 'owner' => owner },
@@ -246,7 +247,7 @@ class BazaRb
246
247
  raise 'The "pname" of the job may not be empty' if pname.empty?
247
248
  raise 'The "owner" of the lock is nil' if owner.nil?
248
249
  raise 'The "owner" of the lock may not be empty' if owner.empty?
249
- elapsed(@loog) do
250
+ elapsed(@loog, level: Logger::INFO) do
250
251
  post(
251
252
  home.append('unlock').append(pname),
252
253
  { 'owner' => owner }
@@ -264,7 +265,7 @@ class BazaRb
264
265
  raise 'The "name" of the job is nil' if name.nil?
265
266
  raise 'The "name" of the job may not be empty' if name.empty?
266
267
  job = nil
267
- elapsed(@loog) do
268
+ elapsed(@loog, level: Logger::INFO) do
268
269
  ret = get(home.append('recent').append("#{name}.txt"))
269
270
  job = ret.body.to_i
270
271
  throw :"The recent \"#{name}\" job's ID is ##{job} at #{@host}"
@@ -274,13 +275,13 @@ class BazaRb
274
275
 
275
276
  # Check whether the name of the job exists on the server.
276
277
  #
277
- # @param [String] name The name of the product on the server
278
+ # @param [String] pname The name of the product on the server
278
279
  # @return [Boolean] TRUE if such name exists
279
280
  def name_exists?(pname)
280
281
  raise 'The "pname" of the product is nil' if pname.nil?
281
282
  raise 'The "pname" of the product may not be empty' if pname.empty?
282
283
  exists = false
283
- elapsed(@loog) do
284
+ elapsed(@loog, level: Logger::INFO) do
284
285
  ret = get(home.append('exists').append(pname))
285
286
  exists = ret.body == 'yes'
286
287
  throw :"The name #{pname.inspect} #{exists ? 'exists' : "doesn't exist"} at #{@host}"
@@ -308,7 +309,7 @@ class BazaRb
308
309
  raise "The file '#{file}' is too big (#{File.size(file)} bytes) for durable_place(), use durable_save() instead"
309
310
  end
310
311
  id = nil
311
- elapsed(@loog) do
312
+ elapsed(@loog, level: Logger::INFO) do
312
313
  ret = post(
313
314
  home.append('durables').append('place'),
314
315
  {
@@ -336,7 +337,7 @@ class BazaRb
336
337
  raise 'The ID of the durable must be a positive integer' unless id.positive?
337
338
  raise 'The "file" of the durable is nil' if file.nil?
338
339
  raise "The file '#{file}' is absent" unless File.exist?(file)
339
- elapsed(@loog) do
340
+ elapsed(@loog, level: Logger::INFO) do
340
341
  upload(home.append('durables').append(id), file, chunk_size:)
341
342
  throw :"Durable ##{id} saved #{File.size(file)} bytes to #{@host}"
342
343
  end
@@ -352,7 +353,7 @@ class BazaRb
352
353
  raise 'The ID of the durable must be an Integer' unless id.is_a?(Integer)
353
354
  raise 'The ID of the durable must be a positive integer' unless id.positive?
354
355
  raise 'The "file" of the durable is nil' if file.nil?
355
- elapsed(@loog) do
356
+ elapsed(@loog, level: Logger::INFO) do
356
357
  download(home.append('durables').append(id), file)
357
358
  throw :"Durable ##{id} loaded #{File.size(file)} bytes from #{@host}"
358
359
  end
@@ -369,7 +370,7 @@ class BazaRb
369
370
  raise 'The ID of the durable must be a positive integer' unless id.positive?
370
371
  raise 'The "owner" of the lock is nil' if owner.nil?
371
372
  raise 'The "owner" of the lock may not be empty' if owner.empty?
372
- elapsed(@loog) do
373
+ elapsed(@loog, level: Logger::INFO) do
373
374
  post(
374
375
  home.append('durables').append(id).append('lock'),
375
376
  { 'owner' => owner }
@@ -389,7 +390,7 @@ class BazaRb
389
390
  raise 'The ID of the durable must be a positive integer' unless id.positive?
390
391
  raise 'The "owner" of the lock is nil' if owner.nil?
391
392
  raise 'The "owner" of the lock may not be empty' if owner.empty?
392
- elapsed(@loog) do
393
+ elapsed(@loog, level: Logger::INFO) do
393
394
  post(
394
395
  home.append('durables').append(id).append('unlock'),
395
396
  { 'owner' => owner }
@@ -409,7 +410,7 @@ class BazaRb
409
410
  raise 'The "file" is nil' if file.nil?
410
411
  raise 'The "file" may not be empty' if file.empty?
411
412
  id = nil
412
- elapsed(@loog) do
413
+ elapsed(@loog, level: Logger::INFO) do
413
414
  ret = get(home.append('durables').append('find').add(jname: pname, pname:, file:), [200, 404])
414
415
  if ret.code == 200
415
416
  id = ret.body.to_i
@@ -441,7 +442,7 @@ class BazaRb
441
442
  'summary' => summary
442
443
  }
443
444
  body['job'] = job unless job.nil?
444
- elapsed(@loog) do
445
+ elapsed(@loog, level: Logger::INFO) do
445
446
  ret = post(
446
447
  home.append('account').append('transfer'),
447
448
  body
@@ -468,7 +469,7 @@ class BazaRb
468
469
  raise 'The "job" must be Integer' unless job.is_a?(Integer)
469
470
  raise 'The "summary" is nil' if summary.nil?
470
471
  id = nil
471
- elapsed(@loog) do
472
+ elapsed(@loog, level: Logger::INFO) do
472
473
  ret = post(
473
474
  home.append('account').append('fee'),
474
475
  {
@@ -492,7 +493,7 @@ class BazaRb
492
493
  # @raise [ServerFailure] If the pop operation fails
493
494
  def pop(owner, zip)
494
495
  success = false
495
- elapsed(@loog) do
496
+ elapsed(@loog, level: Logger::INFO) do
496
497
  uri = home.append('pop').add(owner:)
497
498
  ret = get(uri, [204, 302])
498
499
  if ret.code == 204
@@ -519,7 +520,7 @@ class BazaRb
519
520
  raise 'The ID of the job must be a positive integer' unless id.positive?
520
521
  raise 'The "zip" of the job is nil' if zip.nil?
521
522
  raise "The 'zip' file is absent: #{zip}" unless File.exist?(zip)
522
- elapsed(@loog) do
523
+ elapsed(@loog, level: Logger::INFO) do
523
524
  upload(home.append('finish').add(id:), zip)
524
525
  throw :"Pushed #{File.size(zip)} bytes to #{@host}, finished job ##{id}"
525
526
  end
@@ -531,7 +532,7 @@ class BazaRb
531
532
  # for the given badge already exists, it's returned. Otherwise, the block
532
533
  # is executed and its result is cached.
533
534
  #
534
- # @param [String] name Name of the product
535
+ # @param [String] pname Name of the product
535
536
  # @param [String] badge Unique identifier for this valve/computation
536
537
  # @param [String] why The reason/description for entering this valve
537
538
  # @param [nil|Integer] job Optional job ID to associate with this valve
@@ -570,7 +571,7 @@ class BazaRb
570
571
  # @raise [ServerFailure] If token retrieval fails
571
572
  def csrf
572
573
  token = nil
573
- elapsed(@loog) do
574
+ elapsed(@loog, level: Logger::INFO) do
574
575
  token = get(home.append('csrf')).body
575
576
  throw :"CSRF token retrieved (#{token.length} chars)"
576
577
  end
@@ -579,6 +580,34 @@ class BazaRb
579
580
 
580
581
  private
581
582
 
583
+ # Stick host from X-Zerocracy-Host header if present.
584
+ #
585
+ # @param [Typhoeus::Response] ret The HTTP response containing headers
586
+ # @param [Iri] uri The current URI object to update
587
+ # @return [Iri] The updated URI object (or original if no valid header present)
588
+ # @note Invalid hostnames are logged as warnings and ignored
589
+ def stick_host(ret, uri)
590
+ sticky = ret.headers && ret.headers['X-Zerocracy-Host']
591
+ return uri unless sticky
592
+ return uri unless hostname?(sticky)
593
+ new_host = sticky.strip.chomp('.')
594
+ if new_host != @host
595
+ @loog.debug("Switching host from #{@host} to #{new_host} as per X-Zerocracy-Host")
596
+ @host = new_host
597
+ end
598
+ uri.host(@host)
599
+ end
600
+
601
+ # Validate hostname format according to RFC 1123.
602
+ #
603
+ # @param [String] name The hostname to validate
604
+ # @return [Boolean] True if valid, false otherwise
605
+ def hostname?(name)
606
+ name = name.strip
607
+ return false if name.empty? || name.bytesize > 253
608
+ name.match?(/\A[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*\.?\z/)
609
+ end
610
+
582
611
  # Get the user agent string for HTTP requests.
583
612
  #
584
613
  # @return [String] The user agent string
@@ -706,22 +735,27 @@ class BazaRb
706
735
  @loog.debug(log)
707
736
  return ret
708
737
  end
709
- @loog.debug("#{log}\n #{(ret.headers || {}).map { |k, v| "#{k}: #{v}" }.join("\n ")}")
710
738
  headers = ret.headers || {}
711
- msg = [
712
- "Invalid response code ##{ret.code} ",
713
- "at #{mtd} #{url}",
714
- headers['X-Zerocracy-Flash'] ? " (#{headers['X-Zerocracy-Flash'].inspect})" : ''
715
- ].join
739
+ if headers.any?
740
+ @loog.error(
741
+ "#{log}\n" +
742
+ headers.map { |k, v| " #{k}: #{v}" }.join("\n")
743
+ )
744
+ else
745
+ @loog.error("#{log}\n (no headers returned)")
746
+ end
747
+ details = [
748
+ ("Flash: #{headers['X-Zerocracy-Flash']}" if headers['X-Zerocracy-Flash']),
749
+ ("Failure: #{headers['X-Zerocracy-Failure']}" if headers['X-Zerocracy-Failure']),
750
+ ("FailureMark: #{headers['X-Zerocracy-FailureMark']}" if headers['X-Zerocracy-FailureMark'])
751
+ ].compact
752
+ msg = "Invalid response code ##{ret.code} at #{mtd} #{url}"
753
+ msg += " (#{details.join(', ')})" unless details.empty?
716
754
  case ret.code
717
- when 500
755
+ when 500, 503
718
756
  msg +=
719
757
  ", most probably it's an internal error on the server, " \
720
758
  'please report this to https://github.com/zerocracy/baza.rb'
721
- when 503
722
- msg +=
723
- ", most probably it's an internal error on the server (#{headers['X-Zerocracy-Failure'].inspect}), " \
724
- 'please report this to https://github.com/zerocracy/baza.rb'
725
759
  when 404
726
760
  msg +=
727
761
  ", most probably you are trying to reach a wrong server, which doesn't " \
@@ -794,7 +828,7 @@ class BazaRb
794
828
  FileUtils.touch(file)
795
829
  chunk = 0
796
830
  blanks = [204, 302]
797
- elapsed(@loog) do
831
+ elapsed(@loog, level: Logger::INFO) do
798
832
  loop do
799
833
  slice = ''
800
834
  ret = nil
@@ -828,6 +862,7 @@ class BazaRb
828
862
  ("ranged as #{ret.headers['Content-Range'].inspect}" if ret.headers['Content-Range'])
829
863
  ]
830
864
  ret = checked(ret, [200, 206, 204, 302])
865
+ uri = stick_host(ret, uri)
831
866
  if blanks.include?(ret.code)
832
867
  sleep(2)
833
868
  next
@@ -879,7 +914,7 @@ class BazaRb
879
914
  total = File.size(file)
880
915
  chunk = 0
881
916
  sent = 0
882
- elapsed(@loog) do
917
+ elapsed(@loog, level: Logger::INFO) do
883
918
  loop do
884
919
  slice =
885
920
  if total > chunk_size
@@ -907,6 +942,7 @@ class BazaRb
907
942
  end
908
943
  )
909
944
  end
945
+ uri = stick_host(ret, uri)
910
946
  sent += params[:body].bytesize
911
947
  @loog.debug(
912
948
  [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: baza.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.11.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko