nitro 0.8.0 → 0.9.3
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/AUTHORS +3 -4
- data/ChangeLog +418 -0
- data/LICENSE +1 -1
- data/README +157 -89
- data/RELEASES +50 -0
- data/Rakefile +5 -7
- data/benchmark/nitro/bench.rb +5 -0
- data/benchmark/nitro/simple-webrick-n-200.txt +44 -0
- data/benchmark/nitro/static-webrick-n-200.txt +43 -0
- data/benchmark/nitro/tiny-lhttpd-n-200-c-5.txt +43 -0
- data/benchmark/nitro/tiny-webrick-n-200-c-5.txt +44 -0
- data/benchmark/nitro/tiny-webrick-n-200.txt +44 -0
- data/benchmark/nitro/tiny2-webrick-n-200.txt +44 -0
- data/{lib/nitro/server/cluster.rb → bin/cluster} +26 -30
- data/bin/proto/README +2 -2
- data/bin/proto/{apache.conf → conf/apache.conf} +0 -0
- data/bin/proto/conf/app.conf.rb +22 -0
- data/bin/proto/conf/lhttpd.conf +236 -0
- data/bin/proto/ctl +4 -0
- data/bin/proto/lib/README +5 -0
- data/bin/proto/log/README +3 -0
- data/bin/proto/root/fcgi.rb +6 -0
- data/bin/proto/root/index.xhtml +65 -7
- data/bin/proto/root/m/nitro.png +0 -0
- data/examples/blog/README +7 -5
- data/examples/blog/{apache.conf → conf/apache.conf} +0 -0
- data/examples/blog/conf/app.conf.rb +56 -0
- data/examples/blog/conf/lhttpd.conf +236 -0
- data/examples/blog/ctl +4 -0
- data/examples/blog/lib/blog.rb +11 -136
- data/examples/blog/lib/blog/controller.rb +99 -0
- data/examples/blog/lib/blog/model.rb +39 -0
- data/examples/blog/log/README +3 -0
- data/examples/blog/root/comments.xhtml +2 -2
- data/examples/blog/root/fcgi.rb +6 -0
- data/examples/blog/root/index.xhtml +4 -5
- data/examples/blog/root/login.xhtml +2 -2
- data/examples/blog/root/style.xsl +9 -9
- data/examples/blog/root/view_entry.xhtml +2 -2
- data/examples/flash/conf/app.conf.rb +23 -0
- data/examples/flash/ctl +4 -0
- data/examples/flash/log/README +3 -0
- data/examples/flash/root/index.xhtml +0 -9
- data/examples/flash/root/show_inline_text.xhtml +10 -5
- data/examples/no_xsl_blog/README +12 -0
- data/examples/no_xsl_blog/conf/apache.conf +0 -0
- data/examples/no_xsl_blog/conf/app.conf.rb +57 -0
- data/examples/no_xsl_blog/conf/lhttpd.conf +236 -0
- data/examples/no_xsl_blog/ctl +4 -0
- data/examples/no_xsl_blog/lib/blog.rb +20 -0
- data/examples/no_xsl_blog/lib/blog/controller.rb +102 -0
- data/examples/no_xsl_blog/lib/blog/model.rb +39 -0
- data/examples/no_xsl_blog/lib/blog/template.rb +134 -0
- data/examples/no_xsl_blog/log/README +3 -0
- data/examples/no_xsl_blog/root/comments.xhtml +41 -0
- data/examples/no_xsl_blog/root/entry_form.xhtml +22 -0
- data/examples/no_xsl_blog/root/fcgi.rb +6 -0
- data/examples/no_xsl_blog/root/index.xhtml +39 -0
- data/examples/no_xsl_blog/root/login.xhtml +21 -0
- data/examples/no_xsl_blog/root/m/bubbles.gif +0 -0
- data/examples/no_xsl_blog/root/m/comments_curve.gif +0 -0
- data/examples/no_xsl_blog/root/m/down.gif +0 -0
- data/examples/no_xsl_blog/root/m/footer_bg.gif +0 -0
- data/examples/no_xsl_blog/root/m/garrow.gif +0 -0
- data/examples/no_xsl_blog/root/m/gbull.gif +0 -0
- data/examples/no_xsl_blog/root/m/grbull.gif +0 -0
- data/examples/no_xsl_blog/root/m/h1_bg.gif +0 -0
- data/examples/no_xsl_blog/root/m/header_bg.gif +0 -0
- data/examples/no_xsl_blog/root/m/nitro.gif +0 -0
- data/examples/no_xsl_blog/root/m/obull.gif +0 -0
- data/examples/no_xsl_blog/root/m/page_bg.gif +0 -0
- data/examples/no_xsl_blog/root/m/rss.gif +0 -0
- data/examples/no_xsl_blog/root/m/side_title_bg.gif +0 -0
- data/examples/no_xsl_blog/root/m/sidebar_bg.gif +0 -0
- data/examples/no_xsl_blog/root/recent_posts.xhtml +14 -0
- data/examples/no_xsl_blog/root/style.css +301 -0
- data/examples/no_xsl_blog/root/view_entry.xhtml +25 -0
- data/examples/no_xsl_blog/root/view_entry.xml +12 -0
- data/examples/og/run.rb +2 -2
- data/examples/tiny/README +2 -2
- data/examples/tiny/conf/apache.conf +5 -0
- data/examples/tiny/conf/app.conf.rb +21 -0
- data/examples/tiny/conf/lhttpd.conf +236 -0
- data/examples/tiny/ctl +4 -0
- data/examples/tiny/log/README +3 -0
- data/examples/tiny/root/fcgi.rb +6 -0
- data/examples/tiny/root/index.xhtml +7 -4
- data/examples/tiny/root/nitro.png +0 -0
- data/lib/glue.rb +13 -9
- data/lib/glue/array.rb +1 -1
- data/lib/glue/cache.rb +1 -1
- data/lib/glue/flexob.rb +12 -0
- data/lib/glue/hash.rb +1 -1
- data/lib/glue/inflector.rb +2 -2
- data/lib/glue/logger.rb +4 -8
- data/lib/glue/misc.rb +14 -0
- data/lib/glue/number.rb +1 -1
- data/lib/glue/object.rb +26 -0
- data/lib/glue/pool.rb +1 -1
- data/lib/glue/property.rb +84 -91
- data/lib/glue/string.rb +1 -1
- data/lib/glue/time.rb +1 -1
- data/lib/glue/validation.rb +1 -1
- data/lib/nitro.rb +18 -6
- data/lib/nitro/adaptors/cgi.rb +291 -0
- data/lib/nitro/adaptors/fastcgi.rb +42 -0
- data/lib/nitro/adaptors/runner.rb +123 -0
- data/lib/nitro/adaptors/webrick.rb +110 -0
- data/lib/nitro/buffering.rb +43 -0
- data/lib/nitro/builders/form.rb +1 -1
- data/lib/nitro/builders/rss.rb +1 -1
- data/{bin → lib/nitro}/cluster.rb +26 -30
- data/lib/nitro/context.rb +82 -0
- data/lib/nitro/controller.rb +50 -0
- data/lib/nitro/cookie.rb +46 -0
- data/lib/nitro/dispatcher.rb +105 -0
- data/lib/nitro/filters.rb +9 -10
- data/lib/nitro/localization.rb +42 -0
- data/lib/nitro/mail.rb +11 -14
- data/lib/nitro/render.rb +275 -0
- data/lib/nitro/request.rb +128 -0
- data/lib/nitro/response.rb +38 -0
- data/lib/nitro/scaffold.rb +11 -11
- data/lib/nitro/session.rb +84 -0
- data/lib/nitro/{server/shaders.rb → shaders.rb} +56 -36
- data/lib/nitro/ui/pager.rb +23 -26
- data/lib/nitro/{sitemap.rb → ui/sitemap.rb} +4 -12
- data/lib/nitro/uri.rb +1 -1
- data/lib/nitro/version.rb +10 -8
- data/lib/og.rb +66 -65
- data/lib/og/backend.rb +1 -1
- data/lib/og/backends/mysql.rb +48 -52
- data/lib/og/backends/psql.rb +34 -37
- data/lib/og/connection.rb +15 -15
- data/lib/og/enchant.rb +16 -9
- data/lib/og/meta.rb +127 -54
- data/lib/og/mock.rb +18 -18
- data/lib/og/version.rb +6 -4
- data/lib/parts/content.rb +4 -8
- data/test/glue/tc_logger.rb +3 -0
- data/test/glue/tc_property.rb +19 -3
- data/test/nitro/adaptors/tc_cgi.rb +63 -0
- data/test/nitro/adaptors/tc_webrick.rb +15 -0
- data/test/nitro/builders/tc_xml.rb +2 -2
- data/test/nitro/tc_context.rb +13 -0
- data/test/nitro/tc_controller.rb +47 -0
- data/test/nitro/tc_dispatcher.rb +64 -0
- data/test/nitro/tc_session.rb +20 -0
- data/test/nitro/{tc_sitemap.rb → ui/tc_sitemap.rb} +1 -1
- data/test/root/blog/list.xhtml +6 -0
- data/test/tc_og.rb +41 -4
- metadata +115 -59
- data/bin/proto/app.rb +0 -20
- data/bin/proto/config.rb +0 -77
- data/examples/blog/app.rb +0 -21
- data/examples/blog/config.rb +0 -95
- data/examples/blog/env.rb +0 -22
- data/examples/flash/README +0 -34
- data/examples/flash/app.rb +0 -20
- data/examples/flash/config.rb +0 -38
- data/examples/flash/lib/flash.rb +0 -40
- data/examples/flash/tmp.swf +0 -0
- data/examples/tiny/app.rb +0 -19
- data/examples/tiny/config.rb +0 -29
- data/examples/tiny/root/nitro-small.png +0 -0
- data/lib/nitro/application.rb +0 -217
- data/lib/nitro/config.rb +0 -128
- data/lib/nitro/events.rb +0 -122
- data/lib/nitro/html.rb +0 -151
- data/lib/nitro/http.rb +0 -102
- data/lib/nitro/l10n.rb +0 -30
- data/lib/nitro/server.rb +0 -59
- data/lib/nitro/server/appserver.rb +0 -67
- data/lib/nitro/server/cookie.rb +0 -87
- data/lib/nitro/server/dispatcher.rb +0 -62
- data/lib/nitro/server/filters.rb +0 -75
- data/lib/nitro/server/filters/autologin.rb +0 -51
- data/lib/nitro/server/fragment.rb +0 -70
- data/lib/nitro/server/handlers.rb +0 -127
- data/lib/nitro/server/render.rb +0 -426
- data/lib/nitro/server/request.rb +0 -658
- data/lib/nitro/server/requestpart.rb +0 -54
- data/lib/nitro/server/script.rb +0 -387
- data/lib/nitro/server/server.rb +0 -57
- data/lib/nitro/server/session.rb +0 -220
- data/lib/nitro/server/user.rb +0 -46
- data/lib/nitro/server/webrick.rb +0 -180
- data/lib/nitro/service.rb +0 -26
- data/lib/xsl/ui.xsl +0 -51
- data/lib/xsl/xforms.xsl +0 -28
- data/test/nitro/server/tc_cookie.rb +0 -34
- data/test/nitro/server/tc_filters.rb +0 -38
- data/test/nitro/server/tc_request.rb +0 -70
- data/test/nitro/server/tc_requestpart.rb +0 -28
- data/test/nitro/server/tc_session.rb +0 -34
- data/test/nitro/tc_events.rb +0 -44
- data/test/nitro/tc_html.rb +0 -79
- data/test/nitro/tc_http.rb +0 -18
data/lib/nitro/server/session.rb
DELETED
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
# code:
|
|
2
|
-
# * George Moschovitis <gm@navel.gr>
|
|
3
|
-
#
|
|
4
|
-
# (c) 2002-2003 Navel, all rights reserved.
|
|
5
|
-
# $Id: session.rb 167 2004-11-23 14:03:10Z gmosx $
|
|
6
|
-
|
|
7
|
-
require "md5"
|
|
8
|
-
|
|
9
|
-
require "glue/hash"
|
|
10
|
-
require "nitro/server/user"
|
|
11
|
-
|
|
12
|
-
module N
|
|
13
|
-
|
|
14
|
-
# = SessionManager
|
|
15
|
-
#
|
|
16
|
-
# This object manages session objects. Several utility methods
|
|
17
|
-
# are also provided.
|
|
18
|
-
#
|
|
19
|
-
# === WARNING:
|
|
20
|
-
#
|
|
21
|
-
# This object is typically called in a distributed configuration.
|
|
22
|
-
# Avoid writting methods that accept or return big objects!
|
|
23
|
-
#
|
|
24
|
-
# SOS: This object lives in the Cluster!
|
|
25
|
-
#
|
|
26
|
-
class SessionManager < N::SafeHash
|
|
27
|
-
# the collection of online users.
|
|
28
|
-
attr_reader :online
|
|
29
|
-
|
|
30
|
-
def initialize
|
|
31
|
-
super
|
|
32
|
-
@online = N::SafeHash.new
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
# Return the number of anonymous sessions.
|
|
36
|
-
#
|
|
37
|
-
def anonymous_count
|
|
38
|
-
return self.size - @online.size
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
# Login a named user.
|
|
42
|
-
# The caller may pass user.to_html instead of the user name.
|
|
43
|
-
# this method is distributed keep a lightweight
|
|
44
|
-
# signature. By using @online.keys i get access to the
|
|
45
|
-
# oids and in this way to the full objects.
|
|
46
|
-
#
|
|
47
|
-
def login(user_oid, user_name)
|
|
48
|
-
@online[user_oid] = user_name
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
# Logout a named user.
|
|
52
|
-
#
|
|
53
|
-
def logout(user_oid)
|
|
54
|
-
@online.delete(user_oid)
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
# Returns the session for the given user.
|
|
58
|
-
#
|
|
59
|
-
def session_for_user(user)
|
|
60
|
-
return values().find { |s| user.oid == s.user.oid }
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
# Returns the session for the given user.
|
|
64
|
-
#
|
|
65
|
-
def session_for_name(name)
|
|
66
|
-
return values().find { |s| name == s.user.name }
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
# garbage collect stale sessions
|
|
70
|
-
#
|
|
71
|
-
# === TODO:
|
|
72
|
-
#
|
|
73
|
-
# - add unit testing.
|
|
74
|
-
#
|
|
75
|
-
def self.garbage_collect!
|
|
76
|
-
# gmosx: the only way to get it to ruby with
|
|
77
|
-
# druby, aaarghhh!! Rethink this though! perhaps some
|
|
78
|
-
# fixes i made allow for recoding this.
|
|
79
|
-
for key in $sessions.keys()
|
|
80
|
-
begin
|
|
81
|
-
session = $sessions[key]
|
|
82
|
-
if session.stale?
|
|
83
|
-
Logger.debug "Session finalized: logging out idle user '#{session.user}'" if $DBG
|
|
84
|
-
session.logout()
|
|
85
|
-
$sessions.delete(key)
|
|
86
|
-
end
|
|
87
|
-
rescue Exception, StandardError => e
|
|
88
|
-
Logger.error "Session gc errror #$!"
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
# = Session
|
|
95
|
-
#
|
|
96
|
-
# This object encapsulates a session.
|
|
97
|
-
#
|
|
98
|
-
# === Design:
|
|
99
|
-
#
|
|
100
|
-
# The session should be persistable to survive server shutdowns.
|
|
101
|
-
#
|
|
102
|
-
# === Usage
|
|
103
|
-
#
|
|
104
|
-
# State is a neccessary evil but try to avoid using session
|
|
105
|
-
# variables as much as possible. Session state is typically
|
|
106
|
-
# distributed to many servers so avoid storing complete objects
|
|
107
|
-
# in session variables, only store oids and integer/strings.
|
|
108
|
-
#
|
|
109
|
-
class Session < Hash
|
|
110
|
-
COOKIE_NAME = "nsid"
|
|
111
|
-
|
|
112
|
-
attr_reader :session_id
|
|
113
|
-
|
|
114
|
-
# keep the user to allow for session lookup based on user.
|
|
115
|
-
# also do NOT keep the full user as an object in the session hash
|
|
116
|
-
# to optimize druby usage!
|
|
117
|
-
#
|
|
118
|
-
attr_accessor :user
|
|
119
|
-
|
|
120
|
-
# the last touch time
|
|
121
|
-
attr_accessor :touch_time
|
|
122
|
-
|
|
123
|
-
# Initializs the session.
|
|
124
|
-
#
|
|
125
|
-
def initialize(sid, request = nil)
|
|
126
|
-
super()
|
|
127
|
-
@session_id = sid
|
|
128
|
-
@touch_time = Time.now
|
|
129
|
-
@user = N::AnonymousUser.instance()
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
# Login a user
|
|
133
|
-
#
|
|
134
|
-
# Returns false for banned users.
|
|
135
|
-
#
|
|
136
|
-
def login(request, user)
|
|
137
|
-
return false if user.banned?
|
|
138
|
-
@user = user
|
|
139
|
-
@user.login(request)
|
|
140
|
-
$sessions.login(@user.oid, @user.name)
|
|
141
|
-
Logger.info "User '#{user}' logged in!"
|
|
142
|
-
return true
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
# Logout a user
|
|
146
|
-
#
|
|
147
|
-
def logout()
|
|
148
|
-
self.clear()
|
|
149
|
-
@user.logout()
|
|
150
|
-
$sessions.logout(@user.oid)
|
|
151
|
-
Logger.info "User '#{user}' logged out!"
|
|
152
|
-
@user = N::AnonymousUser.instance
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
#
|
|
156
|
-
#
|
|
157
|
-
def touch
|
|
158
|
-
@touch_time = Time.now
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
#
|
|
162
|
-
#
|
|
163
|
-
def stale?
|
|
164
|
-
timeout = @user.anonymous? ? $srv_anon_session_timeout : $srv_session_timeout
|
|
165
|
-
return (Time.now - @touch_time > timeout)
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
# call this method to synchronize the session with other servers
|
|
169
|
-
# in the cluster.
|
|
170
|
-
#
|
|
171
|
-
def synchronize!
|
|
172
|
-
# gmosx: TODO, add a check if the session is allready
|
|
173
|
-
# synchronized.
|
|
174
|
-
$sessions[@session_id] = self
|
|
175
|
-
end
|
|
176
|
-
|
|
177
|
-
# Refresh session entities.
|
|
178
|
-
#
|
|
179
|
-
# Call this when you manually change entities stored in the
|
|
180
|
-
# session. A typical scenario is when you change an online user.
|
|
181
|
-
#
|
|
182
|
-
# === Warning: the current version only refreshes the "USER" entity.
|
|
183
|
-
#
|
|
184
|
-
def refresh!
|
|
185
|
-
@user = $og.load(@user.oid, @user.class) if @user
|
|
186
|
-
end
|
|
187
|
-
|
|
188
|
-
# Calculates a unique id.
|
|
189
|
-
#
|
|
190
|
-
# The session id must be unique, a monotonically increasing function
|
|
191
|
-
# like time is appropriate. Random may produce equal ids? add a prefix
|
|
192
|
-
# (SALT) to stop hackers from creating session_ids.
|
|
193
|
-
#
|
|
194
|
-
# TODO:
|
|
195
|
-
# make the prefix configurable
|
|
196
|
-
#
|
|
197
|
-
def self.calculate_id
|
|
198
|
-
time = Time.now
|
|
199
|
-
# FIXME: make this more random?
|
|
200
|
-
id = Digest::MD5.md5("SALT#{time.to_i} #{time.tv_usec}").to_s
|
|
201
|
-
return id
|
|
202
|
-
end
|
|
203
|
-
|
|
204
|
-
# Initialize sessions garbage collection.
|
|
205
|
-
#
|
|
206
|
-
# WARNING: this is not used yet!
|
|
207
|
-
#
|
|
208
|
-
def self.initialize_gc(session_manager, interval)
|
|
209
|
-
# gmosx, FIXME: store this in a variable.
|
|
210
|
-
Thread.new {
|
|
211
|
-
loop do
|
|
212
|
-
sleep(interval)
|
|
213
|
-
garbage_collect(session_manager.sessions)
|
|
214
|
-
end
|
|
215
|
-
}
|
|
216
|
-
end
|
|
217
|
-
|
|
218
|
-
end
|
|
219
|
-
|
|
220
|
-
end # module
|
data/lib/nitro/server/user.rb
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
# code:
|
|
2
|
-
# * George Moschovitis <gm@navel.gr>
|
|
3
|
-
#
|
|
4
|
-
# (c) 2004 Navel, all rights reserved.
|
|
5
|
-
# $Id: user.rb 99 2004-10-22 09:50:28Z gmosx $
|
|
6
|
-
|
|
7
|
-
require "singleton"
|
|
8
|
-
|
|
9
|
-
module N
|
|
10
|
-
|
|
11
|
-
# = Anonymous User
|
|
12
|
-
#
|
|
13
|
-
# An anonymous user of the Web Application. This is a base
|
|
14
|
-
# object, typically extended by the users part.
|
|
15
|
-
#
|
|
16
|
-
# Implemented as singleton.
|
|
17
|
-
#
|
|
18
|
-
class AnonymousUser
|
|
19
|
-
include Singleton
|
|
20
|
-
|
|
21
|
-
attr_accessor :name
|
|
22
|
-
attr_accessor :locale
|
|
23
|
-
attr_accessor :shader
|
|
24
|
-
|
|
25
|
-
def initialize
|
|
26
|
-
super
|
|
27
|
-
@name = "anonymous"
|
|
28
|
-
@locale = "en"
|
|
29
|
-
@shader = $default_shader
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def anonymous?
|
|
33
|
-
true
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def login
|
|
37
|
-
# nop
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def logout
|
|
41
|
-
# nop
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
end # module
|
data/lib/nitro/server/webrick.rb
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
# code:
|
|
2
|
-
# * George Moschovitis <gm@navel.gr>
|
|
3
|
-
#
|
|
4
|
-
# (c) 2004 Navel, all rights reserved.
|
|
5
|
-
# $Id: webrick.rb 200 2004-12-27 11:24:41Z gmosx $
|
|
6
|
-
|
|
7
|
-
require "webrick"
|
|
8
|
-
|
|
9
|
-
require "nitro/server/appserver"
|
|
10
|
-
require "nitro/server/dispatcher"
|
|
11
|
-
require "nitro/server/render"
|
|
12
|
-
|
|
13
|
-
# Override WEBrick to suit our needs.
|
|
14
|
-
# Did I mention that WEBrick SUCKS ?
|
|
15
|
-
#
|
|
16
|
-
module WEBrick
|
|
17
|
-
|
|
18
|
-
class HTTPRequest
|
|
19
|
-
|
|
20
|
-
# Allow external setting of cookies.
|
|
21
|
-
#
|
|
22
|
-
def cookies=(val)
|
|
23
|
-
@cookies = val
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
# Allow external setting of query.
|
|
27
|
-
#
|
|
28
|
-
def set_query(query_string)
|
|
29
|
-
@query_string = query_string
|
|
30
|
-
@query = WEBrick::HTTPUtils::parse_query(query_string)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
# Return the referer to this resource. For the initial page in the
|
|
34
|
-
# clickstream there is no referer, set "/" by default.
|
|
35
|
-
#
|
|
36
|
-
def referer
|
|
37
|
-
return @header["referer"][0] || "/"
|
|
38
|
-
end
|
|
39
|
-
alias_method :referrer, :referer
|
|
40
|
-
|
|
41
|
-
# Populate an object from request parameters.
|
|
42
|
-
# This is a truly dangerous method.
|
|
43
|
-
#
|
|
44
|
-
EXCLUDED_PARAMETERS = %w{ oid name }
|
|
45
|
-
def fill(obj, name = nil)
|
|
46
|
-
# if an object is passed create an instance.
|
|
47
|
-
obj = obj.new if obj.is_a?(Class)
|
|
48
|
-
|
|
49
|
-
@query.each do |param, val|
|
|
50
|
-
begin
|
|
51
|
-
# gmosx: DO NOT escape by default !!!
|
|
52
|
-
if not EXCLUDED_PARAMETERS.include?(param)
|
|
53
|
-
obj.send("__force_#{param}", val)
|
|
54
|
-
end
|
|
55
|
-
rescue NameError
|
|
56
|
-
next
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
return obj
|
|
61
|
-
end
|
|
62
|
-
alias_method :populate, :fill
|
|
63
|
-
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
end # module
|
|
67
|
-
|
|
68
|
-
module N
|
|
69
|
-
|
|
70
|
-
# = WebrickServer
|
|
71
|
-
#
|
|
72
|
-
# The Application Server. Handles dynamic requests in a web application.
|
|
73
|
-
# Dont keepalive (or use a VERY SMALL keepalive). Typically this server
|
|
74
|
-
# is used along with a standard http server that handles static
|
|
75
|
-
# resources like images, css.
|
|
76
|
-
#
|
|
77
|
-
# Used temporarily unitl we build our own app server.
|
|
78
|
-
#
|
|
79
|
-
class WebrickServer < N::AppServer
|
|
80
|
-
include WEBrick
|
|
81
|
-
|
|
82
|
-
# the integrated webrick server.
|
|
83
|
-
attr_accessor :webrick
|
|
84
|
-
|
|
85
|
-
def initialize(name = "WebrickServer")
|
|
86
|
-
super
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
# Start the application server.
|
|
90
|
-
#
|
|
91
|
-
def start
|
|
92
|
-
Socket.do_not_reverse_lookup = true # patch for OS X
|
|
93
|
-
|
|
94
|
-
=begin
|
|
95
|
-
accesslog = WEBrick::BasicLog::new('/dev/null')
|
|
96
|
-
referer = WEBrick::BasicLog::new('/dev/null')
|
|
97
|
-
=end
|
|
98
|
-
|
|
99
|
-
accesslog = WEBrick::BasicLog::new('log/access.log')
|
|
100
|
-
referer = WEBrick::BasicLog::new('log/referer.log')
|
|
101
|
-
|
|
102
|
-
@webrick = WEBrick::HTTPServer.new(
|
|
103
|
-
:BindAddress => $appsrv_address,
|
|
104
|
-
:Port => $appsrv_port,
|
|
105
|
-
:DocumentRoot => $root_dir,
|
|
106
|
-
:AccessLog => [
|
|
107
|
-
[accesslog, AccessLog::COMMON_LOG_FORMAT],
|
|
108
|
-
[referer, AccessLog::REFERER_LOG_FORMAT]
|
|
109
|
-
]
|
|
110
|
-
)
|
|
111
|
-
|
|
112
|
-
@webrick.mount('/', N::WebrickDispatcher)
|
|
113
|
-
|
|
114
|
-
trap("INT") { @webrick.shutdown }
|
|
115
|
-
@webrick.start
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
# Stop the application server.
|
|
119
|
-
#
|
|
120
|
-
def stop
|
|
121
|
-
@webrick.stop
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
# = WebrickDispatcher
|
|
127
|
-
#
|
|
128
|
-
class WebrickDispatcher < WEBrick::HTTPServlet::AbstractServlet
|
|
129
|
-
include N::Dispatcher
|
|
130
|
-
|
|
131
|
-
def initialize(server)
|
|
132
|
-
# Handles static resources. Useful when running a standalone
|
|
133
|
-
# webrick server.
|
|
134
|
-
@file_handler = WEBrick::HTTPServlet::FileHandler.new(server, $root_dir, {:FancyIndexing => true })
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
def do_GET(request, response)
|
|
138
|
-
path = request.request_uri.path
|
|
139
|
-
|
|
140
|
-
# rationalize cookies, WEBrick just SUCKS!!
|
|
141
|
-
tmp = {}
|
|
142
|
-
request.cookies.each { |c|
|
|
143
|
-
tmp[c.name] = c
|
|
144
|
-
}
|
|
145
|
-
request.cookies = tmp
|
|
146
|
-
|
|
147
|
-
if path =~ /\./
|
|
148
|
-
@file_handler.do_GET(request, response)
|
|
149
|
-
else
|
|
150
|
-
process(request, response)
|
|
151
|
-
end
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
alias :do_POST :do_GET
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
# Create session
|
|
158
|
-
#
|
|
159
|
-
def create_session(request, response)
|
|
160
|
-
session = nil
|
|
161
|
-
|
|
162
|
-
if cookie = request.cookies[N::Session::COOKIE_NAME]
|
|
163
|
-
session = $sessions[cookie.value]
|
|
164
|
-
end
|
|
165
|
-
|
|
166
|
-
unless session
|
|
167
|
-
Logger.debug 'Creating new session.' if $DBG
|
|
168
|
-
# no session cookie or stale session (garbage collected).
|
|
169
|
-
session_id = N::Session.calculate_id()
|
|
170
|
-
cookie = WEBrick::Cookie.new(N::Session::COOKIE_NAME, session_id)
|
|
171
|
-
response.cookies << cookie
|
|
172
|
-
session = $sessions[session_id] = N::Session.new(session_id)
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
return session
|
|
176
|
-
end
|
|
177
|
-
|
|
178
|
-
end
|
|
179
|
-
|
|
180
|
-
end # module
|
data/lib/nitro/service.rb
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
# code:
|
|
2
|
-
# * George Moschovitis <gm@navel.gr>
|
|
3
|
-
#
|
|
4
|
-
# (c) 2004 Navel, all rights reserved.
|
|
5
|
-
# $Id: service.rb 185 2004-12-10 13:29:09Z gmosx $
|
|
6
|
-
|
|
7
|
-
require 'nitro/server/render'
|
|
8
|
-
require 'nitro/scaffold'
|
|
9
|
-
require 'nitro/filters'
|
|
10
|
-
|
|
11
|
-
module N
|
|
12
|
-
|
|
13
|
-
# = Service
|
|
14
|
-
#
|
|
15
|
-
# Defines an application service.
|
|
16
|
-
#
|
|
17
|
-
class Service
|
|
18
|
-
include N::Render
|
|
19
|
-
include N::Scaffolding
|
|
20
|
-
include N::Filtering
|
|
21
|
-
|
|
22
|
-
# The base path of the service, essentially the mount point.
|
|
23
|
-
attr :base_path
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
end # module
|