eac_envs-http 0.6.0 → 0.6.1

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: 26e1482ff58e47b7a780079016d86be8ebc34f24abce6b72884490a82a2f9cdb
4
- data.tar.gz: b8c417ee8ea17f08c445308d0a613ed0ce368836ddbf0c3737d22feaa796a023
3
+ metadata.gz: 16767658ee6f6609ff953b37bb509445f81c9664f1c2bda6c2e940d3e8dd10c9
4
+ data.tar.gz: 2e8371d49916ab7e55270a207ea9260886a2725a104352e206d1ce2ab9240562
5
5
  SHA512:
6
- metadata.gz: f6b78b5edb1f9bee713d93851a87ee9c9874e99ea689bb795d5726632663060bb4b6c2269e1108cdd2384db13c7d2b7bc7281c31dddd41a31a60a46c087b8830
7
- data.tar.gz: 36b9871a50b8f8d8de845eff995955dbbeef82c12e0fbb743a47a5d5f4b8177b74ab03489feb1c0bfe7cf3d06cff5c523e218a71e618dcfe619ec4af0f475280
6
+ metadata.gz: 4025c5127852ff0ce7bf17d42765a2d1a65c0d71c71e63f83c55b3a9e62091fdd29f37039682b8eb096639f46f97037af870f7296a8fe5da6a943c9798dbb17f
7
+ data.tar.gz: 1ccd594cde8ad9d49cff75525be6c538dc526b52ab006dc88ebca8d510ba1cdced0d4a06f1ccc0de3ec947262f944fb1f64d4e1963b4a21f63d0590cac393abf
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_envs/http/rspec/echo_server/webrick_servlet'
4
+ require 'eac_ruby_utils/core_ext'
5
+ require 'webrick'
6
+ # require 'webrick/https'
7
+
8
+ module EacEnvs
9
+ module Http
10
+ module Rspec
11
+ class EchoServer
12
+ class HttpServer < ::WEBrick::HTTPServer
13
+ def initialize(options)
14
+ super
15
+ mount '/', ::EacEnvs::Http::Rspec::EchoServer::WebrickServlet
16
+ end
17
+
18
+ def on_running(&block)
19
+ ::Thread.abort_on_exception = true
20
+ servlet_thread = ::Thread.new { start }
21
+ begin
22
+ sleep 0.001 while status != :Running
23
+ block.call
24
+ ensure
25
+ shutdown
26
+ servlet_thread.join
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'addressable'
4
4
  require 'eac_ruby_utils/core_ext'
5
+ require 'random-port'
5
6
  require 'webrick'
6
7
  require 'webrick/https'
7
8
 
@@ -11,8 +12,8 @@ module EacEnvs
11
12
  class EchoServer
12
13
  HOSTNAME = 'localhost'
13
14
  SCHEMES = {
14
- http: { Port: 8080 },
15
- https: { Port: 8443, SSLEnable: true, SSLCertName: [['CN', HOSTNAME]] }
15
+ http: {},
16
+ https: { SSLEnable: true, SSLCertName: [['CN', HOSTNAME]] }
16
17
  }.freeze
17
18
 
18
19
  class << self
@@ -27,15 +28,8 @@ module EacEnvs
27
28
  common_constructor :scheme, :webrick_options
28
29
 
29
30
  def on_active(&block)
30
- servlet = webrick_servlet
31
- ::Thread.abort_on_exception = true
32
- servlet_thread = ::Thread.new { servlet.start }
33
- begin
34
- sleep 0.001 while servlet.status != :Running
35
- block.call
36
- ensure
37
- servlet.shutdown
38
- servlet_thread.join
31
+ on_aquired_port do
32
+ http_server.on_running(&block)
39
33
  end
40
34
  end
41
35
 
@@ -43,17 +37,30 @@ module EacEnvs
43
37
  ::Addressable::URI.new(
44
38
  scheme: scheme.to_s,
45
39
  host: ::EacEnvs::Http::Rspec::EchoServer::HOSTNAME,
46
- port: webrick_options.fetch(:Port)
40
+ port: port!
47
41
  )
48
42
  end
49
43
 
50
- private
44
+ protected
45
+
46
+ attr_accessor :port
47
+
48
+ # @return [EacEnvs::Http::Rspec::EchoServer::HttpServer]
49
+ def http_server
50
+ ::EacEnvs::Http::Rspec::EchoServer::HttpServer.new(webrick_options.merge(Port: port!))
51
+ end
52
+
53
+ def on_aquired_port(&block)
54
+ ::RandomPort::Pool.new.acquire do |port|
55
+ self.port = port
56
+ block.call
57
+ self.port = nil
58
+ end
59
+ end
51
60
 
52
- # @return [EacEnvs::Http::Rspec::EchoServer::WebrickServlet]
53
- def webrick_servlet
54
- r = ::WEBrick::HTTPServer.new(webrick_options)
55
- r.mount '/', ::EacEnvs::Http::Rspec::EchoServer::WebrickServlet
56
- r
61
+ # @return [Integer]
62
+ def port!
63
+ port.presence || raise('Port unsetted')
57
64
  end
58
65
 
59
66
  require_sub __FILE__
@@ -2,6 +2,6 @@
2
2
 
3
3
  module EacEnvs
4
4
  module Http
5
- VERSION = '0.6.0'
5
+ VERSION = '0.6.1'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eac_envs-http
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Put here the authors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-03 00:00:00.000000000 Z
11
+ date: 2024-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eac_fs
@@ -132,6 +132,26 @@ dependencies:
132
132
  - - ">="
133
133
  - !ruby/object:Gem::Version
134
134
  version: 2.2.1
135
+ - !ruby/object:Gem::Dependency
136
+ name: random-port
137
+ requirement: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - "~>"
140
+ - !ruby/object:Gem::Version
141
+ version: '0.7'
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: 0.7.1
145
+ type: :runtime
146
+ prerelease: false
147
+ version_requirements: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - "~>"
150
+ - !ruby/object:Gem::Version
151
+ version: '0.7'
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: 0.7.1
135
155
  - !ruby/object:Gem::Dependency
136
156
  name: eac_ruby_gem_support
137
157
  requirement: !ruby/object:Gem::Requirement
@@ -166,6 +186,7 @@ files:
166
186
  - lib/eac_envs/http/response/statuses.rb
167
187
  - lib/eac_envs/http/rspec.rb
168
188
  - lib/eac_envs/http/rspec/echo_server.rb
189
+ - lib/eac_envs/http/rspec/echo_server/http_server.rb
169
190
  - lib/eac_envs/http/rspec/echo_server/request_processor.rb
170
191
  - lib/eac_envs/http/rspec/echo_server/webrick_servlet.rb
171
192
  - lib/eac_envs/http/version.rb