hayabusa 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.0.2
@@ -1,12 +1,11 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
- #This scripts start an appserver, executes a HTTP-request for every FCGI-request and terminates when FCGI terminates.
3
+ #This scripts start an appserver, executes a CGI-request for every FCGI-request and terminates when FCGI terminates.
4
4
  #Good for programming appserver-supported projects that doesnt need threadding without running an appserver all the time.
5
5
 
6
- #It doesnt support shared threadding or objects because multiple instances in form of processes will be executed.
7
-
8
- #Its a bit slower because it needs to flush writes to the database at end of every request and re-read them on spawn, because multiple instances might be present.
6
+ debug = false
9
7
 
8
+ $stderr.puts "[hayabusa] Starting up!" if debug
10
9
  error_log_file = "/tmp/hayabusa_fcgi.log"
11
10
 
12
11
  begin
@@ -16,6 +15,7 @@ rescue Errno::ENOENT
16
15
  end
17
16
 
18
17
  begin
18
+ $stderr.puts "[hayabusa] Loading libs." if debug
19
19
  require "rubygems"
20
20
  require "knjrbfw"
21
21
  require "fcgi"
@@ -27,24 +27,27 @@ begin
27
27
 
28
28
  #We cant define the Hayabusa-server untuil we receive the first headers, so wait for the first request.
29
29
  hayabusa = nil
30
+ hayabusa_fcgi_conf_path = nil
30
31
  fcgi_proxy = nil
31
32
 
33
+ $stderr.puts "[hayabusa] Starting FCGI." if debug
32
34
  FCGI.each_cgi do |cgi|
33
35
  begin
34
36
  #cgi.print "Content-Type: text/html\r\n"
35
37
  #cgi.print "\r\n"
36
38
 
39
+ #Set 'cgi'-variable for CGI-tools.
37
40
  cgi_tools.cgi = cgi
38
41
 
42
+ #Ensure the same FCGI-process isnt active for more than one website.
43
+ raise "Expected 'HTTP_HAYABUSA_FCGI_CONFIG' to be '#{hayabusa_fcgi_conf_path}' but it wasnt: '#{cgi.env_table["HTTP_HAYABUSA_FCGI_CONFIG"]}'." if hayabusa_fcgi_conf_path and hayabusa_fcgi_conf_path != cgi.env_table["HTTP_HAYABUSA_FCGI_CONFIG"]
44
+
39
45
  if !hayabusa
40
46
  raise "No HTTP_HAYABUSA_FCGI_CONFIG-header was given." if !cgi.env_table["HTTP_HAYABUSA_FCGI_CONFIG"]
41
- require cgi.env_table["HTTP_HAYABUSA_FCGI_CONFIG"]
42
-
43
- begin
44
- conf = Hayabusa::FCGI_CONF
45
- rescue NameError
46
- raise "No 'Hayabusa::FCGI_CONF'-constant was spawned by '#{cgi.env_table["HTTP_HAYABUSA_FCGI_CONFIG"]}'."
47
- end
47
+ hayabusa_fcgi_conf_path = cgi.env_table["HTTP_HAYABUSA_FCGI_CONFIG"]
48
+ require hayabusa_fcgi_conf_path
49
+ raise "No 'Hayabusa::FCGI_CONF'-constant was spawned by '#{cgi.env_table["HTTP_HAYABUSA_FCGI_CONFIG"]}'." if !Hayabusa.const_defined?(:FCGI_CONF)
50
+ conf = Hayabusa::FCGI_CONF
48
51
 
49
52
  hayabusa_conf = Hayabusa::FCGI_CONF[:hayabusa]
50
53
  hayabusa_conf.merge!(
@@ -100,9 +103,11 @@ begin
100
103
 
101
104
  if fcgi_proxy
102
105
  #Proxy request to the host-FCGI-process.
106
+ $stderr.puts "[hayabusa] Proxying request." if debug
103
107
  cgi_tools.proxy_request_to(:cgi => cgi, :http => fcgi_proxy[:http])
104
108
  else
105
109
  #Host the FCGI-process.
110
+ $stderr.puts "[hayabusa] Running request as CGI." if debug
106
111
 
107
112
  #Enforce $stdout variable.
108
113
  $stdout = hayabusa.cio
@@ -1,12 +1,11 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
- #This scripts start an appserver, executes a HTTP-request for every FCGI-request and terminates when FCGI terminates.
3
+ #This scripts start an appserver, executes a CGI-request for every FCGI-request and terminates when FCGI terminates.
4
4
  #Good for programming appserver-supported projects that doesnt need threadding without running an appserver all the time.
5
5
 
6
- #It doesnt support shared threadding or objects because multiple instances in form of processes will be executed.
7
-
8
- #Its a bit slower because it needs to flush writes to the database at end of every request and re-read them on spawn, because multiple instances might be present.
6
+ debug = false
9
7
 
8
+ $stderr.puts "[hayabusa] Starting up!" if debug
10
9
  error_log_file = "/tmp/hayabusa_fcgi.log"
11
10
 
12
11
  begin
@@ -16,6 +15,7 @@ rescue Errno::ENOENT
16
15
  end
17
16
 
18
17
  begin
18
+ $stderr.puts "[hayabusa] Loading libs." if debug
19
19
  require "rubygems"
20
20
  require "knjrbfw"
21
21
  require "fcgi"
@@ -27,24 +27,27 @@ begin
27
27
 
28
28
  #We cant define the Hayabusa-server untuil we receive the first headers, so wait for the first request.
29
29
  hayabusa = nil
30
+ hayabusa_fcgi_conf_path = nil
30
31
  fcgi_proxy = nil
31
32
 
33
+ $stderr.puts "[hayabusa] Starting FCGI." if debug
32
34
  FCGI.each_cgi do |cgi|
33
35
  begin
34
36
  #cgi.print "Content-Type: text/html\r\n"
35
37
  #cgi.print "\r\n"
36
38
 
39
+ #Set 'cgi'-variable for CGI-tools.
37
40
  cgi_tools.cgi = cgi
38
41
 
42
+ #Ensure the same FCGI-process isnt active for more than one website.
43
+ raise "Expected 'HTTP_HAYABUSA_FCGI_CONFIG' to be '#{hayabusa_fcgi_conf_path}' but it wasnt: '#{cgi.env_table["HTTP_HAYABUSA_FCGI_CONFIG"]}'." if hayabusa_fcgi_conf_path and hayabusa_fcgi_conf_path != cgi.env_table["HTTP_HAYABUSA_FCGI_CONFIG"]
44
+
39
45
  if !hayabusa
40
46
  raise "No HTTP_HAYABUSA_FCGI_CONFIG-header was given." if !cgi.env_table["HTTP_HAYABUSA_FCGI_CONFIG"]
41
- require cgi.env_table["HTTP_HAYABUSA_FCGI_CONFIG"]
42
-
43
- begin
44
- conf = Hayabusa::FCGI_CONF
45
- rescue NameError
46
- raise "No 'Hayabusa::FCGI_CONF'-constant was spawned by '#{cgi.env_table["HTTP_HAYABUSA_FCGI_CONFIG"]}'."
47
- end
47
+ hayabusa_fcgi_conf_path = cgi.env_table["HTTP_HAYABUSA_FCGI_CONFIG"]
48
+ require hayabusa_fcgi_conf_path
49
+ raise "No 'Hayabusa::FCGI_CONF'-constant was spawned by '#{cgi.env_table["HTTP_HAYABUSA_FCGI_CONFIG"]}'." if !Hayabusa.const_defined?(:FCGI_CONF)
50
+ conf = Hayabusa::FCGI_CONF
48
51
 
49
52
  hayabusa_conf = Hayabusa::FCGI_CONF[:hayabusa]
50
53
  hayabusa_conf.merge!(
@@ -100,9 +103,11 @@ begin
100
103
 
101
104
  if fcgi_proxy
102
105
  #Proxy request to the host-FCGI-process.
106
+ $stderr.puts "[hayabusa] Proxying request." if debug
103
107
  cgi_tools.proxy_request_to(:cgi => cgi, :http => fcgi_proxy[:http])
104
108
  else
105
109
  #Host the FCGI-process.
110
+ $stderr.puts "[hayabusa] Running request as CGI." if debug
106
111
 
107
112
  #Enforce $stdout variable.
108
113
  $stdout = hayabusa.cio
@@ -0,0 +1,15 @@
1
+ <IfModule mod_fcgid.c>
2
+ SocketPath /tmp/fcgi_socket
3
+ FcgidIdleTimeout 30
4
+ FcgidMinProcessesPerClass 0
5
+ FcgidIdleScanInterval 15
6
+ </IfModule>
7
+
8
+ <Directory "/path/to/hayabusa/bin">
9
+ Options +FollowSymLinks +ExecCGI
10
+ Order allow,deny
11
+ Allow from all
12
+ AllowOverride none
13
+ </Directory>
14
+
15
+ Alias /hayabusa_fcgi_bin "/path/to/hayabusa/bin"
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{hayabusa}
8
- s.version = "0.0.1"
8
+ s.version = "0.0.2"
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-08-16}
12
+ s.date = %q{2012-08-17}
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", "knjappserver_start.rb"]
@@ -34,6 +34,7 @@ Gem::Specification.new do |s|
34
34
  "bin/knjappserver_start.rb",
35
35
  "conf/apache2_cgi_rhtml_conf.conf",
36
36
  "conf/apache2_fcgi_rhtml_conf.conf",
37
+ "conf/apache2_hayabusa_conf.conf",
37
38
  "hayabusa.gemspec",
38
39
  "lib/hayabusa.rb",
39
40
  "lib/hayabusa_cgi_session.rb",
@@ -159,7 +159,7 @@ class Hayabusa
159
159
  @db = @config[:db]
160
160
  elsif @config[:db].is_a?(Hash)
161
161
  @db = Knj::Db.new(@config[:db])
162
- elsif !@config[:db] and @config[:db_args]
162
+ elsif @config[:db_args]
163
163
  @db = Knj::Db.new(@config[:db_args])
164
164
  else
165
165
  if @config[:title]
@@ -10,7 +10,23 @@ class Hayabusa::Cgi_session
10
10
  @handlers_cache = @config[:handlers_cache]
11
11
  cgi_conf = @config[:cgi]
12
12
  @get, @post, @meta, @headers = cgi_conf[:get], cgi_conf[:post], cgi_conf[:meta], cgi_conf[:headers]
13
+ @browser = Knj::Web.browser(@meta)
13
14
 
15
+ #Parse cookies and other headers.
16
+ @cookie = {}
17
+ @headers.each do |key, val|
18
+ #$stderr.puts "Header-Key: '#{key}'."
19
+
20
+ case key
21
+ when "COOKIE"
22
+ Knj::Web.parse_cookies(val).each do |key, val|
23
+ @cookie[key] = val
24
+ end
25
+ end
26
+ end
27
+
28
+
29
+ #Set up the 'out', 'written_size' and 'size_send' variables which is used to write output.
14
30
  if cgi_conf[:cgi]
15
31
  @out = cgi_conf[:cgi]
16
32
  else
@@ -36,16 +52,52 @@ class Hayabusa::Cgi_session
36
52
 
37
53
  Dir.chdir(@config[:doc_root])
38
54
  @page_path = @meta["PATH_TRANSLATED"]
55
+ @page_path = "index.rhtml" if @page_path == "/"
56
+
39
57
  @ext = File.extname(@page_path).downcase[1..-1].to_s
40
58
 
41
59
  @resp = Hayabusa::Http_session::Response.new(:socket => self)
42
60
  @resp.reset(:http_version => http_version, :mode => :cgi)
43
- @resp.header("Content-Type", "text/html")
44
61
 
45
62
  @cgroup = Hayabusa::Http_session::Contentgroup.new(:socket => self, :hb => @hb, :resp => @resp, :httpsession => self)
46
63
  @cgroup.reset
47
64
 
48
65
  @resp.cgroup = @cgroup
66
+ @resp.header("Content-Type", "text/html")
67
+
68
+
69
+ #Set up session-variables.
70
+ if @cookie["HayabusaSession"].to_s.length > 0
71
+ @session_id = @cookie["HayabusaSession"]
72
+ elsif @browser["browser"] == "bot"
73
+ @session_id = "bot"
74
+ else
75
+ @session_id = @hb.session_generate_id(@meta)
76
+ send_cookie = true
77
+ end
78
+
79
+ begin
80
+ @session, @session_hash = @hb.session_fromid(@ip, @session_id, @meta)
81
+ rescue ArgumentError => e
82
+ #User should not have the session he asked for because of invalid user-agent or invalid IP.
83
+ @session_id = @hb.session_generate_id(@meta)
84
+ @session, @session_hash = @hb.session_fromid(@ip, @session_id, @meta)
85
+ send_cookie = true
86
+ end
87
+
88
+ if send_cookie
89
+ @resp.cookie(
90
+ "name" => "HayabusaSession",
91
+ "value" => @session_id,
92
+ "path" => "/",
93
+ "expires" => Time.now + 32140800 #add around 12 months
94
+ )
95
+ end
96
+
97
+ raise "'session'-variable could not be spawned." if !@session
98
+ raise "'session_hash'-variable could not be spawned." if !@session_hash
99
+ Thread.current[:hayabusa][:session] = @session
100
+
49
101
 
50
102
  begin
51
103
  @hb.events.call(:request_begin, :httpsession => self) if @hb.events
@@ -55,7 +107,7 @@ class Hayabusa::Cgi_session
55
107
  STDOUT.print "Calling handler.\n" if @debug
56
108
  @handlers_cache[@ext].call(self)
57
109
  else
58
- raise "CGI-mode shouldnt serve static files."
110
+ raise "CGI-mode shouldnt serve static files: '#{@page_path}'."
59
111
  end
60
112
  end
61
113
 
@@ -118,7 +170,6 @@ class Hayabusa::Cgi_session
118
170
  Thread.current[:hayabusa] = {
119
171
  :hb => @hb,
120
172
  :httpsession => self,
121
- :session => @session,
122
173
  :get => @get,
123
174
  :post => @post,
124
175
  :meta => @meta,
@@ -101,8 +101,7 @@ class Hayabusa::Database
101
101
  "indexes" => [
102
102
  {"name" => "date_added", "columns" => ["date_added"]},
103
103
  {"name" => "idhash", "columns" => ["idhash"]}
104
- ],
105
- "renames" => ["sessions"]
104
+ ]
106
105
  },
107
106
  "Translation" => {
108
107
  "columns" => [
@@ -115,10 +114,7 @@ class Hayabusa::Database
115
114
  ],
116
115
  "indexes" => [
117
116
  {"name" => "lookup", "columns" => ["object_class", "object_id", "key", "locale"]}
118
- ],
119
- "indexes_remove" => {
120
- "object_class" => true
121
- }
117
+ ]
122
118
  }
123
119
  }
124
120
  }
@@ -43,6 +43,7 @@ class Hayabusa
43
43
  #Will make the session rememberable for a year. IP wont be checked any more.
44
44
  def session_remember
45
45
  session = _httpsession.session
46
+ raise "Could not get session-variable from HTTP-session." if !session
46
47
  session[:remember] = 1
47
48
 
48
49
  self.cookie(
@@ -20,6 +20,7 @@ end
20
20
 
21
21
  def _session
22
22
  return Thread.current[:hayabusa][:session].sess_data if Thread.current[:hayabusa] and Thread.current[:hayabusa][:session]
23
+ raise "Session was not registered on thread."
23
24
  end
24
25
 
25
26
  def _session_hash
@@ -9,6 +9,7 @@ class Hayabusa::Models::Session < Knj::Datarow
9
9
  if self[:sess_data].to_s.length > 0
10
10
  begin
11
11
  @sess_data = Marshal.load(Base64.decode64(self[:sess_data]))
12
+ raise "The session-data could not be loaded." if !@sess_data
12
13
  rescue ArgumentError
13
14
  @sess_data = {}
14
15
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: hayabusa
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Kasper Johansen
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-08-16 00:00:00 +02:00
13
+ date: 2012-08-17 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -154,6 +154,7 @@ files:
154
154
  - bin/knjappserver_start.rb
155
155
  - conf/apache2_cgi_rhtml_conf.conf
156
156
  - conf/apache2_fcgi_rhtml_conf.conf
157
+ - conf/apache2_hayabusa_conf.conf
157
158
  - hayabusa.gemspec
158
159
  - lib/hayabusa.rb
159
160
  - lib/hayabusa_cgi_session.rb
@@ -236,7 +237,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
236
237
  requirements:
237
238
  - - ">="
238
239
  - !ruby/object:Gem::Version
239
- hash: 3557679821494000327
240
+ hash: 2980723636993966335
240
241
  segments:
241
242
  - 0
242
243
  version: "0"