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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16767658ee6f6609ff953b37bb509445f81c9664f1c2bda6c2e940d3e8dd10c9
|
4
|
+
data.tar.gz: 2e8371d49916ab7e55270a207ea9260886a2725a104352e206d1ce2ab9240562
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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: {
|
15
|
-
https: {
|
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
|
-
|
31
|
-
|
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:
|
40
|
+
port: port!
|
47
41
|
)
|
48
42
|
end
|
49
43
|
|
50
|
-
|
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 [
|
53
|
-
def
|
54
|
-
|
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__
|
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.
|
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-
|
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
|