tipi 0.32 → 0.33

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: b0fd31b18e0c98a8beb780933f7adef48e0e4403a765cc64f37ef02515d94723
4
- data.tar.gz: 1cc72a408cd8fe9b4d1528bd7b1200f3e7a71098596f5b18812d2d75b6120936
3
+ metadata.gz: adbbb6098994749bc96df90a6c73820ca54245c6026141768c83d883677fd6d3
4
+ data.tar.gz: daf182efaff0561bb6ff85706ae14ab70de68f840290eb5bb88e870fc0a29199
5
5
  SHA512:
6
- metadata.gz: d4fb34dbec4798561322546a90f8104f3e91bd806923ba6d73e3267c06ab05499104431bf15f1abb0984d014626a062267305370470d80a7c61776a2f0c0bd8b
7
- data.tar.gz: b0b7d9ec9e0536acef6f9675d592d7c48123bf591468326178b96ef673f194c44a43dcd57ed7f860d78acfe27f71192378f328b5531efff73731cd4b3875c3ee
6
+ metadata.gz: 78c8fb0c465779673563fb87857fdc935c4906830086f664657c00b2b80686f4fa35c3673a554976d26a41af072686ad2c197dd1fbd6a14d875480831e8455ff
7
+ data.tar.gz: bbb9c98e7f167aae1a006fd30ac7557ddf9671d3951e00012582b748f3afea363e53b166c40ec1af3be0f5c6d96d1991f45d9e549f5fd23e614345508719ef5f
@@ -1,3 +1,8 @@
1
+ ## 0.33 2020-11-20
2
+
3
+ * Update code for Polyphony 0.47.5
4
+ * Add support for Rack::File body to Tipi::RackAdapter
5
+
1
6
  ## 0.32 2020-08-14
2
7
 
3
8
  * Respond with array of strings instead of concatenating for HTTP 1
@@ -1,10 +1,10 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tipi (0.32)
4
+ tipi (0.33)
5
5
  http-2 (~> 0.10.0)
6
6
  http_parser.rb (~> 0.6.0)
7
- polyphony (~> 0.45)
7
+ polyphony (~> 0.47.5.1)
8
8
  rack (>= 2.0.8, < 2.3.0)
9
9
  websocket (~> 1.2.8)
10
10
 
@@ -24,7 +24,7 @@ GEM
24
24
  builder
25
25
  minitest (>= 5.0)
26
26
  ruby-progressbar
27
- polyphony (0.45.2)
27
+ polyphony (0.47.5.1)
28
28
  rack (2.2.3)
29
29
  rake (12.3.3)
30
30
  ruby-progressbar (1.10.1)
data/bin/tipi CHANGED
@@ -7,7 +7,20 @@ require File.expand_path('../lib/tipi/configuration', __dir__)
7
7
  config = {}
8
8
  #config[:forked] = 4
9
9
 
10
+ puts DATA.read
11
+ puts
12
+
10
13
  configuration_manager = spin { Tipi::Configuration.supervise_config }
11
14
 
12
15
  configuration_manager << config
13
16
  configuration_manager.await
17
+
18
+ __END__
19
+
20
+ ooo
21
+ oo
22
+ o
23
+ \|/
24
+ / \ Tipi - A better web server for a better world
25
+ /___\
26
+
@@ -7,18 +7,15 @@ require 'tipi'
7
7
 
8
8
  opts = {
9
9
  reuse_addr: true,
10
+ reuse_port: true,
10
11
  dont_linger: true
11
12
  }
12
13
 
13
- server = Polyphony::HTTP::Server.listen('0.0.0.0', 1234, opts)
14
-
15
- puts 'Listening on port 1234'
16
-
17
14
  child_pids = []
18
15
  8.times do
19
16
  pid = Polyphony.fork do
20
17
  puts "forked pid: #{Process.pid}"
21
- server.each do |req|
18
+ Tipi.serve('0.0.0.0', 1234, opts) do |req|
22
19
  req.respond("Hello world! from pid: #{Process.pid}\n")
23
20
  end
24
21
  rescue Interrupt
@@ -26,4 +23,6 @@ child_pids = []
26
23
  child_pids << pid
27
24
  end
28
25
 
26
+ puts 'Listening on port 1234'
27
+
29
28
  child_pids.each { |pid| Thread.current.backend.waitpid(pid) }
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/setup'
4
+ require 'tipi'
5
+
6
+ ::Exception.__disable_sanitized_backtrace__ = true
7
+
8
+ opts = {
9
+ reuse_addr: true,
10
+ reuse_port: true,
11
+ dont_linger: true
12
+ }
13
+
14
+ server = Tipi.listen('0.0.0.0', 1234, opts)
15
+
16
+ puts 'Listening on port 1234'
17
+
18
+ throttler = Polyphony::Throttler.new(interval: 5)
19
+ server.accept_loop do |socket|
20
+ throttler.call do
21
+ spin { Tipi.client_loop(socket, opts) { |req| req.respond("Hello world!\n") } }
22
+ end
23
+ end
@@ -28,10 +28,8 @@ module Tipi
28
28
  end
29
29
 
30
30
  def accept_loop(server, opts, &handler)
31
- loop do
32
- client = server.accept
31
+ server.accept_loop do |client|
33
32
  spin { client_loop(client, opts, &handler) }
34
- snooze
35
33
  rescue OpenSSL::SSL::SSLError
36
34
  # disregard
37
35
  end
@@ -47,7 +45,7 @@ module Tipi
47
45
 
48
46
  def protocol_adapter(socket, opts)
49
47
  use_http2 = socket.respond_to?(:alpn_protocol) &&
50
- socket.alpn_protocol == H2_PROTOCOL
48
+ socket.alpn_protocol == H2_PROTOCOL
51
49
  klass = use_http2 ? HTTP2Adapter : HTTP1Adapter
52
50
  klass.new(socket, opts)
53
51
  end
@@ -19,7 +19,7 @@ module Tipi
19
19
  end
20
20
 
21
21
  def start_listeners(config)
22
- puts "listening on port 1234"
22
+ puts "Listening on port 1234"
23
23
  @server = Polyphony::Net.tcp_listen('0.0.0.0', 1234, { reuse_addr: true, dont_linger: true })
24
24
  end
25
25
 
@@ -15,7 +15,7 @@ module Tipi
15
15
  end
16
16
 
17
17
  def each(&block)
18
- @conn.read_loop do |data|
18
+ @conn.recv_loop do |data|
19
19
  return if handle_incoming_data(data, &block)
20
20
  end
21
21
  rescue SystemCallError, IOError
@@ -65,7 +65,7 @@ module Tipi
65
65
  # callback
66
66
  def consume_request
67
67
  request = @requests_head
68
- @conn.read_loop do |data|
68
+ @conn.recv_loop do |data|
69
69
  @parser << data
70
70
  return if request.complete?
71
71
  end
@@ -164,7 +164,7 @@ module Tipi
164
164
  # @param headers
165
165
  def respond(body, headers)
166
166
  consume_request if @parsing
167
- data = collect_headers(headers, body)
167
+ data = format_headers(headers, body)
168
168
  if body
169
169
  if @parser.http_minor == 0
170
170
  data << body
@@ -172,7 +172,7 @@ module Tipi
172
172
  data << body.bytesize.to_s(16) << CRLF << body << CRLF_ZERO_CRLF_CRLF
173
173
  end
174
174
  end
175
- @conn.write(*data)
175
+ @conn.write(data.join)
176
176
  end
177
177
 
178
178
  DEFAULT_HEADERS_OPTS = {
@@ -186,8 +186,8 @@ module Tipi
186
186
  # @param empty_response [boolean] whether a response body will be sent
187
187
  # @return [void]
188
188
  def send_headers(headers, opts = DEFAULT_HEADERS_OPTS)
189
- data = collect_headers(headers, true)
190
- @conn.write(*data)
189
+ data = format_headers(headers, true)
190
+ @conn.write(data.join)
191
191
  end
192
192
 
193
193
  # Sends a response body chunk. If no headers were sent, default headers are
@@ -200,7 +200,7 @@ module Tipi
200
200
  data = []
201
201
  data << "#{chunk.bytesize.to_s(16)}\r\n#{chunk}\r\n"
202
202
  data << "0\r\n\r\n" if done
203
- @conn.write(*data)
203
+ @conn.write(data.join)
204
204
  end
205
205
 
206
206
  # Finishes the response to the current request. If no headers were sent,
@@ -221,7 +221,7 @@ module Tipi
221
221
  # @param headers [Hash] response headers
222
222
  # @param empty_response [boolean] whether a response body will be sent
223
223
  # @return [String] formatted response headers
224
- def collect_headers(headers, body)
224
+ def format_headers(headers, body)
225
225
  status = headers[':status'] || (body ? 200 : 204)
226
226
  lines = [format_status_line(body, status)]
227
227
  headers.each do |k, v|
@@ -49,7 +49,7 @@ module Tipi
49
49
  @interface.on(:stream) { |stream| start_stream(stream, &block) }
50
50
  upgrade if @upgrade_headers
51
51
 
52
- @conn.read_loop(&@interface.method(:<<))
52
+ @conn.recv_loop(&@interface.method(:<<))
53
53
  rescue SystemCallError, IOError
54
54
  # ignore
55
55
  ensure
@@ -68,10 +68,18 @@ module Tipi
68
68
  else RACK_ENV[key]
69
69
  end
70
70
  end
71
-
71
+
72
72
  def respond(request, (status_code, headers, body))
73
73
  headers[':status'] = status_code.to_s
74
- request.respond(body.first, headers)
74
+
75
+ content =
76
+ if body.respond_to?(:to_path)
77
+ File.open(body.to_path, 'rb') { |f| f.read }
78
+ else
79
+ body.first
80
+ end
81
+
82
+ request.respond(content, headers)
75
83
  end
76
84
  end
77
85
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tipi
4
- VERSION = '0.32'
4
+ VERSION = '0.33'
5
5
  end
@@ -41,7 +41,7 @@ module Tipi
41
41
  return msg.to_s
42
42
  end
43
43
 
44
- @client.read_loop do |data|
44
+ @client.recv_loop do |data|
45
45
  @reader << data
46
46
  if (msg = @reader.next)
47
47
  break msg.to_s
@@ -23,11 +23,13 @@ class IO
23
23
 
24
24
  def self.mockup_connection(input, output, output2)
25
25
  eg(
26
- :read => ->(*args) { input.read(*args) },
27
- :read_loop => ->(*args, &block) { input.read_loop(*args, &block) },
28
- :readpartial => ->(*args) { input.readpartial(*args) },
29
- :<< => ->(*args) { output.write(*args) },
30
- :write => ->(*args) { output.write(*args) },
26
+ :read => ->(*args) { p [:read]; input.read(*args) },
27
+ :read_loop => ->(*args, &block) { p [:read_loop, caller]; input.read_loop(*args, &block) },
28
+ :recv_loop => ->(*args, &block) { p [:recv_loop]; input.read_loop(*args, &block) },
29
+ :readpartial => ->(*args) { p [:readpartial]; input.readpartial(*args) },
30
+ :recv => ->(*args) { p [:recv]; input.readpartial(*args) },
31
+ :<< => ->(*args) { p [:<<, args]; output.write(*args) },
32
+ :write => ->(*args) { p [:write, args]; output.write(*args) },
31
33
  :close => -> { output.close },
32
34
  :eof? => -> { output2.closed? }
33
35
  )
@@ -158,12 +160,14 @@ class HTTP1ServerTest < MiniTest::Test
158
160
  request = req
159
161
  req.send_headers
160
162
  req.each_chunk do |c|
163
+ puts "chunk: #{c.inspect}"
161
164
  chunks << c
162
165
  req << c.upcase
163
166
  end
164
167
  req.finish
165
168
  end
166
169
 
170
+ p connection
167
171
  connection << <<~HTTP.http_lines
168
172
  POST / HTTP/1.1
169
173
  Transfer-Encoding: chunked
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
19
19
 
20
20
  s.executables = ['tipi']
21
21
 
22
- s.add_runtime_dependency 'polyphony', '~>0.45'
22
+ s.add_runtime_dependency 'polyphony', '~>0.47.5.1'
23
23
 
24
24
  s.add_runtime_dependency 'http_parser.rb', '~>0.6.0'
25
25
  s.add_runtime_dependency 'http-2', '~>0.10.0'
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.32'
4
+ version: '0.33'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sharon Rosner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-14 00:00:00.000000000 Z
11
+ date: 2020-11-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: polyphony
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.45'
19
+ version: 0.47.5.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.45'
26
+ version: 0.47.5.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: http_parser.rb
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -185,6 +185,7 @@ files:
185
185
  - examples/http_server_graceful.rb
186
186
  - examples/http_server_simple.rb
187
187
  - examples/http_server_throttled.rb
188
+ - examples/http_server_throttled_accept.rb
188
189
  - examples/http_server_timeout.rb
189
190
  - examples/http_ws_server.rb
190
191
  - examples/https_server.rb
@@ -240,7 +241,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
240
241
  - !ruby/object:Gem::Version
241
242
  version: '0'
242
243
  requirements: []
243
- rubygems_version: 3.1.2
244
+ rubygems_version: 3.1.4
244
245
  signing_key:
245
246
  specification_version: 4
246
247
  summary: Tipi - the All-in-one Web Server for Ruby Apps