mongrel 1.1.4-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. data.tar.gz.sig +0 -0
  2. data/CHANGELOG +16 -0
  3. data/COPYING +55 -0
  4. data/LICENSE +55 -0
  5. data/Manifest +69 -0
  6. data/README +74 -0
  7. data/TODO +5 -0
  8. data/bin/mongrel_rails +283 -0
  9. data/examples/builder.rb +29 -0
  10. data/examples/camping/README +3 -0
  11. data/examples/camping/blog.rb +294 -0
  12. data/examples/camping/tepee.rb +149 -0
  13. data/examples/httpd.conf +474 -0
  14. data/examples/mime.yaml +3 -0
  15. data/examples/mongrel.conf +9 -0
  16. data/examples/mongrel_simple_ctrl.rb +92 -0
  17. data/examples/mongrel_simple_service.rb +116 -0
  18. data/examples/monitrc +57 -0
  19. data/examples/random_thrash.rb +19 -0
  20. data/examples/simpletest.rb +52 -0
  21. data/examples/webrick_compare.rb +20 -0
  22. data/ext/http11/ext_help.h +14 -0
  23. data/ext/http11/extconf.rb +6 -0
  24. data/ext/http11/http11.c +402 -0
  25. data/ext/http11/http11_parser.c +1221 -0
  26. data/ext/http11/http11_parser.h +49 -0
  27. data/ext/http11/http11_parser.java.rl +170 -0
  28. data/ext/http11/http11_parser.rl +152 -0
  29. data/ext/http11/http11_parser_common.rl +54 -0
  30. data/ext/http11_java/Http11Service.java +13 -0
  31. data/ext/http11_java/org/jruby/mongrel/Http11.java +266 -0
  32. data/ext/http11_java/org/jruby/mongrel/Http11Parser.java +572 -0
  33. data/lib/http11.so +0 -0
  34. data/lib/mongrel.rb +355 -0
  35. data/lib/mongrel/camping.rb +107 -0
  36. data/lib/mongrel/cgi.rb +181 -0
  37. data/lib/mongrel/command.rb +222 -0
  38. data/lib/mongrel/configurator.rb +388 -0
  39. data/lib/mongrel/const.rb +110 -0
  40. data/lib/mongrel/debug.rb +203 -0
  41. data/lib/mongrel/gems.rb +22 -0
  42. data/lib/mongrel/handlers.rb +468 -0
  43. data/lib/mongrel/header_out.rb +28 -0
  44. data/lib/mongrel/http_request.rb +155 -0
  45. data/lib/mongrel/http_response.rb +163 -0
  46. data/lib/mongrel/init.rb +10 -0
  47. data/lib/mongrel/mime_types.yml +616 -0
  48. data/lib/mongrel/rails.rb +185 -0
  49. data/lib/mongrel/stats.rb +89 -0
  50. data/lib/mongrel/tcphack.rb +18 -0
  51. data/lib/mongrel/uri_classifier.rb +76 -0
  52. data/mongrel-public_cert.pem +20 -0
  53. data/mongrel.gemspec +231 -0
  54. data/setup.rb +1585 -0
  55. data/test/mime.yaml +3 -0
  56. data/test/mongrel.conf +1 -0
  57. data/test/test_cgi_wrapper.rb +26 -0
  58. data/test/test_command.rb +86 -0
  59. data/test/test_conditional.rb +107 -0
  60. data/test/test_configurator.rb +87 -0
  61. data/test/test_debug.rb +25 -0
  62. data/test/test_handlers.rb +123 -0
  63. data/test/test_http11.rb +156 -0
  64. data/test/test_redirect_handler.rb +44 -0
  65. data/test/test_request_progress.rb +99 -0
  66. data/test/test_response.rb +127 -0
  67. data/test/test_stats.rb +35 -0
  68. data/test/test_uriclassifier.rb +261 -0
  69. data/test/test_ws.rb +115 -0
  70. data/test/testhelp.rb +66 -0
  71. data/tools/trickletest.rb +45 -0
  72. metadata +152 -0
  73. metadata.gz.sig +0 -0
@@ -0,0 +1,29 @@
1
+ require 'mongrel'
2
+
3
+ class TestPlugin < GemPlugin::Plugin "/handlers"
4
+ include Mongrel::HttpHandlerPlugin
5
+
6
+ def process(request, response)
7
+ STDERR.puts "My options are: #{options.inspect}"
8
+ STDERR.puts "Request Was:"
9
+ STDERR.puts request.params.to_yaml
10
+ end
11
+ end
12
+
13
+ config = Mongrel::Configurator.new :host => "127.0.0.1" do
14
+ load_plugins :includes => ["mongrel"], :excludes => ["rails"]
15
+ daemonize :cwd => Dir.pwd, :log_file => "mongrel.log", :pid_file => "mongrel.pid"
16
+
17
+ listener :port => 3000 do
18
+ uri "/app", :handler => plugin("/handlers/testplugin", :test => "that")
19
+ uri "/app", :handler => Mongrel::DirHandler.new(".")
20
+ load_plugins :includes => ["mongrel", "rails"]
21
+ end
22
+
23
+ trap("INT") { stop }
24
+ run
25
+ end
26
+
27
+ config.join
28
+
29
+
@@ -0,0 +1,3 @@
1
+ To get these examples running, install Camping.
2
+
3
+ Instructions here: http://code.whytheluckystiff.net/camping/
@@ -0,0 +1,294 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.dirname(__FILE__) + "/../../lib"
4
+ require 'rubygems'
5
+ require_gem 'camping', '>=1.4'
6
+ require 'camping/session'
7
+
8
+ Camping.goes :Blog
9
+
10
+ module Blog
11
+ include Camping::Session
12
+ end
13
+
14
+ module Blog::Models
15
+ def self.schema(&block)
16
+ @@schema = block if block_given?
17
+ @@schema
18
+ end
19
+
20
+ class Post < Base; belongs_to :user; end
21
+ class Comment < Base; belongs_to :user; end
22
+ class User < Base; end
23
+ end
24
+
25
+ Blog::Models.schema do
26
+ create_table :blog_posts, :force => true do |t|
27
+ t.column :id, :integer, :null => false
28
+ t.column :user_id, :integer, :null => false
29
+ t.column :title, :string, :limit => 255
30
+ t.column :body, :text
31
+ end
32
+ create_table :blog_users, :force => true do |t|
33
+ t.column :id, :integer, :null => false
34
+ t.column :username, :string
35
+ t.column :password, :string
36
+ end
37
+ create_table :blog_comments, :force => true do |t|
38
+ t.column :id, :integer, :null => false
39
+ t.column :post_id, :integer, :null => false
40
+ t.column :username, :string
41
+ t.column :body, :text
42
+ end
43
+ execute "INSERT INTO blog_users (username, password) VALUES ('admin', 'camping')"
44
+ end
45
+
46
+ module Blog::Controllers
47
+ class Index < R '/'
48
+ def get
49
+ @posts = Post.find :all
50
+ render :index
51
+ end
52
+ end
53
+
54
+ class Add
55
+ def get
56
+ unless @state.user_id.blank?
57
+ @user = User.find @state.user_id
58
+ @post = Post.new
59
+ end
60
+ render :add
61
+ end
62
+ def post
63
+ post = Post.create :title => input.post_title, :body => input.post_body,
64
+ :user_id => @state.user_id
65
+ redirect View, post
66
+ end
67
+ end
68
+
69
+ class Info < R '/info/(\d+)', '/info/(\w+)/(\d+)', '/info', '/info/(\d+)/(\d+)/(\d+)/([\w-]+)'
70
+ def get(*args)
71
+ div do
72
+ code args.inspect; br; br
73
+ code ENV.inspect; br
74
+ code "Link: #{R(Info, 1, 2)}"
75
+ end
76
+ end
77
+ end
78
+
79
+ class View < R '/view/(\d+)'
80
+ def get post_id
81
+ @post = Post.find post_id
82
+ @comments = Models::Comment.find :all, :conditions => ['post_id = ?', post_id]
83
+ render :view
84
+ end
85
+ end
86
+
87
+ class Edit < R '/edit/(\d+)', '/edit'
88
+ def get post_id
89
+ unless @state.user_id.blank?
90
+ @user = User.find @state.user_id
91
+ end
92
+ @post = Post.find post_id
93
+ render :edit
94
+ end
95
+
96
+ def post
97
+ @post = Post.find input.post_id
98
+ @post.update_attributes :title => input.post_title, :body => input.post_body
99
+ redirect View, @post
100
+ end
101
+ end
102
+
103
+ class Comment
104
+ def post
105
+ Models::Comment.create(:username => input.post_username,
106
+ :body => input.post_body, :post_id => input.post_id)
107
+ redirect View, input.post_id
108
+ end
109
+ end
110
+
111
+ class Login
112
+ def post
113
+ @user = User.find :first, :conditions => ['username = ? AND password = ?', input.username, input.password]
114
+
115
+ if @user
116
+ @login = 'login success !'
117
+ @state.user_id = @user.id
118
+ else
119
+ @login = 'wrong user name or password'
120
+ end
121
+ render :login
122
+ end
123
+ end
124
+
125
+ class Logout
126
+ def get
127
+ @state.user_id = nil
128
+ render :logout
129
+ end
130
+ end
131
+
132
+ class Style < R '/styles.css'
133
+ def get
134
+ @headers["Content-Type"] = "text/css; charset=utf-8"
135
+ @body = %{
136
+ body {
137
+ font-family: Utopia, Georga, serif;
138
+ }
139
+ h1.header {
140
+ background-color: #fef;
141
+ margin: 0; padding: 10px;
142
+ }
143
+ div.content {
144
+ padding: 10px;
145
+ }
146
+ }
147
+ end
148
+ end
149
+ end
150
+
151
+ module Blog::Views
152
+
153
+ def layout
154
+ html do
155
+ head do
156
+ title 'blog'
157
+ link :rel => 'stylesheet', :type => 'text/css',
158
+ :href => '/styles.css', :media => 'screen'
159
+ end
160
+ body do
161
+ h1.header { a 'blog', :href => R(Index) }
162
+ div.content do
163
+ self << yield
164
+ end
165
+ end
166
+ end
167
+ end
168
+
169
+ def index
170
+ if @posts.empty?
171
+ p 'No posts found.'
172
+ p { a 'Add', :href => R(Add) }
173
+ else
174
+ for post in @posts
175
+ _post(post)
176
+ end
177
+ end
178
+ end
179
+
180
+ def login
181
+ p { b @login }
182
+ p { a 'Continue', :href => R(Add) }
183
+ end
184
+
185
+ def logout
186
+ p "You have been logged out."
187
+ p { a 'Continue', :href => R(Index) }
188
+ end
189
+
190
+ def add
191
+ if @user
192
+ _form(post, :action => R(Add))
193
+ else
194
+ _login
195
+ end
196
+ end
197
+
198
+ def edit
199
+ if @user
200
+ _form(post, :action => R(Edit))
201
+ else
202
+ _login
203
+ end
204
+ end
205
+
206
+ def view
207
+ _post(post)
208
+
209
+ p "Comment for this post:"
210
+ for c in @comments
211
+ h1 c.username
212
+ p c.body
213
+ end
214
+
215
+ form :action => R(Comment), :method => 'post' do
216
+ label 'Name', :for => 'post_username'; br
217
+ input :name => 'post_username', :type => 'text'; br
218
+ label 'Comment', :for => 'post_body'; br
219
+ textarea :name => 'post_body' do; end; br
220
+ input :type => 'hidden', :name => 'post_id', :value => post.id
221
+ input :type => 'submit'
222
+ end
223
+ end
224
+
225
+ # partials
226
+ def _login
227
+ form :action => R(Login), :method => 'post' do
228
+ label 'Username', :for => 'username'; br
229
+ input :name => 'username', :type => 'text'; br
230
+
231
+ label 'Password', :for => 'password'; br
232
+ input :name => 'password', :type => 'text'; br
233
+
234
+ input :type => 'submit', :name => 'login', :value => 'Login'
235
+ end
236
+ end
237
+
238
+ def _post(post)
239
+ h1 post.title
240
+ p post.body
241
+ p do
242
+ a "Edit", :href => R(Edit, post)
243
+ a "View", :href => R(View, post)
244
+ end
245
+ end
246
+
247
+ def _form(post, opts)
248
+ p do
249
+ text "You are logged in as #{@user.username} | "
250
+ a 'Logout', :href => R(Logout)
251
+ end
252
+ form({:method => 'post'}.merge(opts)) do
253
+ label 'Title', :for => 'post_title'; br
254
+ input :name => 'post_title', :type => 'text',
255
+ :value => post.title; br
256
+
257
+ label 'Body', :for => 'post_body'; br
258
+ textarea post.body, :name => 'post_body'; br
259
+
260
+ input :type => 'hidden', :name => 'post_id', :value => post.id
261
+ input :type => 'submit'
262
+ end
263
+ end
264
+ end
265
+
266
+ def Blog.create
267
+ Camping::Models::Session.create_schema
268
+ unless Blog::Models::Post.table_exists?
269
+ ActiveRecord::Schema.define(&Blog::Models.schema)
270
+ end
271
+ end
272
+
273
+ if __FILE__ == $0
274
+ require 'mongrel/camping'
275
+
276
+ Blog::Models::Base.establish_connection :adapter => 'sqlite3', :database => 'blog.db'
277
+ Blog::Models::Base.logger = Logger.new('camping.log')
278
+ Blog::Models::Base.threaded_connections=false
279
+ Blog.create
280
+
281
+ # Use the Configurator as an example rather than Mongrel::Camping.start
282
+ config = Mongrel::Configurator.new :host => "0.0.0.0" do
283
+ listener :port => 3002 do
284
+ uri "/blog", :handler => Mongrel::Camping::CampingHandler.new(Blog)
285
+ uri "/favicon", :handler => Mongrel::Error404Handler.new("")
286
+ trap("INT") { stop }
287
+ run
288
+ end
289
+ end
290
+
291
+ puts "** Blog example is running at http://localhost:3002/blog"
292
+ puts "** Default username is `admin', password is `camping'"
293
+ config.join
294
+ end
@@ -0,0 +1,149 @@
1
+ #!/usr/bin/ruby
2
+ $:.unshift File.dirname(__FILE__) + "/../../lib"
3
+ %w(rubygems redcloth camping acts_as_versioned).each { |lib| require lib }
4
+
5
+ Camping.goes :Tepee
6
+
7
+ module Tepee::Models
8
+ def self.schema(&block)
9
+ @@schema = block if block_given?
10
+ @@schema
11
+ end
12
+
13
+ class Page < Base
14
+ PAGE_LINK = /\[\[([^\]|]*)[|]?([^\]]*)\]\]/
15
+ validates_uniqueness_of :title
16
+ before_save { |r| r.title = r.title.underscore }
17
+ acts_as_versioned
18
+ end
19
+ end
20
+
21
+ Tepee::Models.schema do
22
+ create_table :tepee_pages, :force => true do |t|
23
+ t.column :title, :string, :limit => 255
24
+ t.column :body, :text
25
+ end
26
+ Tepee::Models::Page.create_versioned_table
27
+ end
28
+
29
+ module Tepee::Controllers
30
+ class Index < R '/'
31
+ def get
32
+ redirect Show, 'home_page'
33
+ end
34
+ end
35
+
36
+ class List < R '/list'
37
+ def get
38
+ @pages = Page.find :all, :order => 'title'
39
+ render :list
40
+ end
41
+ end
42
+
43
+ class Show < R '/s/(\w+)', '/s/(\w+)/(\d+)'
44
+ def get page_name, version = nil
45
+ redirect(Edit, page_name, 1) and return unless @page = Page.find_by_title(page_name)
46
+ @version = (version.nil? or version == @page.version.to_s) ? @page : @page.versions.find_by_version(version)
47
+ render :show
48
+ end
49
+ end
50
+
51
+ class Edit < R '/e/(\w+)/(\d+)', '/e/(\w+)'
52
+ def get page_name, version = nil
53
+ @page = Page.find_or_create_by_title(page_name)
54
+ @page = @page.versions.find_by_version(version) unless version.nil? or version == @page.version.to_s
55
+ render :edit
56
+ end
57
+
58
+ def post page_name
59
+ Page.find_or_create_by_title(page_name).update_attributes :body => input.post_body and redirect Show, page_name
60
+ end
61
+ end
62
+ end
63
+
64
+ module Tepee::Views
65
+ def layout
66
+ html do
67
+ head do
68
+ title 'test'
69
+ end
70
+ body do
71
+ p do
72
+ small do
73
+ span "welcome to " ; a 'tepee', :href => "http://code.whytheluckystiff.net/svn/camping/trunk/examples/tepee/"
74
+ span '. go ' ; a 'home', :href => R(Show, 'home_page')
75
+ span '. list all ' ; a 'pages', :href => R(List)
76
+ end
77
+ end
78
+ div.content do
79
+ self << yield
80
+ end
81
+ end
82
+ end
83
+ end
84
+
85
+ def show
86
+ h1 @page.title
87
+ div { _markup @version.body }
88
+ p do
89
+ a 'edit', :href => R(Edit, @version.title, @version.version)
90
+ a 'back', :href => R(Show, @version.title, @version.version-1) unless @version.version == 1
91
+ a 'next', :href => R(Show, @version.title, @version.version+1) unless @version.version == @page.version
92
+ a 'current', :href => R(Show, @version.title) unless @version.version == @page.version
93
+ end
94
+ end
95
+
96
+ def edit
97
+ form :method => 'post', :action => R(Edit, @page.title) do
98
+ p do
99
+ label 'Body' ; br
100
+ textarea @page.body, :name => 'post_body', :rows => 50, :cols => 100
101
+ end
102
+
103
+ p do
104
+ input :type => 'submit'
105
+ a 'cancel', :href => R(Show, @page.title, @page.version)
106
+ end
107
+ end
108
+ end
109
+
110
+ def list
111
+ h1 'all pages'
112
+ ul { @pages.each { |p| li { a p.title, :href => R(Show, p.title) } } }
113
+ end
114
+
115
+ def _markup body
116
+ return '' if body.blank?
117
+ body.gsub!(Tepee::Models::Page::PAGE_LINK) do
118
+ page = title = $1
119
+ title = $2 unless $2.empty?
120
+ page = page.gsub /\W/, '_'
121
+ if Tepee::Models::Page.find(:all, :select => 'title').collect { |p| p.title }.include?(page)
122
+ %Q{<a href="#{self/R(Show, page)}">#{title}</a>}
123
+ else
124
+ %Q{<span>#{title}<a href="#{self/R(Edit, page, 1)}">?</a></span>}
125
+ end
126
+ end
127
+ RedCloth.new(body, [ :hard_breaks ]).to_html
128
+ end
129
+ end
130
+
131
+ def Tepee.create
132
+ unless Tepee::Models::Page.table_exists?
133
+ ActiveRecord::Schema.define(&Tepee::Models.schema)
134
+ Tepee::Models::Page.reset_column_information
135
+ end
136
+ end
137
+
138
+ if __FILE__ == $0
139
+ require 'mongrel/camping'
140
+
141
+ Tepee::Models::Base.establish_connection :adapter => 'sqlite3', :database => 'tepee.db'
142
+ Tepee::Models::Base.logger = Logger.new('camping.log')
143
+ Tepee::Models::Base.threaded_connections=false
144
+ Tepee.create
145
+
146
+ server = Mongrel::Camping::start("0.0.0.0",3000,"/tepee",Tepee)
147
+ puts "** Tepee example is running at http://localhost:3000/tepee"
148
+ server.acceptor.join
149
+ end