knjappserver 0.0.16 → 0.0.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/VERSION +1 -1
  2. data/bin/knjappserver_start.rb +17 -25
  3. data/knjappserver.gemspec +17 -6
  4. data/lib/conf/conf_example.rb +3 -3
  5. data/lib/files/database_schema.rb +1 -2
  6. data/lib/include/class_customio.rb +8 -25
  7. data/lib/include/class_erbhandler.rb +7 -1
  8. data/lib/include/class_httpserver.rb +50 -34
  9. data/lib/include/class_httpsession.rb +138 -101
  10. data/lib/include/class_httpsession_contentgroup.rb +52 -24
  11. data/lib/include/class_httpsession_http_request.rb +203 -0
  12. data/lib/include/{class_httpresp.rb → class_httpsession_http_response.rb} +27 -28
  13. data/lib/include/class_httpsession_post_multipart.rb +117 -0
  14. data/lib/include/class_knjappserver.rb +146 -96
  15. data/lib/include/class_knjappserver_cleaner.rb +74 -68
  16. data/lib/include/class_knjappserver_cmdline.rb +23 -17
  17. data/lib/include/class_knjappserver_errors.rb +121 -104
  18. data/lib/include/class_knjappserver_leakproxy_client.rb +6 -0
  19. data/lib/include/class_knjappserver_leakproxy_server.rb +56 -0
  20. data/lib/include/class_knjappserver_logging.rb +25 -25
  21. data/lib/include/class_knjappserver_mailing.rb +84 -56
  22. data/lib/include/class_knjappserver_sessions.rb +15 -22
  23. data/lib/include/class_knjappserver_threadding.rb +70 -43
  24. data/lib/include/class_knjappserver_threadding_timeout.rb +20 -4
  25. data/lib/include/class_knjappserver_translations.rb +6 -4
  26. data/lib/include/class_knjappserver_web.rb +87 -35
  27. data/lib/include/class_log.rb +9 -9
  28. data/lib/include/class_log_link.rb +4 -4
  29. data/lib/include/class_session.rb +8 -4
  30. data/lib/include/gettext_funcs.rb +8 -6
  31. data/lib/include/magic_methods.rb +4 -0
  32. data/lib/pages/debug_database_connections.rhtml +46 -0
  33. data/lib/pages/debug_http_sessions.rhtml +40 -0
  34. data/lib/pages/error_notfound.rhtml +12 -0
  35. data/lib/pages/spec.rhtml +1 -1
  36. data/lib/pages/spec_post.rhtml +3 -0
  37. data/lib/pages/spec_thread_joins.rhtml +21 -0
  38. data/lib/pages/spec_threadded_content.rhtml +2 -0
  39. data/lib/pages/tests.rhtml +14 -0
  40. data/lib/scripts/benchmark.rb +25 -8
  41. data/lib/scripts/knjappserver_cgi.rb +60 -0
  42. data/lib/scripts/knjappserver_fcgi.rb +135 -0
  43. data/lib/scripts/leakproxy.rb +27 -0
  44. data/spec/knjappserver_spec.rb +16 -5
  45. data/spec/leakproxy_spec.rb +56 -0
  46. metadata +38 -27
  47. data/lib/include/class_httpsession_knjengine.rb +0 -154
  48. data/lib/include/class_httpsession_mongrel.rb +0 -75
  49. data/lib/include/class_httpsession_webrick.rb +0 -75
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knjappserver
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.17
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: 2011-11-15 00:00:00.000000000 +01:00
12
+ date: 2012-02-21 00:00:00.000000000 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: knjrbfw
17
- requirement: &19883700 !ruby/object:Gem::Requirement
17
+ requirement: &16146280 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: 0.0.8
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *19883700
25
+ version_requirements: *16146280
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: erubis
28
- requirement: &19796260 !ruby/object:Gem::Requirement
28
+ requirement: &16145700 !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: *19796260
36
+ version_requirements: *16145700
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: knjdbrevision
39
- requirement: &19795540 !ruby/object:Gem::Requirement
39
+ requirement: &16145200 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: 0.0.2
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *19795540
47
+ version_requirements: *16145200
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: mail
50
- requirement: &19794800 !ruby/object:Gem::Requirement
50
+ requirement: &16144680 !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: *19794800
58
+ version_requirements: *16144680
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: rspec
61
- requirement: &19794080 !ruby/object:Gem::Requirement
61
+ requirement: &16144020 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ~>
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: 2.3.0
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *19794080
69
+ version_requirements: *16144020
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: bundler
72
- requirement: &19793340 !ruby/object:Gem::Requirement
72
+ requirement: &16143360 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ~>
@@ -77,10 +77,10 @@ dependencies:
77
77
  version: 1.0.0
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *19793340
80
+ version_requirements: *16143360
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: jeweler
83
- requirement: &19792580 !ruby/object:Gem::Requirement
83
+ requirement: &16141740 !ruby/object:Gem::Requirement
84
84
  none: false
85
85
  requirements:
86
86
  - - ~>
@@ -88,10 +88,10 @@ dependencies:
88
88
  version: 1.6.3
89
89
  type: :development
90
90
  prerelease: false
91
- version_requirements: *19792580
91
+ version_requirements: *16141740
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: rcov
94
- requirement: &19791860 !ruby/object:Gem::Requirement
94
+ requirement: &16090320 !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: *19791860
102
+ version_requirements: *16090320
103
103
  - !ruby/object:Gem::Dependency
104
104
  name: sqlite3
105
- requirement: &19791040 !ruby/object:Gem::Requirement
105
+ requirement: &16089600 !ruby/object:Gem::Requirement
106
106
  none: false
107
107
  requirements:
108
108
  - - ! '>='
@@ -110,10 +110,10 @@ dependencies:
110
110
  version: '0'
111
111
  type: :development
112
112
  prerelease: false
113
- version_requirements: *19791040
113
+ version_requirements: *16089600
114
114
  - !ruby/object:Gem::Dependency
115
115
  name: json
116
- requirement: &19790320 !ruby/object:Gem::Requirement
116
+ requirement: &16088860 !ruby/object:Gem::Requirement
117
117
  none: false
118
118
  requirements:
119
119
  - - ! '>='
@@ -121,7 +121,7 @@ dependencies:
121
121
  version: '0'
122
122
  type: :development
123
123
  prerelease: false
124
- version_requirements: *19790320
124
+ version_requirements: *16088860
125
125
  description: Which supports a lot of undocumented stuff.
126
126
  email: k@spernj.org
127
127
  executables:
@@ -150,17 +150,18 @@ files:
150
150
  - lib/files/run/README
151
151
  - lib/include/class_customio.rb
152
152
  - lib/include/class_erbhandler.rb
153
- - lib/include/class_httpresp.rb
154
153
  - lib/include/class_httpserver.rb
155
154
  - lib/include/class_httpsession.rb
156
155
  - lib/include/class_httpsession_contentgroup.rb
157
- - lib/include/class_httpsession_knjengine.rb
158
- - lib/include/class_httpsession_mongrel.rb
159
- - lib/include/class_httpsession_webrick.rb
156
+ - lib/include/class_httpsession_http_request.rb
157
+ - lib/include/class_httpsession_http_response.rb
158
+ - lib/include/class_httpsession_post_multipart.rb
160
159
  - lib/include/class_knjappserver.rb
161
160
  - lib/include/class_knjappserver_cleaner.rb
162
161
  - lib/include/class_knjappserver_cmdline.rb
163
162
  - lib/include/class_knjappserver_errors.rb
163
+ - lib/include/class_knjappserver_leakproxy_client.rb
164
+ - lib/include/class_knjappserver_leakproxy_server.rb
164
165
  - lib/include/class_knjappserver_logging.rb
165
166
  - lib/include/class_knjappserver_mailing.rb
166
167
  - lib/include/class_knjappserver_sessions.rb
@@ -182,13 +183,23 @@ files:
182
183
  - lib/pages/benchmark_print.rhtml
183
184
  - lib/pages/benchmark_simple.rhtml
184
185
  - lib/pages/benchmark_threadded_content.rhtml
186
+ - lib/pages/debug_database_connections.rhtml
187
+ - lib/pages/debug_http_sessions.rhtml
188
+ - lib/pages/error_notfound.rhtml
185
189
  - lib/pages/logs_latest.rhtml
186
190
  - lib/pages/logs_show.rhtml
187
191
  - lib/pages/spec.rhtml
192
+ - lib/pages/spec_post.rhtml
188
193
  - lib/pages/spec_test_multiple_clients.rhtml
194
+ - lib/pages/spec_thread_joins.rhtml
189
195
  - lib/pages/spec_threadded_content.rhtml
196
+ - lib/pages/tests.rhtml
190
197
  - lib/scripts/benchmark.rb
198
+ - lib/scripts/knjappserver_cgi.rb
199
+ - lib/scripts/knjappserver_fcgi.rb
200
+ - lib/scripts/leakproxy.rb
191
201
  - spec/knjappserver_spec.rb
202
+ - spec/leakproxy_spec.rb
192
203
  - spec/spec_helper.rb
193
204
  has_rdoc: true
194
205
  homepage: http://github.com/kaspernj/knjappserver
@@ -206,7 +217,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
206
217
  version: '0'
207
218
  segments:
208
219
  - 0
209
- hash: -4377496633346000305
220
+ hash: -3001161973856161206
210
221
  required_rubygems_version: !ruby/object:Gem::Requirement
211
222
  none: false
212
223
  requirements:
@@ -1,154 +0,0 @@
1
- require "uri"
2
-
3
- if RUBY_PLATFORM == "java" or RUBY_ENGINE == "rbx"
4
- BasicSocket.do_not_reverse_lookup = true
5
- end
6
-
7
- class Knjappserver::Httpsession::Knjengine
8
- attr_reader :get, :post, :cookie, :meta, :page_path, :headers, :http_version
9
-
10
- def initialize(args)
11
- @args = args
12
- @kas = @args[:kas]
13
- @crlf = "\r\n"
14
- end
15
-
16
- def read_socket
17
- loop do
18
- raise Errno::ECONNRESET, "Socket closed." if @socket.closed?
19
- read = @socket.gets
20
- raise Errno::ECONNRESET, "Socket returned non-string: '#{read.class.name}'." if !read.is_a?(String)
21
- @cont += read
22
- break if @cont[-4..-1] == "\r\n\r\n" or @cont[-2..-1] == "\n\n"
23
- end
24
- end
25
-
26
- def socket_parse(socket)
27
- @cont = ""
28
- @socket = socket
29
- self.read_socket
30
-
31
- #Parse URI (page_path and get).
32
- match = @cont.match(/^(GET|POST|HEAD) (.+) HTTP\/1\.(\d+)\s*/)
33
- raise "Could not parse request: '#{@cont.split("\n").first}'." if !match
34
-
35
- @http_version = "1.#{match[3]}"
36
-
37
- method = match[1]
38
- @cont = @cont.gsub(match[0], "")
39
- uri = URI.parse(match[2])
40
-
41
- page_filepath = Knj::Web.urldec(uri.path)
42
- if page_filepath.length <= 0 or page_filepath == "/" or File.directory?("#{@kas.config[:doc_root]}/#{page_filepath}")
43
- page_filepath = "#{page_filepath}/#{@kas.config[:default_page]}"
44
- end
45
-
46
- @page_path = "#{@kas.config[:doc_root]}/#{page_filepath}"
47
- @get = Knj::Web.parse_urlquery(uri.query.to_s, {:urldecode => true, :force_utf8 => true})
48
-
49
-
50
- #Parse headers, cookies and meta.
51
- if RUBY_PLATFORM == "java" or RUBY_ENGINE == "rbx"
52
- if @kas.config[:peeraddr_static]
53
- addr_peer = [0, 0, @kas.config[:peeraddr_static]]
54
- else
55
- addr_peer = @socket.peeraddr
56
- end
57
-
58
- addr = @socket.addr
59
- else
60
- addr = @socket.addr(false)
61
- addr_peer = @socket.peeraddr(false)
62
- end
63
-
64
- @headers = {}
65
- @cookie = {}
66
- @meta = {
67
- "REQUEST_METHOD" => method,
68
- "QUERY_STRING" => uri.query,
69
- "REQUEST_URI" => match[2],
70
- "REMOTE_ADDR" => addr[2],
71
- "REMOTE_PORT" => addr[1],
72
- "SERVER_ADDR" => addr_peer[2],
73
- "SERVER_PORT" => addr_peer[1],
74
- "SCRIPT_NAME" => uri.path
75
- }
76
-
77
- @cont.scan(/(\S+):\s*(.+)\r\n/) do |header_match|
78
- key = header_match[0].downcase
79
- val = header_match[1]
80
-
81
- @headers[key] = [] if !@headers.has_key?(key)
82
- @headers[key] << val
83
-
84
- case key
85
- when "cookie"
86
- Knj::Web.parse_cookies(val).each do |key, val|
87
- @cookie[key] = val
88
- end
89
- else
90
- key = key.upcase.gsub("-", "_")
91
- @meta["HTTP_#{key}"] = val
92
- end
93
- end
94
-
95
-
96
- #Parse post
97
- @post = {}
98
-
99
- if method == "POST"
100
- post_treated = {}
101
- post_data = @socket.read(@headers["content-length"][0].to_i)
102
-
103
- if @headers["content-type"] and match = @headers["content-type"][0].match(/^multipart\/form-data; boundary=(.+)\Z/)
104
- io = StringIO.new(post_data)
105
- post_treated = parse_form_data(io, match[1])
106
- else
107
- post_data.split("&").each do |splitted|
108
- splitted = splitted.split("=")
109
- post_treated[Knj::Web.urldec(splitted[0])] = splitted[1]
110
- end
111
- end
112
-
113
- self.convert_webrick_post(@post, post_treated, {:urldecode => true})
114
- end
115
- end
116
-
117
- def convert_webrick_post(seton, webrick_post, args = {})
118
- webrick_post.each do |varname, value|
119
- Knj::Web.parse_name(seton, varname, value, args)
120
- end
121
- end
122
-
123
- #Thanks to WEBrick
124
- def parse_form_data(io, boundary)
125
- boundary_regexp = /\A--#{boundary}(--)?#{@crlf}\z/
126
- form_data = {}
127
- return form_data unless io
128
- data = nil
129
-
130
- io.each do |line|
131
- if boundary_regexp =~ line
132
- if data
133
- data.chop!
134
- key = data.name
135
-
136
- if form_data.has_key?(key)
137
- form_data[key].append_data(data)
138
- else
139
- form_data[key] = data
140
- end
141
- end
142
-
143
- data = WEBrick::HTTPUtils::FormData.new
144
- next
145
- else
146
- if data
147
- data << line
148
- end
149
- end
150
- end
151
-
152
- return form_data
153
- end
154
- end
@@ -1,75 +0,0 @@
1
- class Knjappserver::Httpsession::Webrick
2
- attr_reader :get, :post, :cookie, :meta, :page_path, :headers
3
-
4
- def initialize(args)
5
- @args = args
6
- @kas = @args[:kas]
7
- end
8
-
9
- def socket_parse(socket)
10
- req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
11
- req.parse(socket)
12
-
13
-
14
- #Set meta.
15
- @meta = req.meta_vars
16
-
17
-
18
- #Set page_path.
19
- page_filepath = meta["PATH_INFO"]
20
- if page_filepath.length <= 0 or page_filepath == "/" or File.directory?("#{@kas.config[:doc_root]}/#{page_filepath}")
21
- page_filepath = "#{page_filepath}/#{@kas.config[:default_page]}"
22
- end
23
-
24
- @page_path = "#{@kas.config[:doc_root]}/#{page_filepath}"
25
-
26
-
27
- #Set get and headers.
28
- @get = Knj::Web.parse_urlquery(@meta["QUERY_STRING"])
29
- @headers = req.header
30
-
31
-
32
- #Set post.
33
- @post = {}
34
- if meta["REQUEST_METHOD"] == "POST"
35
- self.convert_webrick_post(@post, req.query)
36
- end
37
-
38
-
39
- #Set cookie.
40
- @cookie = {}
41
-
42
- req.cookies.each do |cookie_enum|
43
- @cookie[cookie_enum.name] = Knj::Web.urldec(cookie_enum.value)
44
- end
45
-
46
-
47
- req.fixup if req and req.keep_alive?
48
- end
49
-
50
- def convert_webrick_post(seton, webrick_post, args = {})
51
- webrick_post.each do |varname, value|
52
- Knj::Web.parse_name(seton, varname, value, args)
53
- end
54
- end
55
-
56
- def destroy
57
- @args.clear if @args
58
- @args = nil
59
- @kas = nil
60
-
61
- @meta.clear if @meta
62
- @meta = nil
63
-
64
- @page_path = nil
65
-
66
- @get.clear if @get
67
- @get = nil
68
-
69
- @post.clear if @post
70
- @post = nil
71
-
72
- @cookie.clear if @cookie
73
- @cookie = nil
74
- end
75
- end
@@ -1,75 +0,0 @@
1
- class Knjappserver::Httpsession::Webrick
2
- attr_reader :get, :post, :cookie, :meta, :page_path, :headers
3
-
4
- def initialize(args)
5
- @args = args
6
- @kas = @args[:kas]
7
- end
8
-
9
- def socket_parse(socket)
10
- req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
11
- req.parse(socket)
12
-
13
-
14
- #Set meta.
15
- @meta = req.meta_vars
16
-
17
-
18
- #Set page_path.
19
- page_filepath = meta["PATH_INFO"]
20
- if page_filepath.length <= 0 or page_filepath == "/" or File.directory?("#{@kas.config[:doc_root]}/#{page_filepath}")
21
- page_filepath = "#{page_filepath}/#{@kas.config[:default_page]}"
22
- end
23
-
24
- @page_path = "#{@kas.config[:doc_root]}/#{page_filepath}"
25
-
26
-
27
- #Set get and headers.
28
- @get = Knj::Web.parse_urlquery(@meta["QUERY_STRING"])
29
- @headers = req.header
30
-
31
-
32
- #Set post.
33
- @post = {}
34
- if meta["REQUEST_METHOD"] == "POST"
35
- self.convert_webrick_post(@post, req.query)
36
- end
37
-
38
-
39
- #Set cookie.
40
- @cookie = {}
41
-
42
- req.cookies.each do |cookie_enum|
43
- @cookie[cookie_enum.name] = Knj::Web.urldec(cookie_enum.value)
44
- end
45
-
46
-
47
- req.fixup if req and req.keep_alive?
48
- end
49
-
50
- def convert_webrick_post(seton, webrick_post, args = {})
51
- webrick_post.each do |varname, value|
52
- Knj::Web.parse_name(seton, varname, value, args)
53
- end
54
- end
55
-
56
- def destroy
57
- @args.clear if @args
58
- @args = nil
59
- @kas = nil
60
-
61
- @meta.clear if @meta
62
- @meta = nil
63
-
64
- @page_path = nil
65
-
66
- @get.clear if @get
67
- @get = nil
68
-
69
- @post.clear if @post
70
- @post = nil
71
-
72
- @cookie.clear if @cookie
73
- @cookie = nil
74
- end
75
- end