hayabusa 0.0.24 → 0.0.29

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +363 -0
  3. data/Rakefile +0 -14
  4. data/bin/hayabusa_fcgi.fcgi +1 -0
  5. data/bin/hayabusa_fcgi_server.rb +0 -1
  6. data/lib/hayabusa.rb +124 -118
  7. data/lib/hayabusa_cgi_tools.rb +4 -2
  8. data/lib/hayabusa_client_session.rb +3 -1
  9. data/lib/hayabusa_database.rb +84 -84
  10. data/lib/hayabusa_datarow.rb +873 -0
  11. data/lib/hayabusa_ext/mailing.rb +8 -7
  12. data/lib/hayabusa_ext/web.rb +5 -0
  13. data/lib/hayabusa_fcgi.rb +13 -4
  14. data/lib/hayabusa_http_session.rb +2 -0
  15. data/lib/hayabusa_http_session_contentgroup.rb +7 -1
  16. data/lib/hayabusa_http_session_request.rb +7 -1
  17. data/lib/hayabusa_http_session_response.rb +30 -29
  18. data/lib/hayabusa_objects.rb +1455 -0
  19. data/lib/hayabusa_revision.rb +347 -0
  20. data/lib/kernel_ext/magic_methods.rb +4 -0
  21. data/lib/models/log.rb +27 -27
  22. data/lib/models/log_access.rb +20 -20
  23. data/lib/models/log_data.rb +6 -6
  24. data/lib/models/log_data_link.rb +2 -2
  25. data/lib/models/log_data_value.rb +5 -5
  26. data/lib/models/log_link.rb +12 -12
  27. data/lib/models/session.rb +6 -6
  28. metadata +125 -126
  29. data/.document +0 -5
  30. data/.rspec +0 -1
  31. data/Gemfile +0 -24
  32. data/Gemfile.lock +0 -70
  33. data/README.rdoc +0 -315
  34. data/VERSION +0 -1
  35. data/bin/hayabusa_fcgi.fcgi +0 -42
  36. data/conf/apache2_cgi_rhtml_conf.conf +0 -10
  37. data/conf/apache2_fcgi_rhtml_conf.conf +0 -22
  38. data/conf/apache2_hayabusa_conf.conf +0 -15
  39. data/hayabusa.gemspec +0 -167
  40. data/pages/benchmark.rhtml +0 -0
  41. data/pages/benchmark_print.rhtml +0 -14
  42. data/pages/benchmark_simple.rhtml +0 -3
  43. data/pages/benchmark_threadded_content.rhtml +0 -21
  44. data/pages/config_cgi.rb +0 -22
  45. data/pages/config_fcgi.rb +0 -22
  46. data/pages/debug_database_connections.rhtml +0 -46
  47. data/pages/debug_http_sessions.rhtml +0 -40
  48. data/pages/debug_memory_usage.rhtml +0 -39
  49. data/pages/error_notfound.rhtml +0 -12
  50. data/pages/image.png +0 -0
  51. data/pages/logs_latest.rhtml +0 -57
  52. data/pages/logs_show.rhtml +0 -32
  53. data/pages/spec.rhtml +0 -41
  54. data/pages/spec_exit.rhtml +0 -5
  55. data/pages/spec_multiple_threads.rhtml +0 -18
  56. data/pages/spec_sleeper.rhtml +0 -4
  57. data/pages/spec_test_multiple_clients.rhtml +0 -3
  58. data/pages/spec_thread_joins.rhtml +0 -29
  59. data/pages/spec_threadded_content.rhtml +0 -40
  60. data/pages/spec_vars_get.rhtml +0 -4
  61. data/pages/spec_vars_header.rhtml +0 -3
  62. data/pages/spec_vars_post.rhtml +0 -4
  63. data/pages/spec_vars_post_fileupload.rhtml +0 -19
  64. data/pages/testpic.jpeg +0 -0
  65. data/pages/tests.rhtml +0 -14
  66. data/pages/threadded_content_test.rhtml +0 -23
  67. data/spec/fcgi_multiple_processes_spec.rb +0 -104
  68. data/spec/hayabusa_spec.rb +0 -423
  69. data/spec/spec_helper.rb +0 -12
  70. data/spec/test_upload.xlsx +0 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 60e88035481dc2afdc4ee23c24f2c44a1b504890c62b1e228b2e813f9d3b15a7
4
+ data.tar.gz: ff6b3e9c203f94ce49c7e1cc431b3c89a09410ee8a0f2c45a7eb2ac41964fe4c
5
+ SHA512:
6
+ metadata.gz: e5205de4cf85d3a269e393d972a18e430afeb6c201e441ccd4e95589d5eeb2eac12e8b1cdeeed5f298657eb9aaf9314e13d0244a3aca5de0e8ac941e771513aa
7
+ data.tar.gz: 83addfb1405a664473579b8f9abbea6b7e4e3d4bc101bda50acc35a193298be340cd8a324964f8f2d4a59dff1a39148f1a81f9fb74b7c22e11fb837a06c39a73
data/README.md ADDED
@@ -0,0 +1,363 @@
1
+ # Hayabusa Webserver
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
+ ```ruby
25
+ gem install hayabusa
26
+ ```
27
+
28
+ ## Usage
29
+
30
+ ### Basic example
31
+
32
+ Create a file called "start.rb":
33
+ ```ruby
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: Baza::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
+
54
+ Place a file called "index.rhtml" with the start-script and write something like:
55
+ ```erb
56
+ <%
57
+ print "Hello world."
58
+ %>
59
+ ```
60
+
61
+ Then go to your browser and type "localhost:10080".
62
+
63
+
64
+ ### How to send a header
65
+ ```erb
66
+ <%
67
+ _hb.header("SomeHeader", "SomeValue")
68
+ %>
69
+ ```
70
+
71
+ 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:
72
+ ```ruby
73
+ appsrv = Hayabusa.new(
74
+ ...
75
+ send_size: 4096
76
+ ...
77
+ )
78
+ ```
79
+
80
+ Or you can do it for just one page dynamically (this should be done VERY early - like before the first lines gets printed out):
81
+ ```erb
82
+ <%
83
+ _hb.headers_send_size = 4096
84
+ %>
85
+ ```
86
+
87
+ You can also test if the headers are sent for your HTTP-session or not like this:
88
+ ```erb
89
+ <%
90
+ if _hb.headers_sent?
91
+ print "The headers are sent!"
92
+ else
93
+ print "The headers are not sent yet - we can still add headers!"
94
+ end
95
+ %>
96
+ ```
97
+
98
+ ### How to send set a cookie
99
+ ```erb
100
+ <%
101
+ _hb.cookie(
102
+ "name" => "MyCookie",
103
+ "value" => "SomeValue",
104
+ "expires" => Time.new + 3600,
105
+ "path" => "/"
106
+ )
107
+ %>
108
+ ```
109
+
110
+ ### How to do threadded content
111
+ ```erb
112
+ <%
113
+ _hb.threadded_content do
114
+ sleep 4
115
+ print "Test 1<br />"
116
+ end
117
+
118
+ _hb.threadded_content do
119
+ sleep 1
120
+ print "Test 2<br />"
121
+ end
122
+
123
+ _hb.threadded_content do
124
+ sleep 3
125
+ print "Test 3<br />"
126
+ end
127
+ %>
128
+ ```
129
+
130
+ It should print in the right order, even though "Test 1" will finish as the last thread:
131
+ ```
132
+ Test 1
133
+ Test 2
134
+ Test 3
135
+ ```
136
+
137
+ ### How to access request data
138
+ ```erb
139
+ <%
140
+ puts _get
141
+ puts _post
142
+ puts _meta
143
+ puts _cookie
144
+ puts _session
145
+ puts _session_hash
146
+ %>
147
+ ```
148
+
149
+ ### How to set session variables:
150
+ ```ruby
151
+ _session[:logged_in] = true
152
+ ```
153
+
154
+ ### How to set other objects that cant be marshalled on sessions (variables will die after restart):
155
+ ```ruby
156
+ _session_hash[:mythread] = Thread.new do
157
+ do_some_stuff
158
+ end
159
+ ```
160
+
161
+
162
+ ### How to access the database
163
+ ```erb
164
+ <%
165
+ _db.q("SELECT * FROM Session") do |data|
166
+ puts data
167
+ end
168
+ %>
169
+ ```
170
+
171
+ ### How to create a thread with database access that runs in background via the threadpool
172
+ ```erb
173
+ <%
174
+ _hb.thread do
175
+ sleep 2
176
+ 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!
177
+ end
178
+ %>
179
+ ```
180
+
181
+ ### How to do execute something every 10 seconds.
182
+ ```erb
183
+ <%
184
+ _hb.timeout(:time => 10) do
185
+ print "This will be printed to the command line every 10 secs.\n"
186
+ end
187
+ %>
188
+ ```
189
+
190
+ ### How to send a mail
191
+
192
+ 1. Be sure to start the appserver with SMTP arguments:
193
+ ```ruby
194
+ appsrv = Hayabusa.new(
195
+ ...
196
+ smtp_paras: {
197
+ "smtp_host" => "hostname",
198
+ "smtp_port" => 465,
199
+ "smtp_user" => "username,
200
+ "smtp_passwd" => "password",
201
+ "ssl" => true
202
+ }
203
+ ...
204
+ )
205
+ ```
206
+
207
+ 2. Do something like this:
208
+ ```erb
209
+ <%
210
+ _hb.mail(
211
+ :to => "friends@email.com",
212
+ :subject => "The subject",
213
+ :html => "The HTML content.",
214
+ :from => "your@email.com"
215
+ )
216
+ %>
217
+ ```
218
+
219
+ You can also make the appserver send you an email every time an error occurrs:
220
+ ```erb
221
+ <%
222
+ appsrv = Hayabusa.new(
223
+ ...
224
+ :error_report_emails => ["your@email.com", "another@email.com"],
225
+ :error_report_from => "robot@domain.com"
226
+ ...
227
+ )
228
+ %>
229
+ ```
230
+
231
+ ### How to use Gettext / Locales
232
+
233
+ 1. Make folders and po-files so you have something like: "locales/en_GB/LC_MESSAGES/default.po".
234
+
235
+ 2. Start the appserver with the following arguments:
236
+ ```ruby
237
+ appsrv = Hayabusa.new(
238
+ ...
239
+ locales_root: "#{File.dirname(__FILE__)}/../locales",
240
+ locales_gettext_funcs: true,
241
+ locale_default: "da_DK",
242
+ ...
243
+ )
244
+ ```
245
+
246
+ 3. Use gettext like your normally would:
247
+ ```erb
248
+ <%
249
+ print _("Hello world.")
250
+ %>
251
+ ```
252
+
253
+ 4. Dont do "require 'gettext'" or anything like this - the appserver does it all for you!
254
+
255
+
256
+ === How to use multithreadded MySQL without mutex'ing around it.
257
+
258
+ 1. Install the 'mysql2' gem.
259
+ ```ruby
260
+ gem install mysql2
261
+ ```
262
+
263
+ 2. Start the appserver with the following arguments:
264
+ ```ruby
265
+ appsrv = Hayabusa.new(
266
+ ...
267
+ db: {
268
+ type: "mysql",
269
+ subtype: "mysql2",
270
+ host: "localhost",
271
+ user: "username",
272
+ pass: "password",
273
+ db: "database",
274
+ return_keys: "symbols",
275
+ threadsafe: true,
276
+ encoding: "utf8",
277
+ query_args: {cast: false}
278
+ }
279
+ ...
280
+ )
281
+
282
+
283
+ ### How to make a cron-script that checks if my app is running through the appserver.
284
+
285
+ 1. Be sure to start the appserver with a title:
286
+ ```ruby
287
+ appsrv = Hayabusa.new(
288
+ ...
289
+ title: "MyApp"
290
+ ...
291
+ )
292
+ ```
293
+
294
+ 2. Add this command to your cron-config:
295
+ ```shell
296
+ /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\""
297
+ ```
298
+
299
+ ### How to restart the appserver from Ruby or restart it based on memory usage.
300
+
301
+ 1. Be sure to start the appserver with a restart-command:
302
+ ```ruby
303
+ appsrv = Hayabusa.new(
304
+ ...
305
+ restart_cmd: "/usr/bin/ruby1.9.1 /path/to/app/start.rb"
306
+ ...
307
+ )
308
+ ```
309
+
310
+ 2. You can also make it restart itself based on memory usage:
311
+ ```ruby
312
+ appsrv = Hayabusa.new(
313
+ ...
314
+ restart_when_used_memory: 384
315
+ ...
316
+ )
317
+ ```
318
+
319
+ 3. You can restart it dynamically (or test that it is able to restart itself with your given arguments) by doing something like this:
320
+ ```erb
321
+ <%
322
+ _hb.should_restart = true
323
+ %>
324
+ ```
325
+
326
+ When it restarts it will wait for a window with no running HTTP requests before restarting.
327
+
328
+
329
+ ### How to use helper methods.
330
+
331
+ 1. This will show a message by using javascript in execute history.back(-1) afterwards.
332
+ ```ruby
333
+ _hb.alert("You can only view this page if you are logged in.").back if !logged_in
334
+ ```
335
+
336
+ 2. This will show the error message and execute history.back(-1) afterwards.
337
+ ```ruby
338
+ _hb.on_error_go_back do
339
+ raise "test"
340
+ end
341
+ ```
342
+
343
+ 3. This will redirect the user and not execute anything after it:
344
+ ```ruby
345
+ _hb.redirect("?show=frontpage")
346
+ ```
347
+
348
+ 4. We also add the method "html" to the String-class so escaping it is painless:
349
+ ```ruby
350
+ print "<b>Will this be bold?</b>".html
351
+ ```
352
+
353
+ 5. This is how you can escape SQL-stuff:
354
+ ```ruby
355
+ data = _db.query("SELECT * FROM Session WHERE id ='#{_db.esc(some_var)}'").fetch
356
+ ```
357
+
358
+ 6. Print strings using short-tag:
359
+ ```erb
360
+ <div>
361
+ My name is <%=name_var%>.
362
+ </div>
363
+ ```
data/Rakefile CHANGED
@@ -11,20 +11,6 @@ rescue Bundler::BundlerError => e
11
11
  end
12
12
  require 'rake'
13
13
 
14
- require 'jeweler'
15
- Jeweler::Tasks.new do |gem|
16
- # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
- gem.name = "hayabusa"
18
- gem.homepage = "http://github.com/kaspernj/hayabusa"
19
- gem.license = "MIT"
20
- gem.summary = %Q{A threadded web/app-server that supports stand-alone, CGI and FCGI-modes.}
21
- gem.description = %Q{A threadded web/app-server that focuses on threadding, shared ressources, speed and more.}
22
- gem.email = "k@spernj.org"
23
- gem.authors = ["Kasper Johansen"]
24
- # dependencies defined in Gemfile
25
- end
26
- Jeweler::RubygemsDotOrgTasks.new
27
-
28
14
  require 'rspec/core'
29
15
  require 'rspec/core/rake_task'
30
16
  RSpec::Core::RakeTask.new(:spec) do |spec|
@@ -0,0 +1 @@
1
+ hayabusa_fcgi.rb
@@ -37,7 +37,6 @@ require opts[:conf_path]
37
37
  #Gemerate Hayabusa-config-hash.
38
38
  hayabusa_conf = Hayabusa::FCGI_CONF[:hayabusa]
39
39
  hayabusa_conf.merge!(
40
- :debug => false,
41
40
  :debug_log => true,
42
41
  :debug_print => false,
43
42
  :debug_print_err => false,