landline 0.12.0 → 0.12.1
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/README.md +2 -4
- data/lib/landline/app.rb +28 -13
- data/lib/landline/dsl/methods_probe.rb +3 -3
- data/lib/landline/path.rb +20 -33
- data/lib/landline/probe/handler.rb +10 -2
- data/lib/landline/probe.rb +0 -22
- data/lib/landline/request.rb +12 -2
- data/lib/landline/sandbox.rb +32 -0
- data/lib/landline/server.rb +1 -1
- data/lib/landline/util/lookup.rb +2 -0
- data/lib/landline.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6713c809dcb1f2216afff7f05d00e932c85d36c1b205359a2c8f8655b79fbb1
|
4
|
+
data.tar.gz: 34846e521a08d55376a520a194417edf0cb66972bf6c052ac6fb5d888fea30f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b54438875d8532e95858567f0305b03baf00a6c88a735851116be73ea2b7619031226624ff846d05a7439050deff1b02acfe5c5a7d1a8afdb8e67b2ea6b520a1
|
7
|
+
data.tar.gz: 03031f8d28c5e8657854cdff63e4f205d9b553cb03e34109b761a5f65207fd473005a61a5504a3f96517a37fe2d1f1b234b733916a3bd5f33f4de0e64a30fbab
|
data/README.md
CHANGED
data/lib/landline/app.rb
CHANGED
@@ -3,18 +3,20 @@
|
|
3
3
|
module Landline
|
4
4
|
# Rack application interface
|
5
5
|
class App
|
6
|
-
# TODO: fix this mess somehow (probably impossible)
|
7
|
-
|
8
|
-
# @!parse include Landline::DSL::PathMethods
|
9
|
-
# @!parse include Landline::DSL::PathConstructors
|
10
|
-
# @!parse include Landline::DSL::ProbeConstructors
|
11
|
-
# @!parse include Landline::DSL::ProbeMethods
|
12
|
-
# @!parse include Landline::DSL::CommonMethods
|
13
6
|
class << self
|
7
|
+
# TODO: fix this mess somehow (probably impossible)
|
8
|
+
# @!parse include Landline::DSL::PathMethods
|
9
|
+
# @!parse include Landline::DSL::PathConstructors
|
10
|
+
# @!parse include Landline::DSL::ProbeConstructors
|
11
|
+
# @!parse include Landline::DSL::ProbeMethods
|
12
|
+
# @!parse include Landline::DSL::CommonMethods
|
13
|
+
|
14
14
|
# Duplicate used middleware for the subclassed app
|
15
15
|
def inherited(subclass)
|
16
16
|
super(subclass)
|
17
|
+
@setup_chain ||= []
|
17
18
|
subclass.middleware = @middleware.dup
|
19
|
+
subclass.setup_chain = @setup_chain.dup
|
18
20
|
end
|
19
21
|
|
20
22
|
# Include a middleware in application
|
@@ -24,17 +26,30 @@ module Landline
|
|
24
26
|
@middleware.append(middleware)
|
25
27
|
end
|
26
28
|
|
27
|
-
#
|
28
|
-
|
29
|
-
|
30
|
-
@setup_block = block
|
29
|
+
# Check if Server can respond to given symbol
|
30
|
+
def respond_to_missing?(symbol, _include_private)
|
31
|
+
Landline::ServerContext.instance_methods.include?(symbol) || super
|
31
32
|
end
|
32
33
|
|
33
|
-
|
34
|
+
# Store applied app manipulations
|
35
|
+
def method_missing(symbol, *args, **params, &callback)
|
36
|
+
if Landline::ServerContext.instance_methods.include? symbol
|
37
|
+
@setup_chain.append([symbol, args, params, callback])
|
38
|
+
else
|
39
|
+
super(symbol, *args, **params, &callback)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
attr_accessor :middleware, :setup_chain
|
34
44
|
end
|
35
45
|
|
36
46
|
def initialize(*args, **opts)
|
37
|
-
|
47
|
+
setup_chain = self.class.setup_chain
|
48
|
+
@app = ::Landline::Server.new(*args, **opts) do
|
49
|
+
setup_chain.each do |symbol, cargs, cparams, callback|
|
50
|
+
send(symbol, *cargs, **cparams, &callback)
|
51
|
+
end
|
52
|
+
end
|
38
53
|
self.class.middleware&.reverse_each do |cls|
|
39
54
|
@app = cls.new(@app)
|
40
55
|
end
|
@@ -43,21 +43,21 @@ module Landline
|
|
43
43
|
# @param path [String]
|
44
44
|
def jump(path)
|
45
45
|
@origin.request.path = path
|
46
|
-
throw(:
|
46
|
+
throw(:finish, [307, { "x-internal-jump": true }, []])
|
47
47
|
end
|
48
48
|
|
49
49
|
# (in Landline::Probe context)
|
50
50
|
# Do clientside request redirection via 302 code
|
51
51
|
# @param path [String]
|
52
52
|
def redirect(path)
|
53
|
-
throw(:
|
53
|
+
throw(:finish, [302, { "location": path }, []])
|
54
54
|
end
|
55
55
|
|
56
56
|
# (in Landline::Probe context)
|
57
57
|
# Do clientside request redirection via 307 code
|
58
58
|
# @param path [String]
|
59
59
|
def redirect_with_method(path)
|
60
|
-
throw(:
|
60
|
+
throw(:finish, [307, { "location": path }, []])
|
61
61
|
end
|
62
62
|
|
63
63
|
alias code status
|
data/lib/landline/path.rb
CHANGED
@@ -4,23 +4,9 @@ require_relative 'pattern_matching'
|
|
4
4
|
require_relative 'node'
|
5
5
|
require_relative 'dsl/constructors_path'
|
6
6
|
require_relative 'dsl/methods_path'
|
7
|
-
require_relative 'dsl/methods_common'
|
8
|
-
require_relative 'dsl/methods_probe'
|
9
|
-
require_relative 'dsl/constructors_probe'
|
10
7
|
require_relative 'util/lookup'
|
11
8
|
|
12
9
|
module Landline
|
13
|
-
# Execution context for filters and preprocessors.
|
14
|
-
class ProcessorContext
|
15
|
-
include Landline::DSL::CommonMethods
|
16
|
-
include Landline::DSL::ProbeMethods
|
17
|
-
include Landline::DSL::ProbeConstructors
|
18
|
-
|
19
|
-
def initialize(path)
|
20
|
-
@origin = path
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
10
|
# Execution context for path setup block.
|
25
11
|
class PathContext
|
26
12
|
include Landline::DSL::PathConstructors
|
@@ -31,21 +17,8 @@ module Landline
|
|
31
17
|
end
|
32
18
|
end
|
33
19
|
|
34
|
-
# Ephemeral proxy class to which callback execution binds
|
35
|
-
class PathExecutionOrigin
|
36
|
-
def initialize(request, properties)
|
37
|
-
@request = request
|
38
|
-
@properties = Landline::Util::LookupROProxy.new(properties)
|
39
|
-
end
|
40
|
-
|
41
|
-
attr_accessor :response
|
42
|
-
attr_reader :request, :properties
|
43
|
-
end
|
44
|
-
|
45
20
|
# Primary building block of request navigation.
|
46
21
|
class Path < Landline::Node
|
47
|
-
ExecutionOrigin = Landline::PathExecutionOrigin
|
48
|
-
ProcContext = Landline::ProcessorContext
|
49
22
|
Context = Landline::PathContext
|
50
23
|
|
51
24
|
# @param path [Object] Object to generate {Landline::Pattern} from
|
@@ -108,8 +81,8 @@ module Landline
|
|
108
81
|
|
109
82
|
# Create an execution context for in-path processing blocks
|
110
83
|
def get_context(request)
|
111
|
-
|
112
|
-
|
84
|
+
request.context.origin.properties.lookup = @properties
|
85
|
+
request.context
|
113
86
|
end
|
114
87
|
|
115
88
|
# Sequentially run through all filters and drop request if one is false
|
@@ -118,7 +91,10 @@ module Landline
|
|
118
91
|
def run_filters(request)
|
119
92
|
proccontext = get_context(request)
|
120
93
|
@filters.each do |filter|
|
121
|
-
|
94
|
+
output = catch(:break) do
|
95
|
+
proccontext.instance_exec(request, &filter)
|
96
|
+
end
|
97
|
+
return false unless output
|
122
98
|
end
|
123
99
|
true
|
124
100
|
end
|
@@ -128,8 +104,13 @@ module Landline
|
|
128
104
|
def run_preprocessors(request)
|
129
105
|
proccontext = get_context(request)
|
130
106
|
@preprocessors.each do |preproc|
|
131
|
-
|
107
|
+
output = catch(:break) do
|
108
|
+
proccontext.instance_exec(request, &preproc)
|
109
|
+
true
|
110
|
+
end
|
111
|
+
return false unless output
|
132
112
|
end
|
113
|
+
true
|
133
114
|
end
|
134
115
|
|
135
116
|
# Append postprocessors to request
|
@@ -146,7 +127,8 @@ module Landline
|
|
146
127
|
def process_wrapped(request)
|
147
128
|
return false unless run_filters(request)
|
148
129
|
|
149
|
-
run_preprocessors(request)
|
130
|
+
return false unless run_preprocessors(request)
|
131
|
+
|
150
132
|
enqueue_postprocessors(request)
|
151
133
|
@children.each do |x|
|
152
134
|
value = x.go(request)
|
@@ -155,7 +137,7 @@ module Landline
|
|
155
137
|
value = index(request)
|
156
138
|
return exit_stack(request, value) if value
|
157
139
|
|
158
|
-
|
140
|
+
notfound(request)
|
159
141
|
rescue StandardError => e
|
160
142
|
_die(request, 500, backtrace: [e.to_s] + e.backtrace)
|
161
143
|
end
|
@@ -167,6 +149,11 @@ module Landline
|
|
167
149
|
response
|
168
150
|
end
|
169
151
|
|
152
|
+
# Exit with failure or throw 404
|
153
|
+
def notfound(request)
|
154
|
+
@bounce ? exit_stack(request) : _die(request, 404)
|
155
|
+
end
|
156
|
+
|
170
157
|
# Try to perform indexing on the path if possible
|
171
158
|
# @param request [Landline::Request]
|
172
159
|
# @return [Boolean] true if indexing succeeded
|
@@ -29,8 +29,8 @@ module Landline
|
|
29
29
|
# @return [Boolean] true if further navigation is possible
|
30
30
|
# @raise [UncaughtThrowError] may raise if die() is called.
|
31
31
|
def process(request)
|
32
|
-
origin =
|
33
|
-
|
32
|
+
origin, context = get_context(request)
|
33
|
+
|
34
34
|
return reject(request) unless request.path.match?(/^\/?$/)
|
35
35
|
|
36
36
|
response = catch(:break) do
|
@@ -47,6 +47,14 @@ module Landline
|
|
47
47
|
end
|
48
48
|
throw :finish, response
|
49
49
|
end
|
50
|
+
|
51
|
+
private
|
52
|
+
|
53
|
+
# Create a context to run handler in
|
54
|
+
def get_context(request)
|
55
|
+
request.context.origin.properties.lookup = @properties
|
56
|
+
[request.context.origin, request.context]
|
57
|
+
end
|
50
58
|
end
|
51
59
|
end
|
52
60
|
end
|
data/lib/landline/probe.rb
CHANGED
@@ -24,28 +24,6 @@ module Landline
|
|
24
24
|
autoload :Link, "landline/probe/crosscall_handler"
|
25
25
|
end
|
26
26
|
|
27
|
-
# Context that provides execution context for Probes.
|
28
|
-
class ProbeContext
|
29
|
-
include Landline::DSL::ProbeConstructors
|
30
|
-
include Landline::DSL::ProbeMethods
|
31
|
-
include Landline::DSL::CommonMethods
|
32
|
-
|
33
|
-
def initialize(origin)
|
34
|
-
@origin = origin
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
# Ephemeral proxy class to which callback execution binds
|
39
|
-
class ProbeExecutionOrigin
|
40
|
-
def initialize(request, properties)
|
41
|
-
@request = request
|
42
|
-
@properties = Landline::Util::LookupROProxy.new(properties)
|
43
|
-
end
|
44
|
-
|
45
|
-
attr_accessor :response
|
46
|
-
attr_reader :request, :properties
|
47
|
-
end
|
48
|
-
|
49
27
|
# Test probe. Also base for all "reactive" nodes.
|
50
28
|
class Probe < Landline::Node
|
51
29
|
# @param path [Object]
|
data/lib/landline/request.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'uri'
|
4
4
|
require_relative 'util/query'
|
5
5
|
require_relative 'util/cookie'
|
6
|
+
require_relative 'sandbox'
|
6
7
|
|
7
8
|
module Landline
|
8
9
|
# Request wrapper for Rack protocol
|
@@ -30,13 +31,16 @@ module Landline
|
|
30
31
|
@states = []
|
31
32
|
# Postprocessors for current request
|
32
33
|
@postprocessors = []
|
34
|
+
# Execution context
|
35
|
+
@context = init_context
|
33
36
|
end
|
34
37
|
|
35
38
|
# Run postprocessors
|
36
39
|
# @param response [Landline::Response]
|
37
40
|
def run_postprocessors(response)
|
41
|
+
@context.origin.properties.lookup = {}
|
38
42
|
@postprocessors.reverse_each do |postproc|
|
39
|
-
|
43
|
+
@context.instance_exec(self, response, &postproc)
|
40
44
|
end
|
41
45
|
@postprocessors = []
|
42
46
|
end
|
@@ -90,11 +94,17 @@ module Landline
|
|
90
94
|
|
91
95
|
attr_reader :request_method, :script_name, :path_info, :server_name,
|
92
96
|
:server_port, :server_protocol, :headers, :param, :splat,
|
93
|
-
:postprocessors, :cookies, :rack
|
97
|
+
:postprocessors, :cookies, :rack, :context
|
94
98
|
attr_accessor :path, :filepath, :query
|
95
99
|
|
96
100
|
private
|
97
101
|
|
102
|
+
# Initialize execution context
|
103
|
+
def init_context
|
104
|
+
origin = Landline::ProcessorOrigin.new(self, {})
|
105
|
+
Landline::ProcessorContext.new(origin)
|
106
|
+
end
|
107
|
+
|
98
108
|
# Initialize basic rack request parameters
|
99
109
|
# @param env [Hash]
|
100
110
|
def init_request_params(env)
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'dsl/methods_common'
|
4
|
+
require_relative 'dsl/methods_probe'
|
5
|
+
require_relative 'dsl/constructors_probe'
|
6
|
+
require_relative 'util/lookup'
|
7
|
+
|
8
|
+
module Landline
|
9
|
+
# Execution context for filters and preprocessors.
|
10
|
+
class ProcessorContext
|
11
|
+
include Landline::DSL::CommonMethods
|
12
|
+
include Landline::DSL::ProbeMethods
|
13
|
+
include Landline::DSL::ProbeConstructors
|
14
|
+
|
15
|
+
def initialize(path)
|
16
|
+
@origin = path
|
17
|
+
end
|
18
|
+
|
19
|
+
attr_reader :origin
|
20
|
+
end
|
21
|
+
|
22
|
+
# Ephemeral proxy class to which callback execution binds
|
23
|
+
class ProcessorOrigin
|
24
|
+
def initialize(request, properties)
|
25
|
+
@request = request
|
26
|
+
@properties = Landline::Util::LookupROProxy.new(properties)
|
27
|
+
end
|
28
|
+
|
29
|
+
attr_accessor :response
|
30
|
+
attr_reader :request, :properties
|
31
|
+
end
|
32
|
+
end
|
data/lib/landline/server.rb
CHANGED
@@ -14,7 +14,7 @@ module Landline
|
|
14
14
|
# @param parent [Landline::Node, nil] Parent object to inherit properties to
|
15
15
|
# @param setup [#call] Setup block
|
16
16
|
def initialize(passthrough = nil, parent: nil, **opts, &setup)
|
17
|
-
super("", parent:
|
17
|
+
super("", parent: parent, **opts, &setup)
|
18
18
|
return if parent
|
19
19
|
|
20
20
|
@passthrough = passthrough
|
data/lib/landline/util/lookup.rb
CHANGED
data/lib/landline.rb
CHANGED
@@ -12,7 +12,7 @@ require_relative 'landline/app'
|
|
12
12
|
# Landline is a backend framework born as a by-product of experimentation
|
13
13
|
module Landline
|
14
14
|
# Landline version
|
15
|
-
VERSION = '0.12 "Concrete and Gold" (pre-alpha)'
|
15
|
+
VERSION = '0.12.1 "Concrete and Gold" (pre-alpha)'
|
16
16
|
|
17
17
|
# Landline branding and version
|
18
18
|
VLINE = "Landline/#{Landline::VERSION} (Ruby/#{RUBY_VERSION}/#{RUBY_RELEASE_DATE})\n".freeze
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: landline
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.12.
|
4
|
+
version: 0.12.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yessiest
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-05-07 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
Landline is a no-hard-dependencies HTTP routing DSL that was made entirely for fun.
|
@@ -48,6 +48,7 @@ files:
|
|
48
48
|
- lib/landline/probe/serve_handler.rb
|
49
49
|
- lib/landline/request.rb
|
50
50
|
- lib/landline/response.rb
|
51
|
+
- lib/landline/sandbox.rb
|
51
52
|
- lib/landline/server.rb
|
52
53
|
- lib/landline/template.rb
|
53
54
|
- lib/landline/template/erb.rb
|
@@ -81,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
82
|
- !ruby/object:Gem::Version
|
82
83
|
version: '0'
|
83
84
|
requirements: []
|
84
|
-
rubygems_version: 3.5.
|
85
|
+
rubygems_version: 3.5.6
|
85
86
|
signing_key:
|
86
87
|
specification_version: 4
|
87
88
|
summary: Elegant HTTP DSL
|