knjappserver 0.0.28 → 0.0.29
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/Gemfile.lock +5 -4
- data/VERSION +1 -1
- data/knjappserver.gemspec +2 -2
- data/lib/include/class_httpsession.rb +1 -1
- data/lib/include/class_knjappserver.rb +16 -31
- data/lib/include/class_knjappserver_sessions.rb +0 -1
- data/lib/include/class_knjappserver_web.rb +55 -3
- data/lib/scripts/knjappserver_cgi.rb +18 -8
- data/lib/scripts/knjappserver_fcgi.rb +6 -4
- metadata +3 -3
data/Gemfile.lock
CHANGED
@@ -1,19 +1,20 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
datet (0.0.
|
4
|
+
datet (0.0.10)
|
5
5
|
diff-lcs (1.1.3)
|
6
6
|
erubis (2.7.0)
|
7
7
|
git (1.2.5)
|
8
|
-
http2 (0.0.
|
9
|
-
knjrbfw
|
8
|
+
http2 (0.0.4)
|
10
9
|
i18n (0.6.0)
|
11
10
|
jeweler (1.6.4)
|
12
11
|
bundler (~> 1.0)
|
13
12
|
git (>= 1.2.5)
|
14
13
|
rake
|
15
14
|
json (1.7.3)
|
16
|
-
knjrbfw (0.0.
|
15
|
+
knjrbfw (0.0.66)
|
16
|
+
datet
|
17
|
+
http2
|
17
18
|
tsafe
|
18
19
|
wref
|
19
20
|
mail (2.4.4)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.29
|
data/knjappserver.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{knjappserver}
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.29"
|
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-07-
|
12
|
+
s.date = %q{2012-07-20}
|
13
13
|
s.description = %q{Which supports a lot of undocumented stuff.}
|
14
14
|
s.email = %q{k@spernj.org}
|
15
15
|
s.executables = ["check_running.rb", "knjappserver_start.rb"]
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#This class handels the HTTP-sessions.
|
2
2
|
class Knjappserver::Httpsession
|
3
3
|
attr_accessor :data, :alert_sent
|
4
|
-
attr_reader :cookie, :get, :session, :session_id, :session_hash, :kas, :active, :out, :eruby, :browser, :debug, :resp, :page_path, :post, :cgroup, :meta, :httpsession_var, :handler, :working
|
4
|
+
attr_reader :cookie, :get, :headers, :session, :session_id, :session_hash, :kas, :active, :out, :eruby, :browser, :debug, :resp, :page_path, :post, :cgroup, :meta, :httpsession_var, :handler, :working
|
5
5
|
|
6
6
|
#Autoloader for subclasses.
|
7
7
|
def self.const_missing(name)
|
@@ -1,3 +1,11 @@
|
|
1
|
+
require "timeout"
|
2
|
+
require "digest"
|
3
|
+
require "erubis"
|
4
|
+
require "base64"
|
5
|
+
require "stringio"
|
6
|
+
require "socket"
|
7
|
+
require "tsafe" if !Kernel.const_defined?(:Tsafe)
|
8
|
+
|
1
9
|
#The class that stands for the whole appserver / webserver.
|
2
10
|
#===Examples
|
3
11
|
# appsrv = Knjappserver.new(
|
@@ -35,6 +43,14 @@ class Knjappserver
|
|
35
43
|
raise "No ':doc_root' was given in arguments." if !@config.has_key?(:doc_root)
|
36
44
|
|
37
45
|
|
46
|
+
#Require gems.
|
47
|
+
gems = %w[datet]
|
48
|
+
gems.each do |gem|
|
49
|
+
puts "Loading gem: '#{gem}'." if @debug
|
50
|
+
require gem
|
51
|
+
end
|
52
|
+
|
53
|
+
|
38
54
|
#Setup default handlers if none are given.
|
39
55
|
if !@config.has_key?(:handlers)
|
40
56
|
@erbhandler = Knjappserver::ERBHandler.new
|
@@ -121,8 +137,6 @@ class Knjappserver
|
|
121
137
|
#Load various required files from knjrbfw and stuff in the knjappserver-framework.
|
122
138
|
files = [
|
123
139
|
"#{@path_knjrbfw}knjrbfw.rb",
|
124
|
-
"#{@path_knjappserver}/class_httpserver.rb",
|
125
|
-
"#{@path_knjappserver}/class_httpsession.rb",
|
126
140
|
"#{@path_knjappserver}/class_knjappserver_errors.rb",
|
127
141
|
"#{@path_knjappserver}/class_knjappserver_logging.rb",
|
128
142
|
"#{@path_knjappserver}/class_knjappserver_mailing.rb",
|
@@ -131,35 +145,6 @@ class Knjappserver
|
|
131
145
|
"#{@path_knjappserver}/class_knjappserver_web.rb"
|
132
146
|
]
|
133
147
|
|
134
|
-
if @config[:preload]
|
135
|
-
require "timeout"
|
136
|
-
require "digest"
|
137
|
-
require "erubis"
|
138
|
-
require "base64"
|
139
|
-
require "stringio"
|
140
|
-
require "socket"
|
141
|
-
require "tsafe" if !Kernel.const_defined?(:Tsafe)
|
142
|
-
|
143
|
-
files += [
|
144
|
-
"#{@path_knjrbfw}knj/event_handler.rb",
|
145
|
-
"#{@path_knjrbfw}knj/errors.rb",
|
146
|
-
"#{@path_knjrbfw}knj/eruby.rb",
|
147
|
-
"#{@path_knjrbfw}knj/hash_methods.rb",
|
148
|
-
"#{@path_knjrbfw}knj/objects.rb",
|
149
|
-
"#{@path_knjrbfw}knj/web.rb",
|
150
|
-
"#{@path_knjrbfw}knj/datarow.rb",
|
151
|
-
"#{@path_knjrbfw}knj/datet.rb",
|
152
|
-
"#{@path_knjrbfw}knj/php.rb",
|
153
|
-
"#{@path_knjrbfw}knj/thread.rb",
|
154
|
-
"#{@path_knjrbfw}knj/threadhandler.rb",
|
155
|
-
"#{@path_knjrbfw}knj/threadpool.rb",
|
156
|
-
"#{@path_knjrbfw}knj/translations.rb",
|
157
|
-
"#{@path_knjrbfw}knj/knjdb/libknjdb.rb",
|
158
|
-
]
|
159
|
-
else
|
160
|
-
files << "#{@path_knjrbfw}knj/autoload.rb"
|
161
|
-
end
|
162
|
-
|
163
148
|
files << "#{@path_knjrbfw}knj/gettext_threadded.rb" if @config[:locales_root]
|
164
149
|
files.each do |file|
|
165
150
|
STDOUT.print "Loading: '#{file}'.\n" if @debug
|
@@ -1,5 +1,7 @@
|
|
1
1
|
class Knjappserver
|
2
2
|
#Imports a .rhtml-file and executes it.
|
3
|
+
#===Examples
|
4
|
+
# _kas.import("/some/path/page.rhtml")
|
3
5
|
def import(filepath)
|
4
6
|
if filepath.to_s.index("../proc/self") != nil
|
5
7
|
raise Errno::EACCES, "Possible attempt to hack the appserver."
|
@@ -9,6 +11,9 @@ class Knjappserver
|
|
9
11
|
end
|
10
12
|
|
11
13
|
#Redirects to another URL.
|
14
|
+
#===Examples
|
15
|
+
# _kas.redirect("someotherpage.rhtml")
|
16
|
+
# _kas.redirect("newpage.rhtml", :perm => true)
|
12
17
|
def redirect(url, args = {})
|
13
18
|
#Header way
|
14
19
|
if !_httpsession.alert_sent and !self.headers_sent?
|
@@ -26,6 +31,8 @@ class Knjappserver
|
|
26
31
|
end
|
27
32
|
|
28
33
|
#Sends a javascript-alert to the HTML.
|
34
|
+
#===Examples
|
35
|
+
# _kas.alert("Hello world!")
|
29
36
|
def alert(msg)
|
30
37
|
_httpsession.alert_sent = true
|
31
38
|
Knj::Web.alert(msg)
|
@@ -33,6 +40,8 @@ class Knjappserver
|
|
33
40
|
end
|
34
41
|
|
35
42
|
#Define a cookies in the clients browser.
|
43
|
+
#===Examples
|
44
|
+
# _kas.cookie(:name => "MyCookie", :value => "Trala")
|
36
45
|
def cookie(cookie)
|
37
46
|
raise "No HTTP-session attached to this thread." if !_httpsession
|
38
47
|
raise "HTTP-session not active." if !_httpsession.resp
|
@@ -41,6 +50,8 @@ class Knjappserver
|
|
41
50
|
end
|
42
51
|
|
43
52
|
#Sends a header to the clients browser.
|
53
|
+
#===Examples
|
54
|
+
# _kas.header("Content-Type", "text/javascript")
|
44
55
|
def header(key, val)
|
45
56
|
raise "No HTTP-session attached to this thread." if !_httpsession
|
46
57
|
raise "HTTP-session not active." if !_httpsession.resp
|
@@ -54,17 +65,56 @@ class Knjappserver
|
|
54
65
|
Knj::Php.header(str)
|
55
66
|
end
|
56
67
|
|
68
|
+
#Returns true if the headers are already sent.
|
69
|
+
#===Examples
|
70
|
+
# _kas.headers_sent? #=> true
|
57
71
|
def headers_sent?
|
58
72
|
return true if _httpsession.resp.headers_sent
|
59
73
|
return false
|
60
74
|
end
|
61
75
|
|
76
|
+
#Define the size for when to automatically send headers. If you want to send hundres of kilobytes and then a header, you can use this method to do so.
|
77
|
+
#===Examples
|
78
|
+
#Set the size to 200 kb.
|
79
|
+
# _kas.headers_send_size = (1024 * 200)
|
62
80
|
def headers_send_size=(newsize)
|
63
|
-
if self.headers_sent?
|
64
|
-
|
81
|
+
raise "The headers are already sent and you cannot modify the send-size any more." if self.headers_sent?
|
82
|
+
_httpsession.size_send = newsize.to_i
|
83
|
+
end
|
84
|
+
|
85
|
+
#Serves the given filepath and enables caching for it. No other content should be written to the page when using this method.
|
86
|
+
#===Examples
|
87
|
+
# _kas.header("Content-Type", "text/javascript")
|
88
|
+
# _kas.serve_file("somefile.js")
|
89
|
+
def serve_file(filepath)
|
90
|
+
raise "File doesnt exist: '#{filepath}'." if !File.exists?(filepath)
|
91
|
+
httpsess = _httpsession
|
92
|
+
headers = httpsess.headers
|
93
|
+
resp = httpsess.resp
|
94
|
+
|
95
|
+
if headers["cache-control"] and headers["cache-control"][0]
|
96
|
+
cache_control = {}
|
97
|
+
headers["cache-control"][0].scan(/(.+)=(.+)/) do |match|
|
98
|
+
cache_control[match[1]] = match[2]
|
99
|
+
end
|
65
100
|
end
|
66
101
|
|
67
|
-
|
102
|
+
cache_dont = true if cache_control and cache_control.key?("max-age") and cache_control["max-age"].to_i <= 0
|
103
|
+
lastmod = File.mtime(filepath)
|
104
|
+
|
105
|
+
self.header("Last-Modified", lastmod.httpdate)
|
106
|
+
self.header("Expires", (Time.now + 86400).httpdate) #next day.
|
107
|
+
|
108
|
+
if !cache_dont and headers["if-modified-since"] and headers["if-modified-since"][0]
|
109
|
+
request_mod = Datet.in(headers["if-modified-since"].first).time
|
110
|
+
|
111
|
+
if request_mod == lastmod
|
112
|
+
resp.status = 304
|
113
|
+
return nil
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
httpsess.force_content(:type => :file, :path => filepath)
|
68
118
|
end
|
69
119
|
|
70
120
|
#Sends a javascript back to the browser and exits.
|
@@ -78,6 +128,8 @@ class Knjappserver
|
|
78
128
|
end
|
79
129
|
|
80
130
|
#Urlencodes a string.
|
131
|
+
#===Examples
|
132
|
+
# _kas.redirect("mypage.rhtml?arg=#{_kas.urlenc(value_variable)}")
|
81
133
|
def urlenc(str)
|
82
134
|
return Knj::Web.urlenc(str)
|
83
135
|
end
|
@@ -43,9 +43,18 @@ class Knjappserver
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
+
require "knjrbfw"
|
47
|
+
|
46
48
|
begin
|
47
|
-
require "
|
48
|
-
require "
|
49
|
+
require "http2"
|
50
|
+
require "tsafe"
|
51
|
+
|
52
|
+
#Read real path.
|
53
|
+
file = __FILE__
|
54
|
+
file = File.readlink(file) if File.symlink?(file)
|
55
|
+
file = File.realpath(file)
|
56
|
+
|
57
|
+
require "#{File.dirname(file)}/../knjappserver.rb"
|
49
58
|
|
50
59
|
raise "No HTTP_KNJAPPSERVER_CGI_CONFIG-header was given." if !ENV["HTTP_KNJAPPSERVER_CGI_CONFIG"]
|
51
60
|
require ENV["HTTP_KNJAPPSERVER_CGI_CONFIG"]
|
@@ -80,7 +89,7 @@ begin
|
|
80
89
|
headers = {}
|
81
90
|
cgi.env_table.each do |key, val|
|
82
91
|
if key[0, 5] == "HTTP_" and key != "HTTP_KNJAPPSERVER_CGI_CONFIG"
|
83
|
-
key =
|
92
|
+
key = key[5, key.length].gsub("_", " ").gsub(" ", "-")
|
84
93
|
headers[key] = val
|
85
94
|
end
|
86
95
|
end
|
@@ -109,7 +118,7 @@ begin
|
|
109
118
|
cgi.print(line) if count > 0
|
110
119
|
count += 1
|
111
120
|
}
|
112
|
-
|
121
|
+
)
|
113
122
|
elsif cgi.request_method == "POST"
|
114
123
|
count = 0
|
115
124
|
http.post(:url => url, :post => Knjappserver.convert_fcgi_post(cgi.params),
|
@@ -119,17 +128,18 @@ begin
|
|
119
128
|
cgi.print(line) if count > 0
|
120
129
|
count += 1
|
121
130
|
}
|
122
|
-
|
131
|
+
)
|
123
132
|
else
|
124
133
|
count = 0
|
125
|
-
http.get(
|
134
|
+
http.get(
|
135
|
+
:url => url,
|
126
136
|
:default_headers => headers,
|
127
137
|
:cookies => false,
|
128
138
|
:on_content => proc{|line|
|
129
139
|
cgi.print(line) if count > 0
|
130
140
|
count += 1
|
131
141
|
}
|
132
|
-
|
142
|
+
)
|
133
143
|
end
|
134
144
|
rescue Exception => e
|
135
145
|
print "Content-Type: text/html\r\n"
|
@@ -139,6 +149,6 @@ rescue Exception => e
|
|
139
149
|
begin
|
140
150
|
knjappserver.stop if knjappserver
|
141
151
|
rescue => e
|
142
|
-
print "<br />\n<br />\n
|
152
|
+
print "<br />\n<br />\n#{Knj::Errors.error_str(e, {:html => true})}"
|
143
153
|
end
|
144
154
|
end
|
@@ -8,9 +8,11 @@
|
|
8
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.
|
9
9
|
|
10
10
|
require "rubygems"
|
11
|
+
require "knjrbfw"
|
12
|
+
require "http2"
|
13
|
+
require "tsafe"
|
11
14
|
require "fcgi"
|
12
15
|
|
13
|
-
require "knj/autoload"
|
14
16
|
require "#{File.dirname(Knj::Os.realpath(__FILE__))}/../knjappserver.rb"
|
15
17
|
|
16
18
|
class Knjappserver
|
@@ -101,7 +103,7 @@ FCGI.each_cgi do |cgi|
|
|
101
103
|
cgi.print(line) if count > 0
|
102
104
|
count += 1
|
103
105
|
}
|
104
|
-
|
106
|
+
)
|
105
107
|
elsif cgi.request_method == "POST"
|
106
108
|
count = 0
|
107
109
|
http.post(:url => url, :post => Knjappserver.convert_fcgi_post(cgi.params),
|
@@ -111,7 +113,7 @@ FCGI.each_cgi do |cgi|
|
|
111
113
|
cgi.print(line) if count > 0
|
112
114
|
count += 1
|
113
115
|
}
|
114
|
-
|
116
|
+
)
|
115
117
|
else
|
116
118
|
count = 0
|
117
119
|
http.get(:url => url,
|
@@ -121,7 +123,7 @@ FCGI.each_cgi do |cgi|
|
|
121
123
|
cgi.print(line) if count > 0
|
122
124
|
count += 1
|
123
125
|
}
|
124
|
-
|
126
|
+
)
|
125
127
|
end
|
126
128
|
|
127
129
|
thread_spawn = Thread.new do
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: knjappserver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.29
|
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-07-
|
13
|
+
date: 2012-07-20 00:00:00 +02:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -230,7 +230,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
230
230
|
requirements:
|
231
231
|
- - ">="
|
232
232
|
- !ruby/object:Gem::Version
|
233
|
-
hash:
|
233
|
+
hash: 4291663965426138445
|
234
234
|
segments:
|
235
235
|
- 0
|
236
236
|
version: "0"
|