hayabusa 0.0.24 → 0.0.25
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +2 -2
- data/Gemfile.lock +37 -6
- data/README.md +363 -0
- data/VERSION +1 -1
- data/bin/hayabusa_fcgi_server.rb +0 -1
- data/hayabusa.gemspec +14 -13
- data/lib/hayabusa.rb +7 -3
- data/lib/hayabusa_cgi_tools.rb +4 -2
- data/lib/hayabusa_client_session.rb +3 -1
- data/lib/hayabusa_ext/mailing.rb +8 -7
- data/lib/hayabusa_ext/web.rb +5 -0
- data/lib/hayabusa_fcgi.rb +13 -4
- data/lib/hayabusa_http_session.rb +2 -0
- data/lib/hayabusa_http_session_contentgroup.rb +7 -1
- data/lib/hayabusa_http_session_request.rb +7 -1
- data/lib/kernel_ext/magic_methods.rb +4 -0
- data/spec/hayabusa_spec.rb +1 -1
- metadata +53 -86
- data/README.rdoc +0 -315
data/README.rdoc
DELETED
@@ -1,315 +0,0 @@
|
|
1
|
-
= hayabusa
|
2
|
-
|
3
|
-
This is a multithreadded webserver that runs under Ruby 1.9.2 or JRuby. It runs under one single process and is able to handle multiple simultanious HTTP requests with thread-safety.
|
4
|
-
|
5
|
-
It uses ERubis to parse .rhtml files and caches the bytecode for Ruby-files.
|
6
|
-
|
7
|
-
|
8
|
-
== Contributing to hayabusa
|
9
|
-
|
10
|
-
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
11
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
12
|
-
* Fork the project
|
13
|
-
* Start a feature/bugfix branch
|
14
|
-
* Commit and push until you are happy with your contribution
|
15
|
-
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
16
|
-
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
17
|
-
|
18
|
-
== Copyright
|
19
|
-
|
20
|
-
Copyright (c) 2011 Kasper Johansen. See LICENSE.txt for
|
21
|
-
further details.
|
22
|
-
|
23
|
-
== Installing
|
24
|
-
|
25
|
-
gem install hayabusa
|
26
|
-
|
27
|
-
|
28
|
-
== Usage
|
29
|
-
|
30
|
-
=== Basic example
|
31
|
-
|
32
|
-
Create a file called "start.rb":
|
33
|
-
|
34
|
-
require "rubygems"
|
35
|
-
require "hayabusa"
|
36
|
-
|
37
|
-
require "knjrbfw"
|
38
|
-
require "sqlite3"
|
39
|
-
|
40
|
-
appsrv = Hayabusa.new(
|
41
|
-
:port => 10080,
|
42
|
-
:doc_root => "#{File.dirname(__FILE__)}/doc_root",
|
43
|
-
:db => Knj::Db.new(
|
44
|
-
:type => "sqlite3",
|
45
|
-
:path => "#{File.dirname(__FILE__)}/test.sqlite3"
|
46
|
-
)
|
47
|
-
)
|
48
|
-
appsrv.update_db #creates missing tables, columns, indexes or other stuff it needs.
|
49
|
-
appsrv.start
|
50
|
-
appsrv.join
|
51
|
-
|
52
|
-
|
53
|
-
Place a file called "index.rhtml" with the start-script and write something like:
|
54
|
-
|
55
|
-
<%
|
56
|
-
print "Hello world."
|
57
|
-
%>
|
58
|
-
|
59
|
-
|
60
|
-
Then go to your browser and type "localhost:10080".
|
61
|
-
|
62
|
-
|
63
|
-
=== How to send a header
|
64
|
-
|
65
|
-
<%
|
66
|
-
_hb.header("SomeHeader", "SomeValue")
|
67
|
-
%>
|
68
|
-
|
69
|
-
If you have trouble, because the server already began to send the content while the page was not fully generated, then you can increase the size for when it should begin sending content like this:
|
70
|
-
|
71
|
-
appsrv = Hayabusa.new(
|
72
|
-
...
|
73
|
-
:send_size => 4096
|
74
|
-
...
|
75
|
-
)
|
76
|
-
|
77
|
-
Or you can do it for just one page dynamically (this should be done VERY early - like before the first lines gets printed out):
|
78
|
-
|
79
|
-
<%
|
80
|
-
_hb.headers_send_size = 4096
|
81
|
-
%>
|
82
|
-
|
83
|
-
You can also test if the headers are sent for your HTTP-session or not like this:
|
84
|
-
|
85
|
-
<%
|
86
|
-
if _hb.headers_sent?
|
87
|
-
print "The headers are sent!"
|
88
|
-
else
|
89
|
-
print "The headers are not sent yet - we can still add headers!"
|
90
|
-
end
|
91
|
-
%>
|
92
|
-
|
93
|
-
=== How to send set a cookie
|
94
|
-
|
95
|
-
<%
|
96
|
-
_hb.cookie(
|
97
|
-
"name" => "MyCookie",
|
98
|
-
"value" => "SomeValue",
|
99
|
-
"expires" => Time.new + 3600,
|
100
|
-
"path" => "/"
|
101
|
-
)
|
102
|
-
%>
|
103
|
-
|
104
|
-
=== How to do threadded content
|
105
|
-
|
106
|
-
<%
|
107
|
-
_hb.threadded_content do
|
108
|
-
sleep 4
|
109
|
-
print "Test 1<br />"
|
110
|
-
end
|
111
|
-
|
112
|
-
_hb.threadded_content do
|
113
|
-
sleep 1
|
114
|
-
print "Test 2<br />"
|
115
|
-
end
|
116
|
-
|
117
|
-
_hb.threadded_content do
|
118
|
-
sleep 3
|
119
|
-
print "Test 3<br />"
|
120
|
-
end
|
121
|
-
%>
|
122
|
-
|
123
|
-
It should print in the right order, even though "Test 1" will finish as the last thread:
|
124
|
-
Test 1
|
125
|
-
Test 2
|
126
|
-
Test 3
|
127
|
-
|
128
|
-
|
129
|
-
=== How to access request data
|
130
|
-
<%
|
131
|
-
puts _get
|
132
|
-
puts _post
|
133
|
-
puts _meta
|
134
|
-
puts _cookie
|
135
|
-
puts _session
|
136
|
-
puts _session_hash
|
137
|
-
%>
|
138
|
-
|
139
|
-
|
140
|
-
=== How to set session variables:
|
141
|
-
_session[:logged_in] = true
|
142
|
-
|
143
|
-
|
144
|
-
=== How to set other objects that cant be marshalled on sessions (variables will die after restart):
|
145
|
-
_session_hash[:mythread] = Thread.new do
|
146
|
-
do_some_stuff
|
147
|
-
end
|
148
|
-
|
149
|
-
|
150
|
-
=== How to access the database
|
151
|
-
<%
|
152
|
-
_db.q("SELECT * FROM Session") do |data|
|
153
|
-
puts data
|
154
|
-
end
|
155
|
-
%>
|
156
|
-
|
157
|
-
|
158
|
-
=== How to create a thread with database access that runs in background via the threadpool
|
159
|
-
<%
|
160
|
-
_hb.thread do
|
161
|
-
sleep 2
|
162
|
-
print "Trala!\n" #will be outputted to the command line, since the thread is being executed in the background and the http-request wont depend on it!
|
163
|
-
end
|
164
|
-
%>
|
165
|
-
|
166
|
-
|
167
|
-
=== How to do execute something every 10 seconds.
|
168
|
-
<%
|
169
|
-
_hb.timeout(:time => 10) do
|
170
|
-
print "This will be printed to the command line every 10 secs.\n"
|
171
|
-
end
|
172
|
-
%>
|
173
|
-
|
174
|
-
|
175
|
-
=== How to send a mail
|
176
|
-
|
177
|
-
1. Be sure to start the appserver with SMTP arguments:
|
178
|
-
appsrv = Hayabusa.new(
|
179
|
-
...
|
180
|
-
:smtp_paras => {
|
181
|
-
"smtp_host" => "hostname",
|
182
|
-
"smtp_port" => 465,
|
183
|
-
"smtp_user" => "username,
|
184
|
-
"smtp_passwd" => "password",
|
185
|
-
"ssl" => true
|
186
|
-
}
|
187
|
-
...
|
188
|
-
)
|
189
|
-
|
190
|
-
2. Do something like this:
|
191
|
-
<%
|
192
|
-
_hb.mail(
|
193
|
-
:to => "friends@email.com",
|
194
|
-
:subject => "The subject",
|
195
|
-
:html => "The HTML content.",
|
196
|
-
:from => "your@email.com"
|
197
|
-
)
|
198
|
-
%>
|
199
|
-
|
200
|
-
You can also make the appserver send you an email every time an error occurrs:
|
201
|
-
<%
|
202
|
-
appsrv = Hayabusa.new(
|
203
|
-
...
|
204
|
-
:error_report_emails => ["your@email.com", "another@email.com"],
|
205
|
-
:error_report_from => "robot@domain.com"
|
206
|
-
...
|
207
|
-
)
|
208
|
-
%>
|
209
|
-
|
210
|
-
|
211
|
-
=== How to use Gettext / Locales
|
212
|
-
|
213
|
-
1. Make folders and po-files so you have something like: "locales/en_GB/LC_MESSAGES/default.po".
|
214
|
-
|
215
|
-
2. Start the appserver with the following arguments:
|
216
|
-
appsrv = Hayabusa.new(
|
217
|
-
...
|
218
|
-
:locales_root => "#{File.dirname(__FILE__)}/../locales",
|
219
|
-
:locales_gettext_funcs => true,
|
220
|
-
:locale_default => "da_DK",
|
221
|
-
...
|
222
|
-
)
|
223
|
-
|
224
|
-
3. Use gettext like your normally would:
|
225
|
-
<%
|
226
|
-
print _("Hello world.")
|
227
|
-
%>
|
228
|
-
|
229
|
-
4. Dont do "require 'gettext'" or anything like this - the appserver does it all for you!
|
230
|
-
|
231
|
-
|
232
|
-
=== How to use multithreadded MySQL without mutex'ing around it.
|
233
|
-
|
234
|
-
1. Install the 'mysql2' gem.
|
235
|
-
gem install mysql2
|
236
|
-
|
237
|
-
2. Start the appserver with the following arguments:
|
238
|
-
appsrv = Hayabusa.new(
|
239
|
-
...
|
240
|
-
:db => {
|
241
|
-
:type => "mysql",
|
242
|
-
:subtype => "mysql2",
|
243
|
-
:host => "localhost",
|
244
|
-
:user => "username",
|
245
|
-
:pass => "password",
|
246
|
-
:db => "database",
|
247
|
-
:return_keys => "symbols",
|
248
|
-
:threadsafe => true,
|
249
|
-
:encoding => "utf8",
|
250
|
-
:query_args => {:cast => false}
|
251
|
-
}
|
252
|
-
...
|
253
|
-
)
|
254
|
-
|
255
|
-
|
256
|
-
=== How to make a cron-script that checks if my app is running through the appserver.
|
257
|
-
|
258
|
-
1. Be sure to start the appserver with a title:
|
259
|
-
appsrv = Hayabusa.new(
|
260
|
-
...
|
261
|
-
:title => "MyApp"
|
262
|
-
...
|
263
|
-
)
|
264
|
-
|
265
|
-
2. Add this command to your cron-config:
|
266
|
-
/bin/bash -l -c "ruby ~/.rvm/gems/ruby-1.9.2-head/gems/hayabusa-*/bin/check_running.rb --title=MyApp --forking=1 --command=\"ruby /path/to/app/start_script.rb\""
|
267
|
-
|
268
|
-
|
269
|
-
=== How to restart the appserver from Ruby or restart it based on memory usage.
|
270
|
-
|
271
|
-
1. Be sure to start the appserver with a restart-command:
|
272
|
-
appsrv = Hayabusa.new(
|
273
|
-
...
|
274
|
-
:restart_cmd => "/usr/bin/ruby1.9.1 /path/to/app/start.rb"
|
275
|
-
...
|
276
|
-
)
|
277
|
-
|
278
|
-
2. You can also make it restart itself based on memory usage:
|
279
|
-
appsrv = Hayabusa.new(
|
280
|
-
...
|
281
|
-
:restart_when_used_memory => 384
|
282
|
-
...
|
283
|
-
)
|
284
|
-
|
285
|
-
3. You can restart it dynamically (or test that it is able to restart itself with your given arguments) by doing something like this:
|
286
|
-
<%
|
287
|
-
_hb.should_restart = true
|
288
|
-
%>
|
289
|
-
|
290
|
-
When it restarts it will wait for a window with no running HTTP requests before restarting.
|
291
|
-
|
292
|
-
|
293
|
-
=== How to use helper methods.
|
294
|
-
|
295
|
-
1. This will show a message by using javascript in execute history.back(-1) afterwards.
|
296
|
-
_hb.alert("You can only view this page if you are logged in.").back if !logged_in
|
297
|
-
|
298
|
-
2. This will show the error message and execute history.back(-1) afterwards.
|
299
|
-
_hb.on_error_go_back do
|
300
|
-
raise "test"
|
301
|
-
end
|
302
|
-
|
303
|
-
3. This will redirect the user and not execute anything after it:
|
304
|
-
_hb.redirect("?show=frontpage")
|
305
|
-
|
306
|
-
4. We also add the method "html" to the String-class so escaping it is painless:
|
307
|
-
print "<b>Will this be bold?</b>".html
|
308
|
-
|
309
|
-
5. This is how you can escape SQL-stuff:
|
310
|
-
data = _db.query("SELECT * FROM Session WHERE id ='#{_db.esc(some_var)}'").fetch
|
311
|
-
|
312
|
-
6. Print strings using short-tag:
|
313
|
-
<div>
|
314
|
-
My name is <%=name_var%>.
|
315
|
-
</div>
|