hayabusa 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. data/.document +5 -0
  2. data/.rspec +1 -0
  3. data/Gemfile +20 -0
  4. data/Gemfile.lock +59 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.rdoc +19 -0
  7. data/Rakefile +49 -0
  8. data/VERSION +1 -0
  9. data/bin/check_running.rb +69 -0
  10. data/bin/hayabusa_benchmark.rb +82 -0
  11. data/bin/hayabusa_cgi.rb +84 -0
  12. data/bin/hayabusa_fcgi.fcgi +159 -0
  13. data/bin/hayabusa_fcgi.rb +159 -0
  14. data/bin/knjappserver_start.rb +42 -0
  15. data/conf/apache2_cgi_rhtml_conf.conf +10 -0
  16. data/conf/apache2_fcgi_rhtml_conf.conf +22 -0
  17. data/hayabusa.gemspec +151 -0
  18. data/lib/hayabusa.rb +518 -0
  19. data/lib/hayabusa_cgi_session.rb +128 -0
  20. data/lib/hayabusa_cgi_tools.rb +102 -0
  21. data/lib/hayabusa_custom_io.rb +22 -0
  22. data/lib/hayabusa_database.rb +125 -0
  23. data/lib/hayabusa_erb_handler.rb +27 -0
  24. data/lib/hayabusa_ext/cleaner.rb +140 -0
  25. data/lib/hayabusa_ext/cmdline.rb +52 -0
  26. data/lib/hayabusa_ext/errors.rb +135 -0
  27. data/lib/hayabusa_ext/logging.rb +404 -0
  28. data/lib/hayabusa_ext/mailing.rb +158 -0
  29. data/lib/hayabusa_ext/sessions.rb +71 -0
  30. data/lib/hayabusa_ext/threadding.rb +96 -0
  31. data/lib/hayabusa_ext/threadding_timeout.rb +101 -0
  32. data/lib/hayabusa_ext/translations.rb +43 -0
  33. data/lib/hayabusa_ext/web.rb +190 -0
  34. data/lib/hayabusa_http_server.rb +102 -0
  35. data/lib/hayabusa_http_session.rb +361 -0
  36. data/lib/hayabusa_http_session_contentgroup.rb +176 -0
  37. data/lib/hayabusa_http_session_page_environment.rb +66 -0
  38. data/lib/hayabusa_http_session_post_multipart.rb +135 -0
  39. data/lib/hayabusa_http_session_request.rb +219 -0
  40. data/lib/hayabusa_http_session_response.rb +144 -0
  41. data/lib/hayabusa_models.rb +8 -0
  42. data/lib/kernel_ext/gettext_methods.rb +22 -0
  43. data/lib/kernel_ext/magic_methods.rb +61 -0
  44. data/lib/models/log.rb +130 -0
  45. data/lib/models/log_access.rb +88 -0
  46. data/lib/models/log_data.rb +27 -0
  47. data/lib/models/log_data_link.rb +3 -0
  48. data/lib/models/log_data_value.rb +21 -0
  49. data/lib/models/log_link.rb +65 -0
  50. data/lib/models/session.rb +35 -0
  51. data/pages/benchmark.rhtml +0 -0
  52. data/pages/benchmark_print.rhtml +14 -0
  53. data/pages/benchmark_simple.rhtml +3 -0
  54. data/pages/benchmark_threadded_content.rhtml +21 -0
  55. data/pages/debug_database_connections.rhtml +46 -0
  56. data/pages/debug_http_sessions.rhtml +40 -0
  57. data/pages/debug_memory_usage.rhtml +16 -0
  58. data/pages/error_notfound.rhtml +12 -0
  59. data/pages/logs_latest.rhtml +57 -0
  60. data/pages/logs_show.rhtml +32 -0
  61. data/pages/spec.rhtml +41 -0
  62. data/pages/spec_post.rhtml +3 -0
  63. data/pages/spec_test_multiple_clients.rhtml +3 -0
  64. data/pages/spec_thread_joins.rhtml +21 -0
  65. data/pages/spec_threadded_content.rhtml +40 -0
  66. data/pages/tests.rhtml +14 -0
  67. data/spec/cgi_spec.rb +47 -0
  68. data/spec/custom_urls_spec.rb +35 -0
  69. data/spec/fcgi_multiple_processes_spec.rb +32 -0
  70. data/spec/fcgi_spec.rb +69 -0
  71. data/spec/hayabusa_spec.rb +194 -0
  72. data/spec/spec_helper.rb +12 -0
  73. data/tests/cgi_test/config_cgi.rb +6 -0
  74. data/tests/cgi_test/threadded_content_test.rhtml +23 -0
  75. data/tests/cgi_test/vars_get_test.rhtml +4 -0
  76. data/tests/cgi_test/vars_header_test.rhtml +3 -0
  77. data/tests/cgi_test/vars_post_test.rhtml +4 -0
  78. data/tests/fcgi_test/config_fcgi.rb +6 -0
  79. data/tests/fcgi_test/index.rhtml +3 -0
  80. data/tests/fcgi_test/sleeper.rhtml +4 -0
  81. data/tests/fcgi_test/threadded_content_test.rhtml +23 -0
  82. data/tests/fcgi_test/vars_get_test.rhtml +4 -0
  83. data/tests/fcgi_test/vars_header_test.rhtml +3 -0
  84. data/tests/fcgi_test/vars_post_test.rhtml +4 -0
  85. metadata +257 -0
@@ -0,0 +1,3 @@
1
+ <%
2
+ print _post["test"]
3
+ %>
@@ -0,0 +1,21 @@
1
+ <%
2
+ print "1"
3
+
4
+ cont = "2"
5
+ t1 = _hb.thread do
6
+ sleep 0.5
7
+ cont << "4"
8
+ end
9
+
10
+ t2 = _hb.thread do
11
+ sleep 0.1
12
+ cont << "3"
13
+ end
14
+
15
+ t1.join
16
+ t2.join_error
17
+
18
+ cont << "5"
19
+
20
+ print cont
21
+ %>
@@ -0,0 +1,40 @@
1
+ <%
2
+ _hb.threadded_content do
3
+ sleep 0.2
4
+ print "1"
5
+ end
6
+
7
+ print "2"
8
+
9
+ _hb.threadded_content do
10
+ sleep 0.1
11
+
12
+ _hb.threadded_content do
13
+ sleep 0.1
14
+ print "3"
15
+
16
+ sleep 0.1
17
+
18
+ _hb.threadded_content do
19
+ print "4"
20
+ sleep 0.1
21
+ print "5"
22
+ end
23
+
24
+ _hb.threadded_content do
25
+ print "6"
26
+ print "7"
27
+ end
28
+ end
29
+
30
+ print "8"
31
+ end
32
+
33
+ #This will first finish after the printing has starter - it should still be printed correct.
34
+ _hb.threadded_content do
35
+ sleep 1
36
+ print "9"
37
+ end
38
+
39
+ print "10"
40
+ %>
@@ -0,0 +1,14 @@
1
+ <%
2
+ print "Test 1: #{_testvar1}<br />\n"
3
+ print "Test 2: #{_testvar2}<br />\n"
4
+ %>
5
+
6
+ <table style="width: 1000px;">
7
+ <%
8
+ print Knj::Web.inputs([{
9
+ :title => "FCKEditor test",
10
+ :type => :fckeditor,
11
+ :name => :textest
12
+ }])
13
+ %>
14
+ </table>
@@ -0,0 +1,47 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Hayabusa" do
4
+ it "should be able to start a sample-server" do
5
+ require "rubygems"
6
+ require "http2"
7
+ require "json"
8
+
9
+ Http2.new(:host => "localhost") do |http|
10
+ res = http.post(:url => "hayabusa_cgi_test/vars_post_test.rhtml", :post => {
11
+ "var" => {
12
+ 0 => 1,
13
+ 1 => 2,
14
+ 3 => {
15
+ "kasper" => 5,
16
+ "arr" => ["a", "b", "c"]
17
+ }
18
+ }
19
+ })
20
+
21
+ begin
22
+ data = JSON.parse(res.body)
23
+ rescue JSON::GeneratorError
24
+ raise "Could not parse JSON from result: '#{res.body}'."
25
+ end
26
+
27
+ begin
28
+ raise "Expected hash to be a certain way: '#{data}'." if data["var"]["0"] != "1" or data["var"]["1"] != "2" or data["var"]["3"]["kasper"] != "5" or data["var"]["3"]["arr"]["0"] != "a" or data["var"]["3"]["arr"]["1"] != "b"
29
+ rescue => e
30
+ raise "Error when parsing result: '#{data}'."
31
+ end
32
+
33
+
34
+ res = http.get("hayabusa_cgi_test/threadded_content_test.rhtml")
35
+ raise "Expected body to be '123456' but it was: '#{res.body}'." if res.body != "123456"
36
+
37
+ res = http.get("hayabusa_cgi_test/vars_get_test.rhtml?var[]=1&var[]=2&var[]=3&var[3][kasper]=5")
38
+ data = JSON.parse(res.body)
39
+ raise "Expected hash to be a certain way: '#{data}'." if data["var"]["0"] != "1" or data["var"]["1"] != "2" or data["var"]["3"]["kasper"] != "5"
40
+
41
+
42
+
43
+ res = http.get("hayabusa_cgi_test/vars_header_test.rhtml")
44
+ raise "Expected header 'testheader' to be 'TestValue' but it wasnt: '#{res.header("testheader")}'." if res.header("testheader") != "TestValue"
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,35 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Hayabusa" do
4
+ it "should be able to start a sample-server" do
5
+ require "rubygems"
6
+ require "hayabusa"
7
+ require "knjrbfw"
8
+ require "sqlite3" if RUBY_ENGINE != "jruby"
9
+
10
+ db_path = "#{Knj::Os.tmpdir}/hayabusa_rspec.sqlite3"
11
+ File.unlink(db_path) if File.exists?(db_path)
12
+
13
+ db = Knj::Db.new(
14
+ :type => "sqlite3",
15
+ :path => db_path,
16
+ :return_keys => "symbols"
17
+ )
18
+
19
+ $appserver = Hayabusa.new(
20
+ :debug => false,
21
+ :title => "SpecTestCustomUrls",
22
+ :port => 1515,
23
+ :doc_root => "#{File.dirname(__FILE__)}/../lib/pages",
24
+ :locales_gettext_funcs => true,
25
+ :locale_default => "da_DK",
26
+ :db => db
27
+ )
28
+
29
+ $appserver.start
30
+ end
31
+
32
+ it "should be able to stop." do
33
+ $appserver.stop
34
+ end
35
+ end
@@ -0,0 +1,32 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Hayabusa" do
4
+ it "two simultanious request should be handeled by the same process - one should proxy the request" do
5
+ require "rubygems"
6
+ require "http2"
7
+ require "json"
8
+
9
+ Http2.new(:host => "localhost") do |http1|
10
+ Http2.new(:host => "localhost") do |http2|
11
+ res1 = nil
12
+ res2 = nil
13
+
14
+ t1 = Thread.new do
15
+ res1 = http1.get(:url => "hayabusa_fcgi_test/sleeper.rhtml")
16
+ end
17
+
18
+ t2 = Thread.new do
19
+ res2 = http2.get(:url => "hayabusa_fcgi_test/sleeper.rhtml")
20
+ end
21
+
22
+ t1.join
23
+ t2.join
24
+
25
+ pid1 = res1.body.to_i
26
+ pid2 = res2.body.to_i
27
+
28
+ raise "Expected PIDs to be the same: '#{res1.body}', '#{res2.body}'." if pid1 != pid2 or pid1 == 0 or pid2 == 0
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,69 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Hayabusa" do
4
+ it "should be able to start a sample-server" do
5
+ require "rubygems"
6
+ require "http2"
7
+ require "json"
8
+
9
+ ts = []
10
+ es = []
11
+
12
+ #Execute multiple threads to test FCGI-proxy and thread-safety.
13
+ 1.upto(5) do
14
+ ts << Thread.new do
15
+ begin
16
+ Http2.new(:host => "localhost") do |http|
17
+ res = http.post(:url => "hayabusa_fcgi_test/vars_post_test.rhtml", :post => {
18
+ "var" => {
19
+ 0 => 1,
20
+ 1 => 2,
21
+ 3 => {
22
+ "kasper" => 5,
23
+ "arr" => ["a", "b", "c"]
24
+ }
25
+ }
26
+ })
27
+
28
+ begin
29
+ data = JSON.parse(res.body)
30
+ rescue JSON::GeneratorError
31
+ raise "Could not parse JSON from result: '#{res.body}'."
32
+ end
33
+
34
+ begin
35
+ raise "Expected hash to be a certain way: '#{data}'." if data["var"]["0"] != "1" or data["var"]["1"] != "2" or data["var"]["3"]["kasper"] != "5" or data["var"]["3"]["arr"]["0"] != "a" or data["var"]["3"]["arr"]["1"] != "b"
36
+ rescue => e
37
+ raise "Error when parsing result: '#{data}'."
38
+ end
39
+
40
+
41
+ res = http.get("hayabusa_fcgi_test/threadded_content_test.rhtml")
42
+ raise "Expected body to be '123456' but it was: '#{res.body}'." if res.body != "123456"
43
+
44
+ res = http.get("hayabusa_fcgi_test/vars_get_test.rhtml?var[]=1&var[]=2&var[]=3&var[3][kasper]=5")
45
+ data = JSON.parse(res.body)
46
+ raise "Expected hash to be a certain way: '#{data}'." if data["var"]["0"] != "1" or data["var"]["1"] != "2" or data["var"]["3"]["kasper"] != "5"
47
+
48
+
49
+
50
+ res = http.get("hayabusa_fcgi_test/vars_header_test.rhtml")
51
+ raise "Expected header 'testheader' to be 'TestValue' but it wasnt: '#{res.header("testheader")}'." if res.header("testheader") != "TestValue"
52
+ end
53
+ rescue => e
54
+ es << e
55
+ puts e.inspect
56
+ puts e.backtrace
57
+ end
58
+ end
59
+ end
60
+
61
+ ts.each do |t|
62
+ t.join
63
+ end
64
+
65
+ es.each do |e|
66
+ raise e
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,194 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Hayabusa" do
4
+ it "should be able to start a sample-server" do
5
+ require "rubygems"
6
+ require "hayabusa"
7
+ require "knjrbfw"
8
+ require "sqlite3" if RUBY_ENGINE != "jruby"
9
+
10
+ db_path = "#{Knj::Os.tmpdir}/hayabusa_rspec.sqlite3"
11
+ File.unlink(db_path) if File.exists?(db_path)
12
+
13
+ db = Knj::Db.new(
14
+ :type => "sqlite3",
15
+ :path => db_path,
16
+ :return_keys => "symbols"
17
+ )
18
+
19
+ $appserver = Hayabusa.new(
20
+ :debug => false,
21
+ :title => "SpecTest",
22
+ :port => 1515,
23
+ :doc_root => "#{File.dirname(__FILE__)}/../pages",
24
+ :locales_gettext_funcs => true,
25
+ :locale_default => "da_DK",
26
+ :db => db
27
+ )
28
+
29
+ $appserver.vars[:test] = "kasper"
30
+ $appserver.define_magic_var(:_testvar1, "Kasper")
31
+ $appserver.define_magic_var(:_testvar2, "Johansen")
32
+ $appserver.start
33
+ end
34
+
35
+ it "should be able to handle a GET-request." do
36
+ #Check that we are able to perform a simple GET request and get the correct data back.
37
+ require "http2"
38
+ $http = Http2.new(:host => "localhost", :port => 1515)
39
+
40
+ res = $http.get("spec.rhtml")
41
+ raise "Unexpected HTML: '#{res.body}'." if res.body.to_s != "Test"
42
+
43
+ #Check that URL-decoding are being done.
44
+ res = $http.get("spec.rhtml?choice=check_get_parse&value=#{Knj::Web.urlenc("gfx/nopic.png")}")
45
+ raise "Unexpected HTML: '#{res.body}'." if res.body.to_s != "gfx/nopic.png"
46
+ end
47
+
48
+ it "should be able to handle a HEAD-request." do
49
+ #Http2 doesnt support head?
50
+ #res = $http.head("/spec.rhtml")
51
+ #raise "HEAD-request returned content - it shouldnt?" if res.body.to_s.length > 0
52
+ end
53
+
54
+ it "should be able to handle a POST-request." do
55
+ res = $http.post(:url => "spec.rhtml", :post => {
56
+ "postdata" => "Test post"
57
+ })
58
+ raise "POST-request did not return expected data: '#{res.body}'." if res.body.to_s.strip != "Test post"
59
+
60
+ res = $http.post(:url => "spec.rhtml?choice=dopostconvert", :post => {
61
+ "postdata" => "Test post",
62
+ "array" => ["a", "b", "d"]
63
+ })
64
+ data = JSON.parse(res.body)
65
+ raise "Expected posted data restored but it wasnt: '#{data}'." if data["array"]["0"] != "a" or data["array"]["1"] != "b" or data["array"]["2"] != "d"
66
+ end
67
+
68
+ it "should be able to join the server so other tests can be made manually." do
69
+ begin
70
+ Timeout.timeout(1) do
71
+ $appserver.join
72
+ raise "Appserver didnt join."
73
+ end
74
+ rescue Timeout::Error
75
+ #ignore.
76
+ end
77
+ end
78
+
79
+ it "should be able to use the header-methods." do
80
+ res = $http.get("spec.rhtml")
81
+ raise "Normal header data could not be detected." if res.header("testheader") != "NormalHeader"
82
+ raise "Raw header data could not be detected." if res.header("testraw") != "RawHeader"
83
+ end
84
+
85
+ it "should be able to set and get multiple cookies at the same time." do
86
+ require "json"
87
+
88
+ res = $http.get("spec.rhtml?choice=test_cookie")
89
+ raise res.body if res.body.to_s.length > 0
90
+
91
+ res = $http.get("spec.rhtml?choice=get_cookies")
92
+ parsed = JSON.parse(res.body)
93
+
94
+ raise "Unexpected value for 'TestCookie': '#{parsed["TestCookie"]}'." if parsed["TestCookie"] != "TestValue"
95
+ raise "Unexpected value for 'TestCookie2': '#{parsed["TestCookie2"]}'." if parsed["TestCookie2"] != "TestValue2"
96
+ raise "Unexpected value for 'TestCookie3': '#{parsed["TestCookie3"]}'." if parsed["TestCookie3"] != "TestValue 3 "
97
+ end
98
+
99
+ it "should be able to run the rspec_threadded_content test correctly." do
100
+ res = $http.get("spec_threadded_content.rhtml")
101
+
102
+ if res.body != "12345678910"
103
+ raise res.body.to_s
104
+ end
105
+ end
106
+
107
+ it "should be able to add a timeout." do
108
+ $break_timeout = false
109
+ timeout = $appserver.timeout(:time => 1) do
110
+ $break_timeout = true
111
+ end
112
+
113
+ Timeout.timeout(2) do
114
+ loop do
115
+ break if $break_timeout
116
+ sleep 0.1
117
+ end
118
+ end
119
+ end
120
+
121
+ it "should be able to stop a timeout." do
122
+ $timeout_runned = false
123
+ timeout = $appserver.timeout(:time => 1) do
124
+ $timeout_runned = true
125
+ end
126
+
127
+ sleep 0.5
128
+ timeout.stop
129
+
130
+ begin
131
+ Timeout.timeout(1.5) do
132
+ loop do
133
+ raise "The timeout ran even though stop was called?" if $timeout_runned
134
+ sleep 0.1
135
+ end
136
+ end
137
+ rescue Timeout::Error
138
+ #the timeout didnt run - and it shouldnt so dont do anything.
139
+ end
140
+ end
141
+
142
+ it "should be able to join threads tarted from _hb.thread." do
143
+ res = $http.get("spec_thread_joins.rhtml")
144
+ raise res.body if res.body.to_s != "12345"
145
+ end
146
+
147
+ it "should be able to properly parse special characters in post-requests." do
148
+ res = $http.post(:url => "spec_post.rhtml", :post => {
149
+ "test" => "123+456%789%20"
150
+ })
151
+ raise res.body if res.body != "123+456%789%20"
152
+ end
153
+
154
+ it "should be able to do logging" do
155
+ class ::TestModels
156
+ class Person < Knj::Datarow
157
+
158
+ end
159
+ end
160
+
161
+ Knj::Db::Revision.new.init_db("db" => $appserver.db, "schema" => {
162
+ "tables" => {
163
+ "Person" => {
164
+ "columns" => [
165
+ {"name" => "id", "type" => "int", "autoincr" => true, "primarykey" => true},
166
+ {"name" => "name", "type" => "varchar"}
167
+ ]
168
+ }
169
+ }
170
+ })
171
+
172
+ ob = Knj::Objects.new(
173
+ :db => $appserver.db,
174
+ :datarow => true,
175
+ :require => false,
176
+ :module => ::TestModels
177
+ )
178
+
179
+ person = ob.add(:Person, :name => "Kasper")
180
+
181
+ $appserver.log("This is a test", person)
182
+ logs = $appserver.ob.list(:Log, "object_lookup" => person).to_a
183
+ raise "Expected count to be 1 but got: #{logs.length}" if logs.length != 1
184
+
185
+ $appserver.logs_delete(person)
186
+
187
+ logs = $appserver.ob.list(:Log, "object_lookup" => person).to_a
188
+ raise "Expected count to be 0 but got: #{logs.length}" if logs.length != 0
189
+ end
190
+
191
+ it "should be able to stop." do
192
+ $appserver.stop
193
+ end
194
+ end