api_header_optimizer 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/api_header_optimizer/tester.rb +27 -14
- data/lib/api_header_optimizer/version.rb +1 -1
- data/lib/api_header_optimizer.rb +4 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d70771bd55e301295b8ea91d45ce8272ab7aee7240a59a356873eea37004f63e
|
4
|
+
data.tar.gz: e883e11934321c8f62dd4cbc7cb128bdeff1b109f056fee1f92591f23d3acdd0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d95fda627e12c840fc4f33b1976cbf09d89bcada61086fdf71a4d750da204e4e03508413769582c492e605cf31a30109df0ff253a80618acd06b5e856a919415
|
7
|
+
data.tar.gz: 5bdebb97c62b8c128a7640b367dc3344d1978b95b4e1f85951d72ecb2c446f7dcb878bf0d4a0c72d3ca6d58882acaaf61ddece304544e8f931acd6d95c1db1bf
|
data/README.md
CHANGED
@@ -13,7 +13,7 @@ If bundler is not being used to manage dependencies, install the gem by executin
|
|
13
13
|
## Usage
|
14
14
|
|
15
15
|
This gem allows to extract the headers required in httparty requests.
|
16
|
-
|
16
|
+
If you have some issue with rails c, you can install or update the gem 'globalid'
|
17
17
|
## Development
|
18
18
|
|
19
19
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -9,25 +9,35 @@ module ApiHeaderOptimizer
|
|
9
9
|
@uri = URI(uri)
|
10
10
|
@all_headers = all_headers
|
11
11
|
@results = []
|
12
|
+
@mutex = Mutex.new # Erişim problemlerini önlemek için mutex kullanıyoruz
|
12
13
|
end
|
13
14
|
|
14
15
|
# Tek bir header seti ile istek yapar ve sonucu kontrol eder
|
15
16
|
def test_header_set(header_set)
|
16
17
|
response = make_request(header_set)
|
17
18
|
return unless response # İstek başarısızsa geç
|
18
|
-
|
19
|
+
|
20
|
+
# Sonuçları güvenli bir şekilde eklemek için mutex kullanıyoruz
|
21
|
+
@mutex.synchronize do
|
22
|
+
@results << { headers: header_set, code: response.code, body: response.body }
|
23
|
+
end
|
19
24
|
end
|
20
25
|
|
21
26
|
# Header kombinasyonlarını test eder
|
22
27
|
def test_combinations
|
23
|
-
# Tüm header kombinasyonlarını oluştur ve test et
|
24
28
|
header_keys = @all_headers.keys
|
25
29
|
subsets = ApiHeaderOptimizer::Helpers.subsets(header_keys)
|
26
30
|
|
27
|
-
|
28
|
-
|
29
|
-
|
31
|
+
# Eşzamanlılık için thread'ler oluşturuyoruz
|
32
|
+
threads = subsets.map do |subset|
|
33
|
+
Thread.new do
|
34
|
+
header_set = subset.to_h { |key| [key, @all_headers[key]] }
|
35
|
+
test_header_set(header_set)
|
36
|
+
end
|
30
37
|
end
|
38
|
+
|
39
|
+
# Tüm thread'lerin bitmesini bekliyoruz
|
40
|
+
threads.each(&:join)
|
31
41
|
end
|
32
42
|
|
33
43
|
private
|
@@ -35,15 +45,18 @@ module ApiHeaderOptimizer
|
|
35
45
|
def make_request(headers)
|
36
46
|
http = Net::HTTP.new(@uri.host, @uri.port)
|
37
47
|
http.use_ssl = @uri.scheme == 'https'
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
48
|
+
http.start do |http|
|
49
|
+
headers.each do |header_set|
|
50
|
+
request = Net::HTTP::Get.new(@uri.path)
|
51
|
+
header_set.each { |key, value| request[key] = value }
|
52
|
+
begin
|
53
|
+
response = http.request(request)
|
54
|
+
return response if response.code.to_i.between?(200, 299) # Başarılı yanıtlar
|
55
|
+
rescue => e
|
56
|
+
puts "Request failed: #{e.message}"
|
57
|
+
return nil
|
58
|
+
end
|
59
|
+
end
|
47
60
|
end
|
48
61
|
end
|
49
62
|
end
|
data/lib/api_header_optimizer.rb
CHANGED
@@ -6,6 +6,8 @@ require_relative "api_header_optimizer/optimizer"
|
|
6
6
|
require_relative "api_header_optimizer/tester"
|
7
7
|
|
8
8
|
module ApiHeaderOptimizer
|
9
|
-
|
10
|
-
|
9
|
+
def self.optimize(address_url, headers)
|
10
|
+
optimizer = Optimizer.new(address_url, headers)
|
11
|
+
optimizer.optimize
|
12
|
+
end
|
11
13
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_header_optimizer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ziya Gökalp
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-09-
|
11
|
+
date: 2024-09-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: net-http
|