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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5ec32bf3a53fd6d789fa92f73e9aecd4604ab514
4
+ data.tar.gz: 7428cea3aca44c9d15a91957ad8368ed5ded606a
5
+ SHA512:
6
+ metadata.gz: 41a060c14eddd7e1b1b1ab721ae01bf178560b367a9920795128512e72f83cc535a3783adc33ff03281959f85b218be7325bdbec8503ead7d39c253fcb45bc0c
7
+ data.tar.gz: 0a45f0ffa81f9a4d5aeaf08db73677454716f4d428f2df6cc117d0d4fb044dcee43c37bcffc6da1251a857ea6e4d080ef06fb313913d93b07ae1dfe71c26a2af
data/Gemfile CHANGED
@@ -9,7 +9,6 @@ gem "mail"
9
9
  gem "datet"
10
10
  gem "http2"
11
11
  gem "tpool"
12
- gem "fcgi"
13
12
  gem "ruby_process"
14
13
 
15
14
  # Add dependencies to develop your gem here.
@@ -18,7 +17,8 @@ group :development do
18
17
  gem "json"
19
18
  gem "rspec", ">= 2.3.0"
20
19
  gem "bundler", ">= 1.0.0"
21
- gem "jeweler", "~> 1.6.3"
20
+ gem "jeweler", "~> 1.8.8"
22
21
  gem "rmagick"
23
22
  gem "sqlite3" if RUBY_ENGINE != "jruby"
23
+ gem "php4r"
24
24
  end
data/Gemfile.lock CHANGED
@@ -1,17 +1,35 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
+ addressable (2.3.6)
5
+ builder (3.2.2)
4
6
  datet (0.0.25)
5
7
  diff-lcs (1.2.4)
6
8
  erubis (2.7.0)
7
- fcgi (0.9.1)
8
- git (1.2.5)
9
+ faraday (0.8.9)
10
+ multipart-post (~> 1.2.0)
11
+ git (1.2.8)
12
+ github_api (0.10.1)
13
+ addressable
14
+ faraday (~> 0.8.1)
15
+ hashie (>= 1.2)
16
+ multi_json (~> 1.4)
17
+ nokogiri (~> 1.5.2)
18
+ oauth2
19
+ hashie (3.3.2)
20
+ highline (1.6.21)
9
21
  http2 (0.0.22)
10
- jeweler (1.6.4)
22
+ jeweler (1.8.8)
23
+ builder
11
24
  bundler (~> 1.0)
12
25
  git (>= 1.2.5)
26
+ github_api (= 0.10.1)
27
+ highline (>= 1.6.15)
28
+ nokogiri (= 1.5.10)
13
29
  rake
30
+ rdoc
14
31
  json (1.8.0)
32
+ jwt (1.2.0)
15
33
  knjrbfw (0.0.107)
16
34
  datet
17
35
  http2
@@ -23,12 +41,25 @@ GEM
23
41
  mime-types (~> 1.16)
24
42
  treetop (~> 1.4.8)
25
43
  mime-types (1.23)
44
+ multi_json (1.10.1)
45
+ multi_xml (0.5.5)
46
+ multipart-post (1.2.0)
47
+ nokogiri (1.5.10)
48
+ oauth2 (1.0.0)
49
+ faraday (>= 0.8, < 0.10)
50
+ jwt (~> 1.0)
51
+ multi_json (~> 1.3)
52
+ multi_xml (~> 0.5)
53
+ rack (~> 1.2)
26
54
  php4r (0.0.4)
27
55
  datet
28
56
  http2
29
57
  string-strtr
30
58
  polyglot (0.3.3)
31
- rake (10.1.0)
59
+ rack (1.5.2)
60
+ rake (10.4.2)
61
+ rdoc (4.1.2)
62
+ json (~> 1.4)
32
63
  rmagick (2.13.2)
33
64
  rspec (2.13.0)
34
65
  rspec-core (~> 2.13.0)
@@ -57,12 +88,12 @@ DEPENDENCIES
57
88
  bundler (>= 1.0.0)
58
89
  datet
59
90
  erubis
60
- fcgi
61
91
  http2
62
- jeweler (~> 1.6.3)
92
+ jeweler (~> 1.8.8)
63
93
  json
64
94
  knjrbfw
65
95
  mail
96
+ php4r
66
97
  rmagick
67
98
  rspec (>= 2.3.0)
68
99
  ruby_process
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: 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
+
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
+ ```