strelka 0.0.1.pre129 → 0.0.1.pre148
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.
- data/IDEAS.rdoc +26 -32
- data/Manifest.txt +27 -12
- data/README.rdoc +29 -33
- data/Rakefile +2 -1
- data/bin/leash +2 -1
- data/contrib/hoetemplate/README.rdoc.erb +18 -0
- data/contrib/hoetemplate/data/{file_name → project}/apps/file_name_app +0 -0
- data/contrib/hoetemplate/data/{file_name → project}/templates/layout.tmpl.erb +0 -0
- data/contrib/hoetemplate/data/{file_name → project}/templates/top.tmpl.erb +0 -0
- data/examples/config.yml +3 -0
- data/examples/gen-config.rb +48 -0
- data/examples/sessions-demo.rb +43 -0
- data/lib/strelka/app/errors.rb +59 -17
- data/lib/strelka/app/filters.rb +3 -1
- data/lib/strelka/app/negotiation.rb +5 -3
- data/lib/strelka/app/parameters.rb +33 -31
- data/lib/strelka/app/plugins.rb +14 -8
- data/lib/strelka/app/restresources.rb +3 -1
- data/lib/strelka/app/routing.rb +9 -7
- data/lib/strelka/app/sessions.rb +175 -0
- data/lib/strelka/app/templating.rb +6 -3
- data/lib/strelka/app.rb +19 -11
- data/lib/strelka/behavior/plugin.rb +4 -2
- data/lib/strelka/constants.rb +9 -0
- data/lib/strelka/cookie.rb +357 -0
- data/lib/strelka/cookieset.rb +117 -0
- data/lib/strelka/httprequest/acceptparams.rb +12 -10
- data/lib/strelka/httprequest/negotiation.rb +4 -2
- data/lib/strelka/httprequest/session.rb +71 -0
- data/lib/strelka/httprequest.rb +19 -7
- data/lib/strelka/httpresponse/negotiation.rb +17 -15
- data/lib/strelka/httpresponse/session.rb +101 -0
- data/lib/strelka/httpresponse.rb +26 -4
- data/lib/strelka/logging.rb +3 -1
- data/lib/strelka/mixins.rb +174 -2
- data/lib/strelka/{app/paramvalidator.rb → paramvalidator.rb} +25 -22
- data/lib/strelka/{app/defaultrouter.rb → router/default.rb} +6 -4
- data/lib/strelka/{app/exclusiverouter.rb → router/exclusive.rb} +6 -4
- data/lib/strelka/{app/router.rb → router.rb} +9 -7
- data/lib/strelka/session/default.rb +209 -0
- data/lib/strelka/session.rb +178 -0
- data/lib/strelka.rb +6 -4
- data/spec/lib/constants.rb +3 -1
- data/spec/lib/helpers.rb +7 -0
- data/spec/strelka/app/errors_spec.rb +32 -52
- data/spec/strelka/app/filters_spec.rb +3 -1
- data/spec/strelka/app/negotiation_spec.rb +3 -1
- data/spec/strelka/app/parameters_spec.rb +5 -3
- data/spec/strelka/app/plugins_spec.rb +5 -3
- data/spec/strelka/app/restresources_spec.rb +3 -1
- data/spec/strelka/app/routing_spec.rb +6 -4
- data/spec/strelka/app/sessions_spec.rb +109 -0
- data/spec/strelka/app/templating_spec.rb +3 -1
- data/spec/strelka/app_spec.rb +11 -2
- data/spec/strelka/cookie_spec.rb +194 -0
- data/spec/strelka/cookieset_spec.rb +159 -0
- data/spec/strelka/exceptions_spec.rb +3 -1
- data/spec/strelka/httprequest/acceptparams_spec.rb +3 -1
- data/spec/strelka/httprequest/negotiation_spec.rb +3 -1
- data/spec/strelka/httprequest/session_spec.rb +43 -0
- data/spec/strelka/httprequest_spec.rb +28 -1
- data/spec/strelka/httpresponse/negotiation_spec.rb +3 -3
- data/spec/strelka/httpresponse_spec.rb +13 -0
- data/spec/strelka/logging_spec.rb +3 -1
- data/spec/strelka/mixins_spec.rb +125 -1
- data/spec/strelka/{app/paramvalidator_spec.rb → paramvalidator_spec.rb} +4 -4
- data/spec/strelka/{app/defaultrouter_spec.rb → router/default_spec.rb} +6 -4
- data/spec/strelka/{app/exclusiverouter_spec.rb → router/exclusive_spec.rb} +6 -4
- data/spec/strelka/{app/router_spec.rb → router_spec.rb} +9 -7
- data/spec/strelka/session/default_spec.rb +210 -0
- data/spec/strelka/session_spec.rb +101 -0
- data.tar.gz.sig +1 -1
- metadata +64 -47
- metadata.gz.sig +0 -0
- data/contrib/hoetemplate/.autotest.erb +0 -23
data/IDEAS.rdoc
CHANGED
|
@@ -8,55 +8,49 @@ up-to-date if it does.
|
|
|
8
8
|
|
|
9
9
|
== Leash
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
Show a list of installed applications:
|
|
12
12
|
|
|
13
|
-
$ leash
|
|
13
|
+
$ leash discover
|
|
14
|
+
Searching for Strelka applications...
|
|
15
|
+
|
|
16
|
+
strelka:
|
|
17
|
+
hello-world
|
|
18
|
+
|
|
19
|
+
strelka-admin:
|
|
20
|
+
config-service strelka-admin strelka-setup
|
|
21
|
+
|
|
22
|
+
strelka-cms:
|
|
23
|
+
content-manager
|
|
14
24
|
|
|
15
|
-
|
|
25
|
+
Set up an application's runtime directory and add a route for it to an existing
|
|
26
|
+
mongrel2 config database:
|
|
16
27
|
|
|
17
|
-
$
|
|
28
|
+
$ mkdir /service/cms
|
|
29
|
+
$ cd /service/cms
|
|
30
|
+
$ leash -c /usr/local/etc/mongrel2.sqlite setup strelka-cms content-manager
|
|
18
31
|
|
|
19
|
-
|
|
32
|
+
The application can register pre- and post-install hooks that run migrations,
|
|
33
|
+
prompt for config values, etc.
|
|
20
34
|
|
|
21
|
-
|
|
35
|
+
Then, to start the app:
|
|
22
36
|
|
|
23
|
-
|
|
24
|
-
|
|
37
|
+
$ cd /service/cms
|
|
38
|
+
$ leash --sudo start
|
|
25
39
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
Once you have the first node set up, you need only point 'leash' to the admin
|
|
30
|
-
server running on the first host to set up and automatically configure
|
|
31
|
-
additional Mongrel2 front-ends:
|
|
32
|
-
|
|
33
|
-
server2$ leash join server1
|
|
34
|
-
|
|
35
|
-
This uses a 0MQ service running from the admin server that publishes the
|
|
36
|
-
config using Mongrel2's "config from anything" protocol, so when Mongrel2
|
|
37
|
-
itself supports the 'zmq.so' plugin, you won't even need a local SQLite
|
|
38
|
-
database.
|
|
40
|
+
This stuff will probably use Isolate[https://github.com/jbarnette/isolate] for
|
|
41
|
+
gem sandboxing.
|
|
39
42
|
|
|
40
43
|
|
|
41
44
|
== Strelka Applications
|
|
42
45
|
|
|
43
|
-
* Apps have an appid constant (the mongrel2 UUID)
|
|
44
|
-
* Apps are distributed in gems
|
|
45
|
-
* A larger app can be split across multiple applets within a gem
|
|
46
|
-
- The gem can suggest a set of routes
|
|
47
|
-
- The Strelka admin interface can display the gem with its suggested routes
|
|
48
46
|
* The framework provides convenience methods for looking up the route to
|
|
49
47
|
another app via its appid.
|
|
50
48
|
|
|
51
|
-
|
|
49
|
+
|
|
52
50
|
|
|
53
51
|
=== Future Plugins
|
|
54
52
|
|
|
55
53
|
* CORS (cors) — manage {Cross-Origin Resource Sharing}[http://www.html5rocks.com/en/tutorials/cors/]
|
|
56
54
|
headers
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
== Deployment
|
|
55
|
+
* caching -- utilities for easy HTTP caching
|
|
62
56
|
|
data/Manifest.txt
CHANGED
|
@@ -5,65 +5,80 @@ Manifest.txt
|
|
|
5
5
|
README.rdoc
|
|
6
6
|
Rakefile
|
|
7
7
|
bin/leash
|
|
8
|
-
contrib/hoetemplate/.autotest.erb
|
|
9
8
|
contrib/hoetemplate/History.rdoc.erb
|
|
10
9
|
contrib/hoetemplate/Manifest.txt.erb
|
|
11
10
|
contrib/hoetemplate/README.rdoc.erb
|
|
12
11
|
contrib/hoetemplate/Rakefile.erb
|
|
13
|
-
contrib/hoetemplate/data/
|
|
14
|
-
contrib/hoetemplate/data/
|
|
15
|
-
contrib/hoetemplate/data/
|
|
12
|
+
contrib/hoetemplate/data/project/apps/file_name_app
|
|
13
|
+
contrib/hoetemplate/data/project/templates/layout.tmpl.erb
|
|
14
|
+
contrib/hoetemplate/data/project/templates/top.tmpl.erb
|
|
16
15
|
contrib/hoetemplate/lib/file_name.rb.erb
|
|
17
16
|
contrib/hoetemplate/spec/file_name_spec.rb.erb
|
|
18
17
|
data/strelka/apps/hello-world
|
|
18
|
+
examples/config.yml
|
|
19
|
+
examples/gen-config.rb
|
|
20
|
+
examples/sessions-demo.rb
|
|
19
21
|
lib/strelka.rb
|
|
20
22
|
lib/strelka/app.rb
|
|
21
|
-
lib/strelka/app/defaultrouter.rb
|
|
22
23
|
lib/strelka/app/errors.rb
|
|
23
|
-
lib/strelka/app/exclusiverouter.rb
|
|
24
24
|
lib/strelka/app/filters.rb
|
|
25
25
|
lib/strelka/app/negotiation.rb
|
|
26
26
|
lib/strelka/app/parameters.rb
|
|
27
|
-
lib/strelka/app/paramvalidator.rb
|
|
28
27
|
lib/strelka/app/plugins.rb
|
|
29
28
|
lib/strelka/app/restresources.rb
|
|
30
|
-
lib/strelka/app/router.rb
|
|
31
29
|
lib/strelka/app/routing.rb
|
|
30
|
+
lib/strelka/app/sessions.rb
|
|
32
31
|
lib/strelka/app/templating.rb
|
|
33
32
|
lib/strelka/behavior/plugin.rb
|
|
34
33
|
lib/strelka/constants.rb
|
|
34
|
+
lib/strelka/cookie.rb
|
|
35
|
+
lib/strelka/cookieset.rb
|
|
35
36
|
lib/strelka/exceptions.rb
|
|
36
37
|
lib/strelka/httprequest.rb
|
|
37
38
|
lib/strelka/httprequest/acceptparams.rb
|
|
38
39
|
lib/strelka/httprequest/negotiation.rb
|
|
40
|
+
lib/strelka/httprequest/session.rb
|
|
39
41
|
lib/strelka/httpresponse.rb
|
|
40
42
|
lib/strelka/httpresponse/negotiation.rb
|
|
43
|
+
lib/strelka/httpresponse/session.rb
|
|
41
44
|
lib/strelka/logging.rb
|
|
42
45
|
lib/strelka/mixins.rb
|
|
46
|
+
lib/strelka/paramvalidator.rb
|
|
47
|
+
lib/strelka/router.rb
|
|
48
|
+
lib/strelka/router/default.rb
|
|
49
|
+
lib/strelka/router/exclusive.rb
|
|
50
|
+
lib/strelka/session.rb
|
|
51
|
+
lib/strelka/session/default.rb
|
|
43
52
|
spec/data/error.tmpl
|
|
44
53
|
spec/data/layout.tmpl
|
|
45
54
|
spec/data/main.tmpl
|
|
46
55
|
spec/lib/constants.rb
|
|
47
56
|
spec/lib/helpers.rb
|
|
48
|
-
spec/strelka/app/defaultrouter_spec.rb
|
|
49
57
|
spec/strelka/app/errors_spec.rb
|
|
50
|
-
spec/strelka/app/exclusiverouter_spec.rb
|
|
51
58
|
spec/strelka/app/filters_spec.rb
|
|
52
59
|
spec/strelka/app/negotiation_spec.rb
|
|
53
60
|
spec/strelka/app/parameters_spec.rb
|
|
54
|
-
spec/strelka/app/paramvalidator_spec.rb
|
|
55
61
|
spec/strelka/app/plugins_spec.rb
|
|
56
62
|
spec/strelka/app/restresources_spec.rb
|
|
57
|
-
spec/strelka/app/router_spec.rb
|
|
58
63
|
spec/strelka/app/routing_spec.rb
|
|
64
|
+
spec/strelka/app/sessions_spec.rb
|
|
59
65
|
spec/strelka/app/templating_spec.rb
|
|
60
66
|
spec/strelka/app_spec.rb
|
|
67
|
+
spec/strelka/cookie_spec.rb
|
|
68
|
+
spec/strelka/cookieset_spec.rb
|
|
61
69
|
spec/strelka/exceptions_spec.rb
|
|
62
70
|
spec/strelka/httprequest/acceptparams_spec.rb
|
|
63
71
|
spec/strelka/httprequest/negotiation_spec.rb
|
|
72
|
+
spec/strelka/httprequest/session_spec.rb
|
|
64
73
|
spec/strelka/httprequest_spec.rb
|
|
65
74
|
spec/strelka/httpresponse/negotiation_spec.rb
|
|
66
75
|
spec/strelka/httpresponse_spec.rb
|
|
67
76
|
spec/strelka/logging_spec.rb
|
|
68
77
|
spec/strelka/mixins_spec.rb
|
|
78
|
+
spec/strelka/paramvalidator_spec.rb
|
|
79
|
+
spec/strelka/router/default_spec.rb
|
|
80
|
+
spec/strelka/router/exclusive_spec.rb
|
|
81
|
+
spec/strelka/router_spec.rb
|
|
82
|
+
spec/strelka/session/default_spec.rb
|
|
83
|
+
spec/strelka/session_spec.rb
|
|
69
84
|
spec/strelka_spec.rb
|
data/README.rdoc
CHANGED
|
@@ -30,39 +30,6 @@ application gems that are installed, setting up an application's
|
|
|
30
30
|
runtime directory, and starting a Strelka application.
|
|
31
31
|
|
|
32
32
|
|
|
33
|
-
=== Leash
|
|
34
|
-
|
|
35
|
-
Strelka comes with a command-line tool called 'leash' that you can use to
|
|
36
|
-
make setting up and starting a Strelka application backend a little bit easier.
|
|
37
|
-
|
|
38
|
-
To see a list of the available Strelka applications, run
|
|
39
|
-
<tt>leash discover</tt>:
|
|
40
|
-
|
|
41
|
-
$ leash discover
|
|
42
|
-
Searching for Strelka applications...
|
|
43
|
-
Found:
|
|
44
|
-
|
|
45
|
-
hello-world
|
|
46
|
-
|
|
47
|
-
$ gem install strelka-admin
|
|
48
|
-
Successfully installed strelka-admin-1.1.0
|
|
49
|
-
1 gem installed
|
|
50
|
-
|
|
51
|
-
$ leash discover
|
|
52
|
-
Searching for Strelka applications...
|
|
53
|
-
Found:
|
|
54
|
-
|
|
55
|
-
hello-world strelka-admin config-service
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
To set up a new application runtime directory, run <tt>leash setup</tt>
|
|
59
|
-
with the path to the directory and the name of the application:
|
|
60
|
-
|
|
61
|
-
$ leash setup /usr/local/myapp hello-world
|
|
62
|
-
Creating directory...
|
|
63
|
-
Creating barebones config...
|
|
64
|
-
|
|
65
|
-
|
|
66
33
|
=== The Application Framework
|
|
67
34
|
|
|
68
35
|
The application framework is primarily geared towards developing web (HTTP)
|
|
@@ -139,6 +106,35 @@ easily.
|
|
|
139
106
|
Automatically set up RESTful service resources for Sequel::Model-derived
|
|
140
107
|
classes.
|
|
141
108
|
|
|
109
|
+
|
|
110
|
+
== Roadmap
|
|
111
|
+
|
|
112
|
+
Going forward, we're going to be extracting useful stuff out of our own
|
|
113
|
+
applications as plugins, and finishing up the packaging and deployment
|
|
114
|
+
stories once we've ironed out the details in own environment.
|
|
115
|
+
|
|
116
|
+
Here's a tentative list of what kinds of stuff we have planned:
|
|
117
|
+
|
|
118
|
+
=== More Plugins
|
|
119
|
+
|
|
120
|
+
* CORS -- manage {Cross-Origin Resource Sharing}[http://www.html5rocks.com/en/tutorials/cors/]
|
|
121
|
+
headers, especially for service applications
|
|
122
|
+
* caching -- utilities for easy HTTP caching
|
|
123
|
+
|
|
124
|
+
=== Deployment/Packaging
|
|
125
|
+
|
|
126
|
+
You'll be able to package up your applications as Rubygems for easy deployment.
|
|
127
|
+
The Strelka::App class already supports application discovery, but we
|
|
128
|
+
want to hook that up to the 'leash' command line tool so you can install
|
|
129
|
+
and run them with a minimum of manual monkeying around with directories,
|
|
130
|
+
migrations, etc.
|
|
131
|
+
|
|
132
|
+
=== New Application Styles
|
|
133
|
+
|
|
134
|
+
Create some new handler classes for different application styles, similar to those
|
|
135
|
+
in the Tir[http://tir.mongrel2.org/] framework.
|
|
136
|
+
|
|
137
|
+
|
|
142
138
|
== Contributing
|
|
143
139
|
|
|
144
140
|
You can check out the current development source with Mercurial via its
|
data/Rakefile
CHANGED
|
@@ -21,7 +21,7 @@ hoespec = Hoe.spec 'strelka' do
|
|
|
21
21
|
|
|
22
22
|
self.developer 'Michael Granger', 'ged@FaerieMUD.org'
|
|
23
23
|
|
|
24
|
-
self.dependency 'mongrel2', '~> 0.
|
|
24
|
+
self.dependency 'mongrel2', '~> 0.16'
|
|
25
25
|
self.dependency 'configurability', '~> 1.0'
|
|
26
26
|
self.dependency 'inversion', '~> 0.2'
|
|
27
27
|
self.dependency 'trollop', '~> 1.16'
|
|
@@ -34,6 +34,7 @@ hoespec = Hoe.spec 'strelka' do
|
|
|
34
34
|
self.dependency 'rspec', '~> 2.6', :developer
|
|
35
35
|
|
|
36
36
|
self.spec_extras[:licenses] = ["BSD"]
|
|
37
|
+
self.spec_extras[:rdoc_options] = ['-f', 'fivefish', '-t', 'Strelka Web Application Toolkit']
|
|
37
38
|
self.require_ruby_version( '>=1.9.2' )
|
|
38
39
|
self.hg_sign_tags = true if self.respond_to?( :hg_sign_tags= )
|
|
39
40
|
self.check_history_on_release = true if self.respond_to?( :check_history_on_release= )
|
data/bin/leash
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
|
+
# vim: set nosta noet ts=4 sw=4:
|
|
2
3
|
|
|
3
4
|
require 'strelka'
|
|
4
5
|
require 'trollop'
|
|
@@ -244,7 +245,7 @@ class Strelka::LeashCommand
|
|
|
244
245
|
message "None found."
|
|
245
246
|
else
|
|
246
247
|
paths.each do |gemname, paths|
|
|
247
|
-
message "
|
|
248
|
+
message "\n"
|
|
248
249
|
|
|
249
250
|
subheader "#{gemname}:"
|
|
250
251
|
filenames = paths.map {|path| path.basename.to_s }
|
|
@@ -14,4 +14,22 @@
|
|
|
14
14
|
|
|
15
15
|
Copyright (c) <%= Time.now.strftime("%Y") %>, <%= XIF %>
|
|
16
16
|
All rights reserved.
|
|
17
|
+
<%
|
|
17
18
|
|
|
19
|
+
# Okay, this is admittedly super-gross, but sow is pretty inflexible
|
|
20
|
+
# about its project templates. C'est la vie.
|
|
21
|
+
require 'pathname'
|
|
22
|
+
projectdir = Pathname( path ).dirname
|
|
23
|
+
olddir = projectdir + 'data/project'
|
|
24
|
+
datadir = projectdir + 'data' + project
|
|
25
|
+
|
|
26
|
+
# Rename the datadir to match the project name
|
|
27
|
+
mv olddir, datadir, :verbose => true
|
|
28
|
+
|
|
29
|
+
# ... then change all of the paths to match before sow moves
|
|
30
|
+
# 'em all.
|
|
31
|
+
paths.each do |path|
|
|
32
|
+
path.sub!( %r{/project/}, "/#{project}/" )
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
%>
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
data/examples/config.yml
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# -*- ruby -*-
|
|
2
|
+
# vim: set nosta noet ts=4 sw=4:
|
|
3
|
+
#encoding: utf-8
|
|
4
|
+
|
|
5
|
+
# The Mongrel config used by the examples. Load it with:
|
|
6
|
+
#
|
|
7
|
+
# m2sh.rb -c examples/mongrel2.sqlite load examples/gen-config.rb
|
|
8
|
+
#
|
|
9
|
+
|
|
10
|
+
require 'strelka'
|
|
11
|
+
require 'mongrel2'
|
|
12
|
+
require 'mongrel2/config/dsl'
|
|
13
|
+
|
|
14
|
+
Strelka.load_config( 'examples/config.yml' )
|
|
15
|
+
|
|
16
|
+
# samples server
|
|
17
|
+
server 'examples' do
|
|
18
|
+
|
|
19
|
+
name 'Strelka Examples'
|
|
20
|
+
default_host 'localhost'
|
|
21
|
+
|
|
22
|
+
access_log '/logs/access.log'
|
|
23
|
+
error_log '/logs/error.log'
|
|
24
|
+
chroot '/var/mongrel2'
|
|
25
|
+
pid_file '/run/mongrel2.pid'
|
|
26
|
+
|
|
27
|
+
bind_addr '127.0.0.1'
|
|
28
|
+
port 8113
|
|
29
|
+
|
|
30
|
+
host 'localhost' do
|
|
31
|
+
|
|
32
|
+
route '/', directory( 'data/strelka/', 'examples.html', 'text/html' )
|
|
33
|
+
route '/source', directory( 'examples/', 'README.txt', 'text/plain' )
|
|
34
|
+
|
|
35
|
+
# Handlers
|
|
36
|
+
route '/hello', handler( 'tcp://127.0.0.1:9900', 'helloworld-handler' )
|
|
37
|
+
route '/sessions', handler( 'tcp://127.0.0.1:9905', 'sessions-demo' )
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
setting "zeromq.threads", 1
|
|
44
|
+
|
|
45
|
+
mkdir_p 'var'
|
|
46
|
+
mkdir_p 'run'
|
|
47
|
+
mkdir_p 'logs'
|
|
48
|
+
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# -*- ruby -*-
|
|
2
|
+
# vim: set nosta noet ts=4 sw=4:
|
|
3
|
+
#encoding: utf-8
|
|
4
|
+
|
|
5
|
+
require 'strelka'
|
|
6
|
+
|
|
7
|
+
class SessionsDemo < Strelka::App
|
|
8
|
+
|
|
9
|
+
# The Mongrel2 appid of this app
|
|
10
|
+
ID = 'sessions-demo'
|
|
11
|
+
|
|
12
|
+
plugins :sessions
|
|
13
|
+
|
|
14
|
+
### Set up the run counter
|
|
15
|
+
def initialize( * )
|
|
16
|
+
@runcount = 0
|
|
17
|
+
super
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
### Handle any HTTP request
|
|
22
|
+
def handle_request( req )
|
|
23
|
+
res = req.response
|
|
24
|
+
res.content_type = 'text/plain'
|
|
25
|
+
res.status = HTTP::OK
|
|
26
|
+
|
|
27
|
+
@runcount += 1
|
|
28
|
+
req.session.counter ||= 0
|
|
29
|
+
req.session.counter += 1
|
|
30
|
+
|
|
31
|
+
self.log.debug "Request session is: %p" % [ req.session ]
|
|
32
|
+
res.puts "Session [%s]: session counter: %d, run counter: %d" %
|
|
33
|
+
[ req.session.session_id, req.session.counter, @runcount ]
|
|
34
|
+
|
|
35
|
+
return res
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
end # class SessionsDemo
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
Strelka.load_config( 'examples/config.yml' )
|
|
43
|
+
SessionsDemo.run
|
data/lib/strelka/app/errors.rb
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
# -*- ruby -*-
|
|
2
|
+
# vim: set nosta noet ts=4 sw=4:
|
|
3
|
+
# encoding: utf-8
|
|
2
4
|
|
|
3
5
|
require 'strelka' unless defined?( Strelka )
|
|
4
6
|
require 'strelka/app' unless defined?( Strelka::App )
|
|
@@ -13,23 +15,26 @@ require 'strelka/app' unless defined?( Strelka::App )
|
|
|
13
15
|
# class MyApp < Strelka::App
|
|
14
16
|
# plugins :errors
|
|
15
17
|
#
|
|
16
|
-
#
|
|
18
|
+
# # Send an email when an app is going to return a 500 error
|
|
19
|
+
# on_status HTTP::SERVER_ERROR do |res, status|
|
|
20
|
+
# require 'mail'
|
|
21
|
+
# Mail.deliver do
|
|
22
|
+
# from 'app@example.com'
|
|
23
|
+
# to 'team@example.com'
|
|
24
|
+
# subject "SERVER_ERROR: %p [%s]" %
|
|
25
|
+
# [ self.class, self.class.version_string ]
|
|
26
|
+
# body "Server error while running %p [%s]: %s" %
|
|
27
|
+
# [ self.class, self.conn, status.message ]
|
|
28
|
+
# end
|
|
17
29
|
# end
|
|
18
30
|
#
|
|
19
|
-
#
|
|
20
|
-
#
|
|
21
|
-
#
|
|
22
|
-
#
|
|
23
|
-
# class MyApp < Strelka::App
|
|
24
|
-
# plugins :errors, :templating
|
|
25
|
-
#
|
|
26
|
-
# layout 'layout.tmpl'
|
|
27
|
-
# templates :missing => 'errors/missing.tmpl'
|
|
28
|
-
#
|
|
29
|
-
# on_status HTTP::NOT_FOUND, :missing
|
|
31
|
+
# def handle( req )
|
|
32
|
+
# finish_with( HTTP::SERVER_ERROR, "Oops, that doesn't exist on this server." )
|
|
33
|
+
# end
|
|
30
34
|
#
|
|
31
35
|
# end # class MyApp
|
|
32
36
|
#
|
|
37
|
+
# See the documentation for ClassMethods.on_status for more details.
|
|
33
38
|
module Strelka::App::Errors
|
|
34
39
|
extend Strelka::App::Plugin
|
|
35
40
|
|
|
@@ -39,16 +44,53 @@ module Strelka::App::Errors
|
|
|
39
44
|
|
|
40
45
|
|
|
41
46
|
# Class-level functionality
|
|
42
|
-
module ClassMethods
|
|
47
|
+
module ClassMethods
|
|
43
48
|
|
|
44
49
|
@status_handlers = {}
|
|
45
50
|
|
|
46
|
-
# The registered status handler callbacks, keyed by
|
|
51
|
+
# The registered status handler callbacks, keyed by Integer Ranges of
|
|
52
|
+
# status codes to which they apply
|
|
47
53
|
attr_reader :status_handlers
|
|
48
54
|
|
|
49
55
|
|
|
50
|
-
### Register a callback for responses
|
|
51
|
-
###
|
|
56
|
+
### Register a callback for responses whose status code is within the specified
|
|
57
|
+
### +range+. Range can either be a single integer HTTP status code, or a Range
|
|
58
|
+
### of the same (e.g., 400..499) for all statuses with that range.
|
|
59
|
+
###
|
|
60
|
+
### # Handle only status 400 errors
|
|
61
|
+
### on_status HTTP::BAD_REQUEST do |res, status|
|
|
62
|
+
### # Do something on 400 errors
|
|
63
|
+
### end
|
|
64
|
+
###
|
|
65
|
+
### # Handle any other error in the 4xx range
|
|
66
|
+
### on_status 400..499 do |res, status|
|
|
67
|
+
### # Do something on 4xx errors
|
|
68
|
+
### end
|
|
69
|
+
###
|
|
70
|
+
### If no +range+ is specified, any of the HTTP error statuses will invoke
|
|
71
|
+
### the callback.
|
|
72
|
+
###
|
|
73
|
+
### The block will be called with the response object (a subclass of
|
|
74
|
+
### Mongrel2::Response appropriate for the request type), and a hash of
|
|
75
|
+
### status info that will at least contain the following keys:
|
|
76
|
+
###
|
|
77
|
+
### [+:status+] the HTTP status code that was passed to Strelka::App#finish_with
|
|
78
|
+
### [+:message+] the message string that was passed to Strelka::App#finish_with
|
|
79
|
+
###
|
|
80
|
+
### If you have the <tt>:templating</tt> plugin loaded, you can substitute a
|
|
81
|
+
### Symbol that corresponds with one of the declared templates instead:
|
|
82
|
+
#### With the templating plugin, you can also handle it via a custom template.
|
|
83
|
+
###
|
|
84
|
+
### class MyApp < Strelka::App
|
|
85
|
+
### plugins :errors, :templating
|
|
86
|
+
###
|
|
87
|
+
### layout 'layout.tmpl'
|
|
88
|
+
### templates :missing => 'errors/missing.tmpl'
|
|
89
|
+
###
|
|
90
|
+
### on_status HTTP::NOT_FOUND, :missing
|
|
91
|
+
###
|
|
92
|
+
### end # class MyApp
|
|
93
|
+
###
|
|
52
94
|
def on_status( range=DEFAULT_HANDLER_STATUS_RANGE, template=nil, &block )
|
|
53
95
|
range = Range.new( range, range ) unless range.is_a?( Range )
|
|
54
96
|
methodname = "for_status_%s" % [ range.begin, range.end ].uniq.join('_to_')
|
data/lib/strelka/app/filters.rb
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
# -*- ruby -*-
|
|
2
|
+
# vim: set nosta noet ts=4 sw=4:
|
|
3
|
+
# encoding: utf-8
|
|
2
4
|
|
|
3
5
|
require 'strelka' unless defined?( Strelka )
|
|
4
6
|
require 'strelka/app' unless defined?( Strelka::App )
|
|
@@ -11,7 +13,7 @@ require 'strelka/httpresponse/negotiation'
|
|
|
11
13
|
# HTTP Content negotiation for Strelka applications.
|
|
12
14
|
#
|
|
13
15
|
# The application can test the request for which types are accepted, set
|
|
14
|
-
# different response blocks for different acceptable content types, provides
|
|
16
|
+
# different response blocks for different acceptable content types, provides
|
|
15
17
|
# tranformations for entity bodies and set transformations for new content
|
|
16
18
|
# types.
|
|
17
19
|
#
|
|
@@ -69,7 +71,7 @@ module Strelka::App::Negotiation
|
|
|
69
71
|
end # module ClassMethods
|
|
70
72
|
|
|
71
73
|
|
|
72
|
-
### Extension callback -- extend the HTTPRequest and HTTPResponse classes with Negotiation
|
|
74
|
+
### Extension callback -- extend the HTTPRequest and HTTPResponse classes with Negotiation
|
|
73
75
|
### support when this plugin is loaded.
|
|
74
76
|
def self::included( object )
|
|
75
77
|
Strelka.log.debug "Extending Request and Response with Negotiation mixins"
|
|
@@ -1,45 +1,47 @@
|
|
|
1
|
-
|
|
1
|
+
# -*- ruby -*-
|
|
2
|
+
# vim: set nosta noet ts=4 sw=4:
|
|
3
|
+
# encoding: utf-8
|
|
2
4
|
|
|
3
5
|
require 'strelka' unless defined?( Strelka )
|
|
4
6
|
require 'strelka/app' unless defined?( Strelka::App )
|
|
5
7
|
require 'strelka/app/plugins'
|
|
6
|
-
require 'strelka/
|
|
8
|
+
require 'strelka/paramvalidator'
|
|
7
9
|
|
|
8
10
|
|
|
9
11
|
# Parameter validation and untainting for Strelka apps.
|
|
10
12
|
#
|
|
11
13
|
# The application can declare parameters globally, and then override them on a
|
|
12
14
|
# per-route basis:
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
#
|
|
15
|
+
#
|
|
16
|
+
# class UserManager < Strelka::App
|
|
17
|
+
#
|
|
16
18
|
# plugins :routing, :parameters
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
+
#
|
|
20
|
+
# param :username, /\w+/, "User login", :required
|
|
19
21
|
# param :email
|
|
20
|
-
#
|
|
22
|
+
# param :id, /\d+/, "The user's numeric ID"
|
|
21
23
|
# param :mode, ['add', 'remove']
|
|
22
|
-
#
|
|
23
|
-
#
|
|
24
|
-
#
|
|
25
|
-
#
|
|
26
|
-
#
|
|
27
|
-
#
|
|
28
|
-
#
|
|
29
|
-
#
|
|
30
|
-
#
|
|
31
|
-
#
|
|
32
|
-
#
|
|
33
|
-
#
|
|
34
|
-
#
|
|
35
|
-
#
|
|
24
|
+
#
|
|
25
|
+
# # :username gets validated and merged into query args; URI parameters
|
|
26
|
+
# # clobber query params
|
|
27
|
+
# get '/info/:username', :params => { :id => /[XRT]\d{4}-\d{8}/ } do |req|
|
|
28
|
+
# req.params.okay?
|
|
29
|
+
# req.params[:username]
|
|
30
|
+
# req.params.values_at( :id, :username )
|
|
31
|
+
# req.params.username
|
|
32
|
+
#
|
|
33
|
+
# req.params.error_messages
|
|
34
|
+
# end
|
|
35
|
+
#
|
|
36
|
+
# end # class UserManager
|
|
37
|
+
#
|
|
36
38
|
#
|
|
37
39
|
# == To-Do
|
|
38
|
-
#
|
|
40
|
+
#
|
|
39
41
|
# _We may add support for other ways of passing parameters later,
|
|
40
42
|
# e.g., via structured entity bodies like JSON, XML, YAML, etc_.
|
|
41
|
-
#
|
|
42
|
-
#
|
|
43
|
+
#
|
|
44
|
+
#
|
|
43
45
|
module Strelka::App::Parameters
|
|
44
46
|
extend Strelka::App::Plugin
|
|
45
47
|
|
|
@@ -80,8 +82,8 @@ module Strelka::App::Parameters
|
|
|
80
82
|
|
|
81
83
|
|
|
82
84
|
### Declare a parameter with the specified +name+ that will be validated using the given
|
|
83
|
-
### +constraint+. The +constraint+ can be any of the types supported by
|
|
84
|
-
### Strelka::
|
|
85
|
+
### +constraint+. The +constraint+ can be any of the types supported by
|
|
86
|
+
### Strelka::ParamValidator.
|
|
85
87
|
### :call-seq:
|
|
86
88
|
# param( name, *flags )
|
|
87
89
|
# param( name, constraint, *flags )
|
|
@@ -98,7 +100,7 @@ module Strelka::App::Parameters
|
|
|
98
100
|
# description ||= name.to_s.capitalize
|
|
99
101
|
flags = args
|
|
100
102
|
|
|
101
|
-
# Give a regexp constraint a named capture group for the constraint name if it
|
|
103
|
+
# Give a regexp constraint a named capture group for the constraint name if it
|
|
102
104
|
# doesn't already have one
|
|
103
105
|
if constraint.is_a?( Regexp )
|
|
104
106
|
constraint = Regexp.compile( "(?<#{name}>" + constraint.to_s + ")" ) unless
|
|
@@ -143,7 +145,7 @@ module Strelka::App::Parameters
|
|
|
143
145
|
sub_res = constraint.map( &self.method(:extract_route_from_constraint) )
|
|
144
146
|
Regexp.union( sub_res )
|
|
145
147
|
when Symbol
|
|
146
|
-
re = Strelka::
|
|
148
|
+
re = Strelka::ParamValidator.pattern_for_constraint( constraint ) or
|
|
147
149
|
raise ScriptError, "no pattern for %p constraint" % [ constraint ]
|
|
148
150
|
/(?<#{name}>#{re})/
|
|
149
151
|
else
|
|
@@ -176,7 +178,7 @@ module Strelka::App::Parameters
|
|
|
176
178
|
def handle_request( request, &block )
|
|
177
179
|
profile = self.make_validator_profile( request )
|
|
178
180
|
self.log.debug "Applying validator profile: %p" % [ profile ]
|
|
179
|
-
validator = Strelka::
|
|
181
|
+
validator = Strelka::ParamValidator.new( profile, request.params )
|
|
180
182
|
self.log.debug " validator: %p" % [ validator ]
|
|
181
183
|
|
|
182
184
|
request.params = validator
|
|
@@ -185,7 +187,7 @@ module Strelka::App::Parameters
|
|
|
185
187
|
|
|
186
188
|
|
|
187
189
|
|
|
188
|
-
### Make a validator profile for Strelka::
|
|
190
|
+
### Make a validator profile for Strelka::ParamValidator for the specified
|
|
189
191
|
### +request+ using the declared parameters in the App, returning it as a Hash.
|
|
190
192
|
def make_validator_profile( request )
|
|
191
193
|
profile = {
|