api_header_optimizer 0.1.1 → 0.1.2

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: e08e6943ab506fcbb3a6291b5029aeae8b6e492289c69e381b1dd3e4c2b0736b
4
- data.tar.gz: d98223a148a2f61d8b5b33d046acafe35e24a7f0b4f6f48ac11348b331820c27
3
+ metadata.gz: d70771bd55e301295b8ea91d45ce8272ab7aee7240a59a356873eea37004f63e
4
+ data.tar.gz: e883e11934321c8f62dd4cbc7cb128bdeff1b109f056fee1f92591f23d3acdd0
5
5
  SHA512:
6
- metadata.gz: b24e481b9b05036c70a187df5d7d2697308251c111a2d2bcd5db8eeec7e98ef14daf0767142c8de7cd6f5efe2958b43b7dc10e87c4be190a08e7ef1195a76e86
7
- data.tar.gz: 3da59497ec38a9046a750a1648926e784fe4639ed5a17ec9ca7c528a0fd7dbc896f8db12f6b0ba23a99c718e1bea4c7b7eedb3c80232be4d4114eb2e72e73c77
6
+ metadata.gz: d95fda627e12c840fc4f33b1976cbf09d89bcada61086fdf71a4d750da204e4e03508413769582c492e605cf31a30109df0ff253a80618acd06b5e856a919415
7
+ data.tar.gz: 5bdebb97c62b8c128a7640b367dc3344d1978b95b4e1f85951d72ecb2c446f7dcb878bf0d4a0c72d3ca6d58882acaaf61ddece304544e8f931acd6d95c1db1bf
@@ -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
- @results << { headers: header_set, code: response.code, body: response.body }
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
- subsets.each do |subset|
28
- header_set = subset.to_h { |key| [key, @all_headers[key]] }
29
- test_header_set(header_set)
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
- request = Net::HTTP::Get.new(@uri.path)
39
- headers.each { |key, value| request[key] = value }
40
-
41
- begin
42
- response = http.request(request)
43
- return response if response.code.to_i.between?(200, 299) # Başarılı yanıtlar
44
- rescue StandardError => e
45
- puts "Request failed: #{e.message}"
46
- return nil
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ApiHeaderOptimizer
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_header_optimizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ziya Gökalp