hayabusa 0.0.18 → 0.0.19

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,19 +1,315 @@
1
1
  = hayabusa
2
2
 
3
- Description goes here.
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
+
4
7
 
5
8
  == Contributing to hayabusa
6
9
 
7
- * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
- * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
- * Fork the project.
10
- * Start a feature/bugfix branch.
11
- * Commit and push until you are happy with your contribution.
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
12
15
  * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
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.
14
17
 
15
18
  == Copyright
16
19
 
17
- Copyright (c) 2012 Kasper Johansen. See LICENSE.txt for
20
+ Copyright (c) 2011 Kasper Johansen. See LICENSE.txt for
18
21
  further details.
19
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>
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.18
1
+ 0.0.19
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{hayabusa}
8
- s.version = "0.0.18"
8
+ s.version = "0.0.19"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kasper Johansen"]
12
- s.date = %q{2012-10-10}
12
+ s.date = %q{2012-10-12}
13
13
  s.description = %q{A threadded web/app-server that focuses on threadding, shared ressources, speed and more.}
14
14
  s.email = %q{k@spernj.org}
15
15
  s.executables = ["check_running.rb", "hayabusa_benchmark.rb", "hayabusa_cgi.rb", "hayabusa_fcgi.fcgi", "hayabusa_fcgi.rb", "hayabusa_fcgi_server.rb", "hayabusa_spec_restart.rb", "knjappserver_start.rb"]
@@ -77,10 +77,10 @@ class Hayabusa::Http_session::Post_multipart
77
77
  end
78
78
  elsif @mode == "body"
79
79
  if line[-crlf_len, crlf_len] == crlf
80
- str = line[0, line.length - crlf_len]
80
+ str = "#{str_crlf}#{line[0, line.length - crlf_len]}"
81
81
  str_crlf = crlf
82
82
  else
83
- str = line
83
+ str = "#{str_crlf}#{line}"
84
84
  str_crlf = nil
85
85
  end
86
86
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hayabusa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.18
4
+ version: 0.0.19
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-10 00:00:00.000000000 +02:00
12
+ date: 2012-10-12 00:00:00.000000000 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: knjrbfw
17
- requirement: &11988240 !ruby/object:Gem::Requirement
17
+ requirement: &20970700 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *11988240
25
+ version_requirements: *20970700
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: erubis
28
- requirement: &11987480 !ruby/object:Gem::Requirement
28
+ requirement: &20970060 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *11987480
36
+ version_requirements: *20970060
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: mail
39
- requirement: &11986740 !ruby/object:Gem::Requirement
39
+ requirement: &20969420 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '0'
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *11986740
47
+ version_requirements: *20969420
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: datet
50
- requirement: &11985940 !ruby/object:Gem::Requirement
50
+ requirement: &20968760 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '0'
56
56
  type: :runtime
57
57
  prerelease: false
58
- version_requirements: *11985940
58
+ version_requirements: *20968760
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: http2
61
- requirement: &11985200 !ruby/object:Gem::Requirement
61
+ requirement: &20968100 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: '0'
67
67
  type: :runtime
68
68
  prerelease: false
69
- version_requirements: *11985200
69
+ version_requirements: *20968100
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: tpool
72
- requirement: &11984320 !ruby/object:Gem::Requirement
72
+ requirement: &20967400 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ! '>='
@@ -77,10 +77,10 @@ dependencies:
77
77
  version: '0'
78
78
  type: :runtime
79
79
  prerelease: false
80
- version_requirements: *11984320
80
+ version_requirements: *20967400
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: fcgi
83
- requirement: &11983260 !ruby/object:Gem::Requirement
83
+ requirement: &20964280 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ! '>='
@@ -88,10 +88,10 @@ dependencies:
88
88
  version: '0'
89
89
  type: :runtime
90
90
  prerelease: false
91
- version_requirements: *11983260
91
+ version_requirements: *20964280
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: json
94
- requirement: &11981880 !ruby/object:Gem::Requirement
94
+ requirement: &20963400 !ruby/object:Gem::Requirement
95
95
  none: false
96
96
  requirements:
97
97
  - - ! '>='
@@ -99,10 +99,10 @@ dependencies:
99
99
  version: '0'
100
100
  type: :development
101
101
  prerelease: false
102
- version_requirements: *11981880
102
+ version_requirements: *20963400
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: rspec
105
- requirement: &11980560 !ruby/object:Gem::Requirement
105
+ requirement: &20962360 !ruby/object:Gem::Requirement
106
106
  none: false
107
107
  requirements:
108
108
  - - ! '>='
@@ -110,10 +110,10 @@ dependencies:
110
110
  version: 2.3.0
111
111
  type: :development
112
112
  prerelease: false
113
- version_requirements: *11980560
113
+ version_requirements: *20962360
114
114
  - !ruby/object:Gem::Dependency
115
115
  name: bundler
116
- requirement: &11978460 !ruby/object:Gem::Requirement
116
+ requirement: &20961520 !ruby/object:Gem::Requirement
117
117
  none: false
118
118
  requirements:
119
119
  - - ! '>='
@@ -121,10 +121,10 @@ dependencies:
121
121
  version: 1.0.0
122
122
  type: :development
123
123
  prerelease: false
124
- version_requirements: *11978460
124
+ version_requirements: *20961520
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: jeweler
127
- requirement: &11977700 !ruby/object:Gem::Requirement
127
+ requirement: &20960720 !ruby/object:Gem::Requirement
128
128
  none: false
129
129
  requirements:
130
130
  - - ~>
@@ -132,10 +132,10 @@ dependencies:
132
132
  version: 1.6.3
133
133
  type: :development
134
134
  prerelease: false
135
- version_requirements: *11977700
135
+ version_requirements: *20960720
136
136
  - !ruby/object:Gem::Dependency
137
137
  name: sqlite3
138
- requirement: &11977060 !ruby/object:Gem::Requirement
138
+ requirement: &20960060 !ruby/object:Gem::Requirement
139
139
  none: false
140
140
  requirements:
141
141
  - - ! '>='
@@ -143,7 +143,7 @@ dependencies:
143
143
  version: '0'
144
144
  type: :development
145
145
  prerelease: false
146
- version_requirements: *11977060
146
+ version_requirements: *20960060
147
147
  description: A threadded web/app-server that focuses on threadding, shared ressources,
148
148
  speed and more.
149
149
  email: k@spernj.org
@@ -261,7 +261,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
261
261
  version: '0'
262
262
  segments:
263
263
  - 0
264
- hash: -1407369577175640998
264
+ hash: -2899056431482233064
265
265
  required_rubygems_version: !ruby/object:Gem::Requirement
266
266
  none: false
267
267
  requirements: