baza.rb 0.11.1 → 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 +4 -4
- data/Gemfile +1 -1
- data/Gemfile.lock +2 -2
- data/lib/baza-rb/version.rb +1 -1
- data/lib/baza-rb.rb +46 -11
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: aece820f0bfcb187819d97ca24d4585f7831c6f48a1548bff802b7a504f760b5
|
|
4
|
+
data.tar.gz: 03d8f7403e8c590224d3bbdae1ed90ed7149d6210750718fa644b0d56807796a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 61f1d9d1008111fe1e66c07f187e0de5f63ae1b9c1d905000e8588b37c82f43fbdaf4e6220553b0c131b68e500c1a2ce7219357bd97f745de1f88700a6869ffc
|
|
7
|
+
data.tar.gz: 05006bd92cc3e363b511237c44b5ba4b7048f5f2ab4c5e22d3bac9ee8188bb95fb6b7bc693b35ed44f94afc740b910fd96a732185a3e7a73865302d50a0b6db8
|
data/Gemfile
CHANGED
|
@@ -18,7 +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.
|
|
21
|
+
gem 'rdoc', '6.16.1', require: false # GPL
|
|
22
22
|
gem 'rubocop', '~>1.73', require: false
|
|
23
23
|
gem 'rubocop-minitest', '~>0.38', require: false
|
|
24
24
|
gem 'rubocop-performance', '~>1.23', require: false
|
data/Gemfile.lock
CHANGED
|
@@ -128,7 +128,7 @@ GEM
|
|
|
128
128
|
rake (13.3.1)
|
|
129
129
|
random-port (0.7.6)
|
|
130
130
|
tago (~> 0.0)
|
|
131
|
-
rdoc (6.16.
|
|
131
|
+
rdoc (6.16.1)
|
|
132
132
|
erb
|
|
133
133
|
psych (>= 4.0.0)
|
|
134
134
|
tsort
|
|
@@ -221,7 +221,7 @@ DEPENDENCIES
|
|
|
221
221
|
rackup (~> 2.2)
|
|
222
222
|
rake (~> 13.2)
|
|
223
223
|
random-port (~> 0.7)
|
|
224
|
-
rdoc (= 6.16.
|
|
224
|
+
rdoc (= 6.16.1)
|
|
225
225
|
rubocop (~> 1.73)
|
|
226
226
|
rubocop-minitest (~> 0.38)
|
|
227
227
|
rubocop-performance (~> 1.23)
|
data/lib/baza-rb/version.rb
CHANGED
data/lib/baza-rb.rb
CHANGED
|
@@ -580,6 +580,34 @@ class BazaRb
|
|
|
580
580
|
|
|
581
581
|
private
|
|
582
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
|
+
|
|
583
611
|
# Get the user agent string for HTTP requests.
|
|
584
612
|
#
|
|
585
613
|
# @return [String] The user agent string
|
|
@@ -707,22 +735,27 @@ class BazaRb
|
|
|
707
735
|
@loog.debug(log)
|
|
708
736
|
return ret
|
|
709
737
|
end
|
|
710
|
-
@loog.debug("#{log}\n #{(ret.headers || {}).map { |k, v| "#{k}: #{v}" }.join("\n ")}")
|
|
711
738
|
headers = ret.headers || {}
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
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?
|
|
717
754
|
case ret.code
|
|
718
|
-
when 500
|
|
755
|
+
when 500, 503
|
|
719
756
|
msg +=
|
|
720
757
|
", most probably it's an internal error on the server, " \
|
|
721
758
|
'please report this to https://github.com/zerocracy/baza.rb'
|
|
722
|
-
when 503
|
|
723
|
-
msg +=
|
|
724
|
-
", most probably it's an internal error on the server (#{headers['X-Zerocracy-Failure'].inspect}), " \
|
|
725
|
-
'please report this to https://github.com/zerocracy/baza.rb'
|
|
726
759
|
when 404
|
|
727
760
|
msg +=
|
|
728
761
|
", most probably you are trying to reach a wrong server, which doesn't " \
|
|
@@ -829,6 +862,7 @@ class BazaRb
|
|
|
829
862
|
("ranged as #{ret.headers['Content-Range'].inspect}" if ret.headers['Content-Range'])
|
|
830
863
|
]
|
|
831
864
|
ret = checked(ret, [200, 206, 204, 302])
|
|
865
|
+
uri = stick_host(ret, uri)
|
|
832
866
|
if blanks.include?(ret.code)
|
|
833
867
|
sleep(2)
|
|
834
868
|
next
|
|
@@ -908,6 +942,7 @@ class BazaRb
|
|
|
908
942
|
end
|
|
909
943
|
)
|
|
910
944
|
end
|
|
945
|
+
uri = stick_host(ret, uri)
|
|
911
946
|
sent += params[:body].bytesize
|
|
912
947
|
@loog.debug(
|
|
913
948
|
[
|