tipi 0.45 → 0.46

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e6abb7798a69adc36e18dda822f7ff025f9f9e286eba50ccaf3905a74f29ef32
4
- data.tar.gz: 41ee73bf589d2d4bd764aa58cb71e43477bc52caae708bd05ae4ae6372275415
3
+ metadata.gz: e174ac4f391f2a5d8a6bc023c8dbe800cb28c7c6ab6ce0f5b30a5a741adfbba3
4
+ data.tar.gz: 20f4e08c4295e43b4e530005894573170d11488e33ffdb7bd7ac863ea9b24d10
5
5
  SHA512:
6
- metadata.gz: b23c0bfe27b9e6ff203508ab1a24ecbf10d954996ce9af2045a7d427ccec5746e9ef9df146353e4c134a56c12c4f2518141b46fe342123613c3da713a086a90f
7
- data.tar.gz: a2f0fdc533ab39a23dad733535a9371a44a5809485c04114d0e054f4cb4bcb47b0cb27a266d5d58a7e01b8db06daf79a3aa944151de50e61da33f824e4651e43
6
+ metadata.gz: 44824970035774527e456959c6e8249bd697696ef942e2229b4fc9faa192ab2433c7e78f714af3ac98a4d21fc1e764de718ecd41c9e1374a9d06ab090230ab2f
7
+ data.tar.gz: 46549f1ae238fc25fe878bb59258da44757ed05e84177f113a40f00d962f43947d9bbd44f78f1e97be386001d34fadfba8679a5d0a6c647f4dca618769a8116d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.46 2022-02-01
2
+
3
+ - Allow setting valid hosts
4
+ - Change interface of Qeweney apps to use #run (#15)
5
+ - Close server listener before terminating connections
6
+
1
7
  ## 0.45 2021-10-25
2
8
 
3
9
  - Remove `http_parser.rb` dependency (#14) - thanks @SwagDevOps
data/Gemfile.lock CHANGED
@@ -11,18 +11,18 @@ PATH
11
11
  PATH
12
12
  remote: ../polyphony
13
13
  specs:
14
- polyphony (0.71)
14
+ polyphony (0.73.1)
15
15
 
16
16
  PATH
17
17
  remote: ../qeweney
18
18
  specs:
19
- qeweney (0.14)
19
+ qeweney (0.16)
20
20
  escape_utils (~> 1.2.1)
21
21
 
22
22
  PATH
23
23
  remote: .
24
24
  specs:
25
- tipi (0.45)
25
+ tipi (0.46)
26
26
  acme-client (~> 2.0.8)
27
27
  ever (~> 0.1)
28
28
  extralite (~> 1.2)
@@ -44,32 +44,36 @@ GEM
44
44
  rack (>= 1.6.0)
45
45
  docile (1.4.0)
46
46
  escape_utils (1.2.1)
47
- extralite (1.4)
48
- faraday (1.8.0)
47
+ extralite (1.11)
48
+ faraday (1.9.3)
49
49
  faraday-em_http (~> 1.0)
50
50
  faraday-em_synchrony (~> 1.0)
51
51
  faraday-excon (~> 1.1)
52
- faraday-httpclient (~> 1.0.1)
52
+ faraday-httpclient (~> 1.0)
53
+ faraday-multipart (~> 1.0)
53
54
  faraday-net_http (~> 1.0)
54
- faraday-net_http_persistent (~> 1.1)
55
+ faraday-net_http_persistent (~> 1.0)
55
56
  faraday-patron (~> 1.0)
56
57
  faraday-rack (~> 1.0)
57
- multipart-post (>= 1.2, < 3)
58
+ faraday-retry (~> 1.0)
58
59
  ruby2_keywords (>= 0.0.4)
59
60
  faraday-em_http (1.0.0)
60
61
  faraday-em_synchrony (1.0.0)
61
62
  faraday-excon (1.1.0)
62
63
  faraday-httpclient (1.0.1)
64
+ faraday-multipart (1.0.3)
65
+ multipart-post (>= 1.2, < 3)
63
66
  faraday-net_http (1.0.1)
64
67
  faraday-net_http_persistent (1.2.0)
65
68
  faraday-patron (1.0.0)
66
69
  faraday-rack (1.0.0)
70
+ faraday-retry (1.0.3)
67
71
  http-2 (0.11.0)
68
72
  json (2.5.1)
69
73
  localhost (1.1.9)
70
74
  memory_profiler (1.0.0)
71
75
  minitest (5.11.3)
72
- msgpack (1.4.2)
76
+ msgpack (1.4.4)
73
77
  multipart-post (2.1.1)
74
78
  rack (2.2.3)
75
79
  rake (13.0.6)
@@ -97,4 +101,4 @@ DEPENDENCIES
97
101
  tipi!
98
102
 
99
103
  BUNDLED WITH
100
- 2.1.4
104
+ 2.3.3
data/examples/hello.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- def app
4
- ->(req) { req.respond('Hello, world!', 'Content-Type' => 'text/plain') }
5
- end
3
+ run { |req|
4
+ req.respond('Hello, world!')
5
+ }
data/examples/hello.ru CHANGED
@@ -2,8 +2,8 @@
2
2
 
3
3
  run lambda { |env|
4
4
  [
5
- 200,
6
- {"Content-Type" => "text/plain"},
7
- ["Hello, world!"]
5
+ 200,
6
+ {"Content-Type" => "text/plain"},
7
+ ["Hello, world!"]
8
8
  ]
9
9
  }
data/lib/tipi/acme.rb CHANGED
@@ -10,10 +10,11 @@ module Tipi
10
10
  end
11
11
 
12
12
  class CertificateManager
13
- def initialize(master_ctx:, store:, challenge_handler:)
13
+ def initialize(master_ctx:, store:, challenge_handler:, valid_hosts:)
14
14
  @master_ctx = master_ctx
15
15
  @store = store
16
16
  @challenge_handler = challenge_handler
17
+ @valid_hosts = valid_hosts
17
18
  @contexts = {}
18
19
  @requests = Polyphony::Queue.new
19
20
  @worker = spin { run }
@@ -41,6 +42,10 @@ module Tipi
41
42
  def get_ctx(name)
42
43
  state = { ctx: nil }
43
44
 
45
+ if @valid_hosts
46
+ return nil unless @valid_hosts.include?(name)
47
+ end
48
+
44
49
  ready_ctx = @contexts[name]
45
50
  return ready_ctx if ready_ctx
46
51
  return @master_ctx if name =~ IP_REGEXP
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'tipi'
4
+
5
+ module Kernel
6
+ def run(app = nil, &block)
7
+ Tipi.app = app || block
8
+ end
9
+ end
10
+
11
+ module Tipi
12
+ class << self
13
+ attr_writer :app
14
+
15
+ def app
16
+ return @app if @app
17
+
18
+ raise 'No app define. The app to run should be set using `Tipi.app = ...`'
19
+ end
20
+
21
+ def run_sites(site_map)
22
+ sites = site_map.each_with_object({}) { |(k, v), h| h[k] = v.to_proc }
23
+ valid_hosts = sites.keys
24
+
25
+ @app = ->(req) {
26
+ handler = sites[req.host]
27
+ if handler
28
+ handler.call(req)
29
+ else
30
+ req.respond(nil, ':status' => Qeweney::Status::NOT_FOUND)
31
+ end
32
+ }
33
+
34
+ @app.define_singleton_method(:valid_hosts) { valid_hosts }
35
+ end
36
+ end
37
+ end
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'tipi'
4
4
  require 'localhost/authority'
5
+ require_relative './extensions'
5
6
 
6
7
  module Tipi
7
8
  class Controller
@@ -89,7 +90,7 @@ module Tipi
89
90
  def tipi_service
90
91
  puts "Loading Tipi app from #{@path}"
91
92
  require(@path)
92
- app = Object.send(:app)
93
+ app = Tipi.app
93
94
  web_service(app)
94
95
  # proc { spin { Object.run } }
95
96
  end
@@ -200,7 +201,8 @@ module Tipi
200
201
  certificate_manager = Tipi::ACME::CertificateManager.new(
201
202
  master_ctx: ctx,
202
203
  store: certificate_store,
203
- challenge_handler: challenge_handler
204
+ challenge_handler: challenge_handler,
205
+ valid_hosts: app.respond_to?(:valid_hosts) ? app.valid_hosts : nil
204
206
  )
205
207
  http_app = certificate_manager.challenge_routing_app(redirect_app)
206
208
 
@@ -277,8 +279,8 @@ module Tipi
277
279
 
278
280
  def finalize_listener(server)
279
281
  fiber = Fiber.current
280
- gracefully_terminate_conections(fiber) if fiber.graceful_shutdown?
281
282
  server.close
283
+ gracefully_terminate_conections(fiber) if fiber.graceful_shutdown?
282
284
  rescue Polyphony::BaseException
283
285
  raise
284
286
  rescue Exception => e
@@ -5,6 +5,7 @@ require 'localhost/authority'
5
5
  require 'http/parser'
6
6
  require 'qeweney'
7
7
  require 'tipi/rack_adapter'
8
+ require_relative './extensions'
8
9
 
9
10
  module Tipi
10
11
  class Listener
@@ -360,7 +361,10 @@ module Tipi
360
361
  def tipi_service
361
362
  puts "Loading Tipi app from #{@path}"
362
363
  require(@path)
363
- app = Object.send(:app)
364
+ app = Tipi.app
365
+ if !app
366
+ raise "No app define. The app to run should be set using `Tipi.app = ...`"
367
+ end
364
368
  web_service(app)
365
369
  end
366
370
 
@@ -6,7 +6,6 @@ require 'qeweney/request'
6
6
  module Tipi
7
7
  # Manages an HTTP 2 stream
8
8
  class HTTP2StreamHandler
9
- attr_accessor :__next__
10
9
  attr_reader :conn
11
10
 
12
11
  def initialize(adapter, stream, conn, first, &block)
data/lib/tipi/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tipi
4
- VERSION = '0.45'
4
+ VERSION = '0.46'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tipi
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.45'
4
+ version: '0.46'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sharon Rosner
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-25 00:00:00.000000000 Z
11
+ date: 2022-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: polyphony
@@ -240,7 +240,7 @@ dependencies:
240
240
  - - "~>"
241
241
  - !ruby/object:Gem::Version
242
242
  version: 3.9.3
243
- description:
243
+ description:
244
244
  email: sharon@noteflakes.com
245
245
  executables:
246
246
  - tipi
@@ -319,6 +319,7 @@ files:
319
319
  - lib/tipi/controller.rb
320
320
  - lib/tipi/controller/bare_polyphony.rb
321
321
  - lib/tipi/controller/bare_stock.rb
322
+ - lib/tipi/controller/extensions.rb
322
323
  - lib/tipi/controller/stock_http1_adapter.rb
323
324
  - lib/tipi/controller/web_polyphony.rb
324
325
  - lib/tipi/controller/web_stock.rb
@@ -351,7 +352,7 @@ licenses:
351
352
  - MIT
352
353
  metadata:
353
354
  source_code_uri: https://github.com/digital-fabric/tipi
354
- post_install_message:
355
+ post_install_message:
355
356
  rdoc_options:
356
357
  - "--title"
357
358
  - tipi
@@ -370,8 +371,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
370
371
  - !ruby/object:Gem::Version
371
372
  version: '0'
372
373
  requirements: []
373
- rubygems_version: 3.1.2
374
- signing_key:
374
+ rubygems_version: 3.3.3
375
+ signing_key:
375
376
  specification_version: 4
376
377
  summary: Tipi - the All-in-one Web Server for Ruby Apps
377
378
  test_files: []