syntropy 0.28.2 → 0.30.0
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 +4 -4
- data/.github/workflows/test.yml +2 -2
- data/.ruby-version +1 -0
- data/CHANGELOG.md +11 -0
- data/README.md +0 -4
- data/bin/syntropy +2 -3
- data/cmd/setup/template/site/Dockerfile +1 -1
- data/lib/syntropy/app.rb +22 -14
- data/lib/syntropy/errors.rb +23 -10
- data/lib/syntropy/http/connection.rb +396 -0
- data/lib/syntropy/http/server.rb +174 -0
- data/lib/syntropy/http/status.rb +76 -0
- data/lib/syntropy/http.rb +5 -0
- data/lib/syntropy/json_api.rb +2 -5
- data/lib/syntropy/logger.rb +103 -0
- data/lib/syntropy/mime_types.rb +37 -0
- data/lib/syntropy/request/mock_adapter.rb +58 -0
- data/lib/syntropy/request/request_info.rb +236 -0
- data/lib/syntropy/request/response.rb +206 -0
- data/lib/syntropy/{request_extensions.rb → request/validation.rb} +4 -147
- data/lib/syntropy/request.rb +99 -0
- data/lib/syntropy/utils.rb +1 -1
- data/lib/syntropy/version.rb +1 -1
- data/lib/syntropy.rb +53 -5
- data/syntropy.gemspec +5 -7
- data/test/app/about/_error.rb +1 -1
- data/test/app/api+.rb +1 -1
- data/test/app_custom/_site.rb +1 -1
- data/test/bm_router_proc.rb +3 -3
- data/test/helper.rb +12 -7
- data/test/test_app.rb +30 -30
- data/test/test_caching.rb +2 -2
- data/test/test_connection.rb +649 -0
- data/test/test_errors.rb +6 -6
- data/test/test_json_api.rb +10 -8
- data/test/test_mock_adapter.rb +59 -0
- data/test/test_request_info.rb +90 -0
- data/test/test_response.rb +112 -0
- data/test/test_server.rb +336 -0
- metadata +34 -34
- data/lib/syntropy/file_watch.rb +0 -28
- data/test/test_file_watch.rb +0 -36
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative './request/request_info'
|
|
4
|
+
require_relative './request/validation'
|
|
5
|
+
require_relative './request/response'
|
|
6
|
+
require_relative './http/status'
|
|
7
|
+
|
|
8
|
+
module Syntropy
|
|
9
|
+
class Request
|
|
10
|
+
include RequestInfoMethods
|
|
11
|
+
include RequestValidationMethods
|
|
12
|
+
include ResponseMethods
|
|
13
|
+
|
|
14
|
+
extend RequestInfoClassMethods
|
|
15
|
+
|
|
16
|
+
attr_reader :headers, :adapter, :start_stamp, :route_params
|
|
17
|
+
attr_accessor :route
|
|
18
|
+
|
|
19
|
+
def initialize(headers, adapter)
|
|
20
|
+
@headers = headers
|
|
21
|
+
@adapter = adapter
|
|
22
|
+
@start_stamp = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC)
|
|
23
|
+
@route = nil
|
|
24
|
+
@route_params = {}
|
|
25
|
+
@ctx = nil
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Returns the request context
|
|
29
|
+
def ctx
|
|
30
|
+
@ctx ||= {}
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def next_chunk
|
|
34
|
+
@adapter.get_body_chunk(self)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def each_chunk
|
|
38
|
+
while (chunk = @adapter.get_body_chunk(self))
|
|
39
|
+
yield chunk
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def read
|
|
44
|
+
@adapter.get_body(self)
|
|
45
|
+
end
|
|
46
|
+
alias_method :body, :read
|
|
47
|
+
|
|
48
|
+
def complete?
|
|
49
|
+
@adapter.complete?(self)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
EMPTY_HEADERS = {}.freeze
|
|
53
|
+
|
|
54
|
+
def respond(body, headers = EMPTY_HEADERS)
|
|
55
|
+
@adapter.respond(self, body, headers)
|
|
56
|
+
@headers_sent = true
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def send_headers(headers = EMPTY_HEADERS, empty_response = false)
|
|
60
|
+
return if @headers_sent
|
|
61
|
+
|
|
62
|
+
@headers_sent = true
|
|
63
|
+
@adapter.send_headers(self, headers, empty_response: empty_response)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def send_chunk(body, done: false)
|
|
67
|
+
send_headers({}) unless @headers_sent
|
|
68
|
+
|
|
69
|
+
@adapter.send_chunk(self, body, done: done)
|
|
70
|
+
end
|
|
71
|
+
alias_method :<<, :send_chunk
|
|
72
|
+
|
|
73
|
+
def finish
|
|
74
|
+
send_headers({}) unless @headers_sent
|
|
75
|
+
|
|
76
|
+
@adapter.finish(self)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def headers_sent?
|
|
80
|
+
@headers_sent
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def rx_incr(count)
|
|
84
|
+
headers[':rx'] ? headers[':rx'] += count : headers[':rx'] = count
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def tx_incr(count)
|
|
88
|
+
headers[':tx'] ? headers[':tx'] += count : headers[':tx'] = count
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def transfer_counts
|
|
92
|
+
[headers[':rx'], headers[':tx']]
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def total_transfer
|
|
96
|
+
(headers[':rx'] || 0) + (headers[':tx'] || 0)
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
data/lib/syntropy/utils.rb
CHANGED
data/lib/syntropy/version.rb
CHANGED
data/lib/syntropy.rb
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'qeweney'
|
|
4
3
|
require 'uringmachine'
|
|
5
|
-
require 'tp2'
|
|
6
4
|
require 'papercraft'
|
|
7
5
|
|
|
6
|
+
require 'syntropy/request'
|
|
7
|
+
require 'syntropy/logger'
|
|
8
|
+
require 'syntropy/http'
|
|
9
|
+
require 'syntropy/mime_types'
|
|
8
10
|
require 'syntropy/app'
|
|
9
11
|
require 'syntropy/connection_pool'
|
|
10
12
|
require 'syntropy/errors'
|
|
11
13
|
require 'syntropy/markdown'
|
|
12
14
|
require 'syntropy/module'
|
|
13
|
-
require 'syntropy/request_extensions'
|
|
14
15
|
require 'syntropy/papercraft_extensions'
|
|
15
16
|
require 'syntropy/routing_tree'
|
|
16
17
|
require 'syntropy/json_api'
|
|
17
18
|
require 'syntropy/side_run'
|
|
18
19
|
require 'syntropy/utils'
|
|
20
|
+
require 'syntropy/version'
|
|
19
21
|
|
|
20
22
|
module Syntropy
|
|
21
|
-
Status = Qeweney::Status
|
|
22
|
-
|
|
23
23
|
extend Utilities
|
|
24
24
|
|
|
25
25
|
class << self
|
|
@@ -50,4 +50,52 @@ module Syntropy
|
|
|
50
50
|
" #{GREEN} #{YELLOW}|#{GREEN} vvv o #{CLEAR}https://github.com/digital-fabric/syntropy\n"\
|
|
51
51
|
" #{GREEN} :#{YELLOW}|#{GREEN}:::#{YELLOW}|#{GREEN}::#{YELLOW}|#{GREEN}:\n"\
|
|
52
52
|
"#{YELLOW}+++++++++++++++++++++++++++++++++++++++++++++++++++++++++\e[0m\n\n"
|
|
53
|
+
|
|
54
|
+
class << self
|
|
55
|
+
def run(env = {}, &app)
|
|
56
|
+
if @in_run
|
|
57
|
+
@env = env
|
|
58
|
+
@env[:app] = app if app
|
|
59
|
+
return
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
env ||= @env || {}
|
|
63
|
+
begin
|
|
64
|
+
@in_run = true
|
|
65
|
+
machine = env[:machine] || UM.new
|
|
66
|
+
machine.puts(env[:banner]) if env[:banner]
|
|
67
|
+
|
|
68
|
+
env[:logger]&.info(message: "Running Syntropy #{Syntropy::VERSION}, UringMachine #{UM::VERSION}, Ruby #{RUBY_VERSION}")
|
|
69
|
+
|
|
70
|
+
server = Server.new(machine, env, &app)
|
|
71
|
+
|
|
72
|
+
setup_signal_handling(machine, Fiber.current)
|
|
73
|
+
server.run
|
|
74
|
+
ensure
|
|
75
|
+
@in_run = false
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def env(env = nil, &app)
|
|
80
|
+
return @env if !env && !app
|
|
81
|
+
|
|
82
|
+
@env = env || {}
|
|
83
|
+
@env[:app] = app if app
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
private
|
|
87
|
+
|
|
88
|
+
def setup_signal_handling(machine, fiber)
|
|
89
|
+
queue = UM::Queue.new
|
|
90
|
+
trap('SIGINT') { machine.push(queue, :SIGINT) }
|
|
91
|
+
machine.spin { watch_for_int_signal(machine, queue, fiber) }
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# waits for signal from queue, then terminates given fiber
|
|
95
|
+
# to be done
|
|
96
|
+
def watch_for_int_signal(machine, queue, fiber)
|
|
97
|
+
machine.shift(queue)
|
|
98
|
+
machine.schedule(fiber, UM::Terminate.new)
|
|
99
|
+
end
|
|
100
|
+
end
|
|
53
101
|
end
|
data/syntropy.gemspec
CHANGED
|
@@ -13,9 +13,9 @@ Gem::Specification.new do |s|
|
|
|
13
13
|
s.metadata = {
|
|
14
14
|
'homepage_uri' => 'https://github.com/digital-fabric/syntropy',
|
|
15
15
|
'documentation_uri' => 'https://www.rubydoc.info/gems/syntropy',
|
|
16
|
-
'changelog_uri' => 'https://github.com/digital-fabric/syntropy/blob/
|
|
16
|
+
'changelog_uri' => 'https://github.com/digital-fabric/syntropy/blob/main/CHANGELOG.md'
|
|
17
17
|
}
|
|
18
|
-
s.rdoc_options = ['--title', '
|
|
18
|
+
s.rdoc_options = ['--title', 'Syntropy', '--main', 'README.md']
|
|
19
19
|
s.extra_rdoc_files = ['README.md']
|
|
20
20
|
s.require_paths = ['lib']
|
|
21
21
|
s.required_ruby_version = '>= 3.4'
|
|
@@ -23,11 +23,9 @@ Gem::Specification.new do |s|
|
|
|
23
23
|
|
|
24
24
|
s.add_dependency 'extralite', '~>2.14'
|
|
25
25
|
s.add_dependency 'papercraft', '~>3.2.0'
|
|
26
|
-
s.add_dependency '
|
|
27
|
-
s.add_dependency '
|
|
28
|
-
s.add_dependency '
|
|
29
|
-
|
|
30
|
-
s.add_dependency 'listen', '~>3.9.0'
|
|
26
|
+
s.add_dependency 'uringmachine', '~>1.0.0'
|
|
27
|
+
s.add_dependency 'cgi'
|
|
28
|
+
s.add_dependency 'escape_utils', '1.3.0'
|
|
31
29
|
|
|
32
30
|
s.add_dependency 'json'
|
|
33
31
|
s.add_dependency 'logger'
|
data/test/app/about/_error.rb
CHANGED
data/test/app/api+.rb
CHANGED
data/test/app_custom/_site.rb
CHANGED
data/test/bm_router_proc.rb
CHANGED
|
@@ -13,7 +13,7 @@ require 'roda'
|
|
|
13
13
|
require 'benchmark/ips'
|
|
14
14
|
require 'securerandom'
|
|
15
15
|
require 'rack/mock_request'
|
|
16
|
-
require '
|
|
16
|
+
require 'syntropy/request/mock_adapter'
|
|
17
17
|
|
|
18
18
|
class BM
|
|
19
19
|
def self.name(name)
|
|
@@ -100,7 +100,7 @@ p roda_app.(req)
|
|
|
100
100
|
|
|
101
101
|
################################################################################
|
|
102
102
|
|
|
103
|
-
class
|
|
103
|
+
class Syntropy::Request
|
|
104
104
|
def response_headers
|
|
105
105
|
adapter.headers
|
|
106
106
|
end
|
|
@@ -157,7 +157,7 @@ proc = ->(req) { syntropy_app.(req) }
|
|
|
157
157
|
|
|
158
158
|
module ::Kernel
|
|
159
159
|
def mock_req(headers, body = nil)
|
|
160
|
-
|
|
160
|
+
Syntropy::MockAdapter.mock(headers, body)
|
|
161
161
|
end
|
|
162
162
|
end
|
|
163
163
|
|
data/test/helper.rb
CHANGED
|
@@ -4,16 +4,22 @@ require 'bundler/setup'
|
|
|
4
4
|
require_relative './coverage' if ENV['COVERAGE']
|
|
5
5
|
require 'uringmachine'
|
|
6
6
|
require 'syntropy'
|
|
7
|
-
require '
|
|
7
|
+
require 'syntropy/request/mock_adapter'
|
|
8
8
|
require 'minitest/autorun'
|
|
9
9
|
require 'fileutils'
|
|
10
10
|
|
|
11
11
|
STDOUT.sync = true
|
|
12
12
|
STDERR.sync = true
|
|
13
13
|
|
|
14
|
+
class ::String
|
|
15
|
+
def crlf_lines
|
|
16
|
+
chomp.gsub("\n", "\r\n").chomp
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
14
20
|
module ::Kernel
|
|
15
21
|
def mock_req(headers, body = nil)
|
|
16
|
-
|
|
22
|
+
Syntropy::MockAdapter.mock(headers, body)
|
|
17
23
|
end
|
|
18
24
|
|
|
19
25
|
def capture_exception
|
|
@@ -83,15 +89,16 @@ module Minitest::Assertions
|
|
|
83
89
|
return unless exp_content_type
|
|
84
90
|
|
|
85
91
|
if Symbol === exp_content_type
|
|
86
|
-
exp_content_type =
|
|
92
|
+
exp_content_type = Syntropy::MimeTypes[exp_content_type]
|
|
87
93
|
end
|
|
88
94
|
actual = req.response_content_type
|
|
95
|
+
|
|
89
96
|
assert_equal exp_content_type, actual
|
|
90
97
|
end
|
|
91
98
|
end
|
|
92
99
|
|
|
93
|
-
# Extensions to be used in conjunction with `
|
|
94
|
-
class
|
|
100
|
+
# Extensions to be used in conjunction with `Syntropy::TestAdapter`
|
|
101
|
+
class Syntropy::Request
|
|
95
102
|
def response_headers
|
|
96
103
|
adapter.response_headers
|
|
97
104
|
end
|
|
@@ -113,5 +120,3 @@ class Qeweney::Request
|
|
|
113
120
|
response_headers['Content-Type']
|
|
114
121
|
end
|
|
115
122
|
end
|
|
116
|
-
|
|
117
|
-
# puts "Polyphony backend: #{Thread.current.backend.kind}"
|
data/test/test_app.rb
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
require_relative 'helper'
|
|
4
4
|
|
|
5
5
|
class AppTest < Minitest::Test
|
|
6
|
-
|
|
6
|
+
HTTP = Syntropy::HTTP
|
|
7
7
|
|
|
8
8
|
APP_ROOT = File.join(__dir__, 'app')
|
|
9
9
|
|
|
@@ -29,27 +29,27 @@ class AppTest < Minitest::Test
|
|
|
29
29
|
|
|
30
30
|
def test_app_rendering
|
|
31
31
|
req = make_request(':method' => 'GET', ':path' => '/')
|
|
32
|
-
assert_equal
|
|
32
|
+
assert_equal HTTP::NOT_FOUND, req.response_status
|
|
33
33
|
assert_equal 'Not found', req.response_body
|
|
34
34
|
|
|
35
35
|
req = make_request(':method' => 'HEAD', ':path' => '/')
|
|
36
|
-
assert_equal
|
|
36
|
+
assert_equal HTTP::NOT_FOUND, req.response_status
|
|
37
37
|
assert_nil req.response_body
|
|
38
38
|
|
|
39
39
|
req = make_request(':method' => 'POST', ':path' => '/')
|
|
40
40
|
assert_equal 'Not found', req.response_body
|
|
41
|
-
assert_equal
|
|
41
|
+
assert_equal HTTP::NOT_FOUND, req.response_status
|
|
42
42
|
|
|
43
43
|
req = make_request(':method' => 'GET', ':path' => '/test')
|
|
44
|
-
assert_equal
|
|
44
|
+
assert_equal HTTP::OK, req.response_status
|
|
45
45
|
assert_equal '<h1>Hello, world!</h1>', req.response_body
|
|
46
46
|
|
|
47
47
|
req = make_request(':method' => 'HEAD', ':path' => '/test')
|
|
48
|
-
assert_equal
|
|
48
|
+
assert_equal HTTP::OK, req.response_status
|
|
49
49
|
assert_nil req.response_body
|
|
50
50
|
|
|
51
51
|
req = make_request(':method' => 'POST', ':path' => '/test')
|
|
52
|
-
assert_equal
|
|
52
|
+
assert_equal HTTP::METHOD_NOT_ALLOWED, req.response_status
|
|
53
53
|
assert_equal "Method not allowed", req.response_body
|
|
54
54
|
|
|
55
55
|
req = make_request(':method' => 'GET', ':path' => '/test/assets/style.css')
|
|
@@ -57,13 +57,13 @@ class AppTest < Minitest::Test
|
|
|
57
57
|
assert_equal 'text/css', req.response_headers['Content-Type']
|
|
58
58
|
|
|
59
59
|
req = make_request(':method' => 'GET', ':path' => '/assets/style.css')
|
|
60
|
-
assert_equal
|
|
60
|
+
assert_equal HTTP::NOT_FOUND, req.response_status
|
|
61
61
|
|
|
62
62
|
req = make_request(':method' => 'GET', ':path' => '/test/api?q=get')
|
|
63
63
|
assert_equal({ status: 'OK', response: 0 }, req.response_json)
|
|
64
64
|
|
|
65
65
|
req = make_request(':method' => 'POST', ':path' => '/test/api?q=get')
|
|
66
|
-
assert_equal
|
|
66
|
+
assert_equal HTTP::METHOD_NOT_ALLOWED, req.response_status
|
|
67
67
|
assert_equal({ status: 'Error', message: 'Method not allowed' }, req.response_json)
|
|
68
68
|
|
|
69
69
|
req = make_request(':method' => 'GET', ':path' => '/test/api/foo?q=get')
|
|
@@ -73,32 +73,32 @@ class AppTest < Minitest::Test
|
|
|
73
73
|
assert_equal({ status: 'OK', response: 1 }, req.response_json)
|
|
74
74
|
|
|
75
75
|
req = make_request(':method' => 'GET', ':path' => '/test/api?q=incr')
|
|
76
|
-
assert_equal
|
|
76
|
+
assert_equal HTTP::METHOD_NOT_ALLOWED, req.response_status
|
|
77
77
|
assert_equal({ status: 'Error', message: 'Method not allowed' }, req.response_json)
|
|
78
78
|
|
|
79
79
|
req = make_request(':method' => 'POST', ':path' => '/test/api/foo?q=incr')
|
|
80
80
|
assert_equal({ status: 'Error', message: 'Teapot' }, req.response_json)
|
|
81
|
-
assert_equal
|
|
81
|
+
assert_equal HTTP::TEAPOT, req.response_status
|
|
82
82
|
|
|
83
83
|
req = make_request(':method' => 'POST', ':path' => '/test/api/foo/bar?q=incr')
|
|
84
84
|
assert_equal({ status: 'Error', message: 'Teapot' }, req.response_json)
|
|
85
|
-
assert_equal
|
|
85
|
+
assert_equal HTTP::TEAPOT, req.response_status
|
|
86
86
|
|
|
87
87
|
req = make_request(':method' => 'GET', ':path' => '/test/bar')
|
|
88
88
|
assert_equal 'foobar', req.response_body
|
|
89
|
-
assert_equal
|
|
89
|
+
assert_equal HTTP::OK, req.response_status
|
|
90
90
|
|
|
91
91
|
req = make_request(':method' => 'POST', ':path' => '/test/bar')
|
|
92
92
|
assert_equal 'foobar', req.response_body
|
|
93
|
-
assert_equal
|
|
93
|
+
assert_equal HTTP::OK, req.response_status
|
|
94
94
|
|
|
95
95
|
req = make_request(':method' => 'GET', ':path' => '/test/baz')
|
|
96
96
|
assert_equal 'foobar', req.response_body
|
|
97
|
-
assert_equal
|
|
97
|
+
assert_equal HTTP::OK, req.response_status
|
|
98
98
|
|
|
99
99
|
req = make_request(':method' => 'POST', ':path' => '/test/baz')
|
|
100
100
|
assert_equal 'Method not allowed', req.response_body
|
|
101
|
-
assert_equal
|
|
101
|
+
assert_equal HTTP::METHOD_NOT_ALLOWED, req.response_status
|
|
102
102
|
|
|
103
103
|
req = make_request(':method' => 'GET', ':path' => '/test/about')
|
|
104
104
|
assert_equal 'About', req.response_body.chomp
|
|
@@ -110,7 +110,7 @@ class AppTest < Minitest::Test
|
|
|
110
110
|
assert_nil req.response_body
|
|
111
111
|
|
|
112
112
|
req = make_request(':method' => 'GET', ':path' => '/test/about/foo/bar')
|
|
113
|
-
assert_equal
|
|
113
|
+
assert_equal HTTP::NOT_FOUND, req.response_status
|
|
114
114
|
|
|
115
115
|
req = make_request(':method' => 'GET', ':path' => '/test/params/abc')
|
|
116
116
|
assert_equal '/test/params/[foo]-abc', req.response_body.chomp
|
|
@@ -119,12 +119,12 @@ class AppTest < Minitest::Test
|
|
|
119
119
|
assert_equal '<link>foo</link>', req.response_body
|
|
120
120
|
|
|
121
121
|
req = make_request(':method' => 'GET', ':path' => '/test/bad_mod')
|
|
122
|
-
assert_equal
|
|
122
|
+
assert_equal HTTP::INTERNAL_SERVER_ERROR, req.response_status
|
|
123
123
|
end
|
|
124
124
|
|
|
125
125
|
def test_automatic_redirect_on_trailing_slash
|
|
126
126
|
req = make_request(':method' => 'GET', ':path' => '/test/rss/')
|
|
127
|
-
assert_equal
|
|
127
|
+
assert_equal HTTP::MOVED_PERMANENTLY, req.response_status
|
|
128
128
|
assert_equal '/test/rss', req.response_headers['Location']
|
|
129
129
|
end
|
|
130
130
|
|
|
@@ -146,29 +146,29 @@ class AppTest < Minitest::Test
|
|
|
146
146
|
|
|
147
147
|
def test_middleware
|
|
148
148
|
req = make_request(':method' => 'HEAD', ':path' => '/test?foo=42')
|
|
149
|
-
assert_equal
|
|
149
|
+
assert_equal HTTP::OK, req.response_status
|
|
150
150
|
assert_nil req.response_body
|
|
151
151
|
assert_equal '42', req.ctx[:foo]
|
|
152
152
|
|
|
153
153
|
req = make_request(':method' => 'HEAD', ':path' => '/test/about/raise?foo=43')
|
|
154
|
-
assert_equal
|
|
154
|
+
assert_equal HTTP::INTERNAL_SERVER_ERROR, req.response_status
|
|
155
155
|
assert_equal '<h1>Raised error</h1>', req.response_body
|
|
156
156
|
assert_equal '43', req.ctx[:foo]
|
|
157
157
|
end
|
|
158
158
|
|
|
159
159
|
def test_middleware_invocation_on_404
|
|
160
160
|
req = make_request(':method' => 'HEAD', ':path' => '/azerty?foo=bar')
|
|
161
|
-
assert_equal
|
|
161
|
+
assert_equal HTTP::NOT_FOUND, req.response_status
|
|
162
162
|
assert_nil req.ctx[:foo]
|
|
163
163
|
|
|
164
164
|
req = make_request(':method' => 'HEAD', ':path' => '/test/azerty?foo=bar')
|
|
165
|
-
assert_equal
|
|
165
|
+
assert_equal HTTP::NOT_FOUND, req.response_status
|
|
166
166
|
assert_equal 'bar', req.ctx[:foo]
|
|
167
167
|
end
|
|
168
168
|
end
|
|
169
169
|
|
|
170
170
|
class CustomAppTest < Minitest::Test
|
|
171
|
-
|
|
171
|
+
HTTP = Syntropy::HTTP
|
|
172
172
|
|
|
173
173
|
APP_ROOT = File.join(__dir__, 'app_custom')
|
|
174
174
|
|
|
@@ -190,12 +190,12 @@ class CustomAppTest < Minitest::Test
|
|
|
190
190
|
def test_app_with_site_rb_file
|
|
191
191
|
req = make_request(':method' => 'GET', ':path' => '/foo/bar')
|
|
192
192
|
assert_nil req.response_body
|
|
193
|
-
assert_equal
|
|
193
|
+
assert_equal HTTP::TEAPOT, req.response_status
|
|
194
194
|
end
|
|
195
195
|
end
|
|
196
196
|
|
|
197
197
|
class MultiSiteAppTest < Minitest::Test
|
|
198
|
-
|
|
198
|
+
HTTP = Syntropy::HTTP
|
|
199
199
|
|
|
200
200
|
APP_ROOT = File.join(__dir__, 'app_multi_site')
|
|
201
201
|
|
|
@@ -217,7 +217,7 @@ class MultiSiteAppTest < Minitest::Test
|
|
|
217
217
|
def test_route_by_host
|
|
218
218
|
req = make_request(':method' => 'GET', ':path' => '/', 'host' => 'blah')
|
|
219
219
|
assert_nil req.response_body
|
|
220
|
-
assert_equal
|
|
220
|
+
assert_equal HTTP::BAD_REQUEST, req.response_status
|
|
221
221
|
|
|
222
222
|
req = make_request(':method' => 'GET', ':path' => '/', 'host' => 'foo.bar')
|
|
223
223
|
assert_equal '<h1>foo.bar</h1>', req.response_body.chomp
|
|
@@ -228,7 +228,7 @@ class MultiSiteAppTest < Minitest::Test
|
|
|
228
228
|
end
|
|
229
229
|
|
|
230
230
|
class AppAPITest < Minitest::Test
|
|
231
|
-
|
|
231
|
+
HTTP = Syntropy::HTTP
|
|
232
232
|
|
|
233
233
|
APP_ROOT = File.join(__dir__, 'app')
|
|
234
234
|
|
|
@@ -292,7 +292,7 @@ class AppAPITest < Minitest::Test
|
|
|
292
292
|
end
|
|
293
293
|
|
|
294
294
|
class AppDependenciesTest < Minitest::Test
|
|
295
|
-
|
|
295
|
+
HTTP = Syntropy::HTTP
|
|
296
296
|
|
|
297
297
|
APP_ROOT = File.join(__dir__, 'app')
|
|
298
298
|
|
|
@@ -321,6 +321,6 @@ class AppDependenciesTest < Minitest::Test
|
|
|
321
321
|
|
|
322
322
|
req = make_request(':method' => 'GET', ':path' => '/test/bar')
|
|
323
323
|
assert_equal 'foobar', req.response_body
|
|
324
|
-
assert_equal
|
|
324
|
+
assert_equal HTTP::OK, req.response_status
|
|
325
325
|
end
|
|
326
326
|
end
|
data/test/test_caching.rb
CHANGED
|
@@ -4,7 +4,7 @@ require_relative 'helper'
|
|
|
4
4
|
require 'digest/sha1'
|
|
5
5
|
|
|
6
6
|
class CachingTest < Minitest::Test
|
|
7
|
-
|
|
7
|
+
HTTP = Syntropy::HTTP
|
|
8
8
|
|
|
9
9
|
APP_ROOT = File.join(__dir__, 'app')
|
|
10
10
|
|
|
@@ -40,7 +40,7 @@ class CachingTest < Minitest::Test
|
|
|
40
40
|
@app = Syntropy::App.new(**@env)
|
|
41
41
|
|
|
42
42
|
@c_fd, @s_fd = make_socket_pair
|
|
43
|
-
@adapter =
|
|
43
|
+
@adapter = Syntropy::HTTP::Connection.new(nil, @machine, @s_fd, @env) { @app.(it) }
|
|
44
44
|
end
|
|
45
45
|
|
|
46
46
|
def teardown
|