mongrel 0.3.12.1 → 0.3.12.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -32,7 +32,7 @@ end
32
32
  setup_extension("http11", "http11")
33
33
 
34
34
  name="mongrel"
35
- version="0.3.12.1"
35
+ version="0.3.12.2"
36
36
 
37
37
  setup_gem(name, version) do |spec|
38
38
  spec.summary = "A small fast HTTP library and server that runs Rails, Camping, and Nitro apps."
@@ -520,7 +520,7 @@ void Init_http11()
520
520
  DEF_GLOBAL(server_protocol, "SERVER_PROTOCOL");
521
521
  DEF_GLOBAL(server_protocol_value, "HTTP/1.1");
522
522
  DEF_GLOBAL(http_host, "HTTP_HOST");
523
- DEF_GLOBAL(mongrel_version, "Mongrel 0.3.12.1");
523
+ DEF_GLOBAL(mongrel_version, "Mongrel 0.3.12.2");
524
524
  DEF_GLOBAL(server_software, "SERVER_SOFTWARE");
525
525
  DEF_GLOBAL(port_80, "80");
526
526
 
@@ -99,7 +99,7 @@ module Mongrel
99
99
  # The original URI requested by the client. Passed to URIClassifier to build PATH_INFO and SCRIPT_NAME.
100
100
  REQUEST_URI='REQUEST_URI'.freeze
101
101
 
102
- MONGREL_VERSION="0.3.12.1".freeze
102
+ MONGREL_VERSION="0.3.12.2".freeze
103
103
 
104
104
  # The standard empty 404 response for bad requests. Use Error4040Handler for custom stuff.
105
105
  ERROR_404_RESPONSE="HTTP/1.1 404 Not Found\r\nConnection: close\r\nServer: #{MONGREL_VERSION}\r\n\r\nNOT FOUND".freeze
@@ -0,0 +1,178 @@
1
+ require 'mongrel'
2
+ require 'cgi'
3
+
4
+ module Mongrel module Rails
5
+
6
+
7
+ # Implements a handler that can run Rails and serve files out of the
8
+ # Rails application's public directory. This lets you run your Rails
9
+ # application with Mongrel during development and testing, then use it
10
+ # also in production behind a server that's better at serving the
11
+ # static files.
12
+ #
13
+ # The RailsHandler takes a mime_map parameter which is a simple suffix=mimetype
14
+ # mapping that it should add to the list of valid mime types.
15
+ #
16
+ # It also supports page caching directly and will try to resolve a request
17
+ # in the following order:
18
+ #
19
+ # * If the requested exact PATH_INFO exists as a file then serve it.
20
+ # * If it exists at PATH_INFO+".html" exists then serve that.
21
+ # * Finally, construct a Mongrel::CGIWrapper and run Dispatcher.dispath to have Rails go.
22
+ #
23
+ # This means that if you are using page caching it will actually work with Mongrel
24
+ # and you should see a decent speed boost (but not as fast as if you use lighttpd).
25
+ #
26
+ # An additional feature you can use is
27
+ class RailsHandler < Mongrel::HttpHandler
28
+ attr_reader :files
29
+ attr_reader :guard
30
+
31
+ def initialize(dir, mime_map = {})
32
+ @files = Mongrel::DirHandler.new(dir,false)
33
+ @guard = Mutex.new
34
+
35
+ # register the requested mime types
36
+ mime_map.each {|k,v| Mongrel::DirHandler::add_mime_type(k,v) }
37
+ end
38
+
39
+ # Attempts to resolve the request as follows:
40
+ #
41
+ #
42
+ # * If the requested exact PATH_INFO exists as a file then serve it.
43
+ # * If it exists at PATH_INFO+".html" exists then serve that.
44
+ # * Finally, construct a Mongrel::CGIWrapper and run Dispatcher.dispath to have Rails go.
45
+ def process(request, response)
46
+ return if response.socket.closed?
47
+
48
+ path_info = request.params[Mongrel::Const::PATH_INFO]
49
+ page_cached = request.params[Mongrel::Const::PATH_INFO] + ".html"
50
+
51
+ if @files.can_serve(path_info)
52
+ # File exists as-is so serve it up
53
+ @files.process(request,response)
54
+ elsif @files.can_serve(page_cached)
55
+ # possible cached page, serve it up
56
+ request.params[Mongrel::Const::PATH_INFO] = page_cached
57
+ @files.process(request,response)
58
+ else
59
+ begin
60
+ cgi = Mongrel::CGIWrapper.new(request, response)
61
+ cgi.handler = self
62
+
63
+ @guard.synchronize do
64
+ # Rails is not thread safe so must be run entirely within synchronize
65
+ Dispatcher.dispatch(cgi, ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, response.body)
66
+ end
67
+
68
+ # This finalizes the output using the proper HttpResponse way
69
+ cgi.out {""}
70
+ rescue Errno::EPIPE
71
+ # ignored
72
+ rescue Object => rails_error
73
+ STDERR.puts "Error calling Dispatcher.dispatch #{rails_error.inspect}"
74
+ STDERR.puts rails_error.backtrace.join("\n")
75
+ end
76
+ end
77
+ end
78
+
79
+
80
+ # Does the internal reload for Rails. It might work for most cases, but
81
+ # sometimes you get exceptions. In that case just do a real restart.
82
+ def reload!
83
+ @guard.synchronize do
84
+ $".replace $orig_dollar_quote
85
+ GC.start
86
+ Dispatcher.reset_application!
87
+ ActionController::Routing::Routes.reload
88
+ end
89
+ end
90
+ end
91
+
92
+ # Creates Rails specific configuration options for people to use
93
+ # instead of the base Configurator.
94
+ class RailsConfigurator < Mongrel::Configurator
95
+
96
+ # Creates a single rails handler and returns it so you
97
+ # can add it to a uri. You can actually attach it to
98
+ # as many URIs as you want, but this returns the
99
+ # same RailsHandler for each call.
100
+ #
101
+ # Requires the following options:
102
+ #
103
+ # * :docroot => The public dir to serve from.
104
+ # * :environment => Rails environment to use.
105
+ # * :cwd => The change to working directory
106
+ #
107
+ # And understands the following optional settings:
108
+ #
109
+ # * :mime => A map of mime types.
110
+ #
111
+ # Because of how Rails is designed you can only have
112
+ # one installed per Ruby interpreter (talk to them
113
+ # about thread safety). Because of this the first
114
+ # time you call this function it does all the config
115
+ # needed to get your rails working. After that
116
+ # it returns the one handler you've configured.
117
+ # This lets you attach Rails to any URI (and mulitple)
118
+ # you want, but still protects you from threads destroying
119
+ # your handler.
120
+ def rails(options={})
121
+
122
+ return @rails_handler if @rails_handler
123
+
124
+ ops = resolve_defaults(options)
125
+
126
+ # fix up some defaults
127
+ ops[:environment] ||= "development"
128
+ ops[:docroot] ||= "public"
129
+ ops[:mime] ||= {}
130
+
131
+
132
+ $orig_dollar_quote = $".clone
133
+ ENV['RAILS_ENV'] = ops[:environment]
134
+ env_location = "#{ops[:cwd]}/config/environment"
135
+ require env_location
136
+ require 'dispatcher'
137
+ require 'mongrel/rails'
138
+
139
+ @rails_handler = RailsHandler.new(ops[:docroot], ops[:mime])
140
+ end
141
+
142
+
143
+ # Reloads rails. This isn't too reliable really, but
144
+ # should work for most minimal reload purposes. Only reliable
145
+ # way it so stop then start the process.
146
+ def reload!
147
+ if not @rails_handler
148
+ raise "Rails was not configured. Read the docs for RailsConfigurator."
149
+ end
150
+
151
+ log "Reloading rails..."
152
+ @rails_handler.reload!
153
+ log "Done reloading rails."
154
+
155
+ end
156
+
157
+ # Takes the exact same configuration as Mongrel::Configurator (and actually calls that)
158
+ # but sets up the additional HUP handler to call reload!.
159
+ def setup_rails_signals(options={})
160
+ ops = resolve_defaults(options)
161
+
162
+ if RUBY_PLATFORM !~ /mswin/
163
+ setup_signals(options)
164
+
165
+ # rails reload
166
+ trap("HUP") {
167
+ log "HUP signal received."
168
+ reload!
169
+ }
170
+
171
+ log "Rails signals registered. HUP => reload (without restart). It might not work well."
172
+ else
173
+ log "WARNING: Rails does not support signals on Win32."
174
+ end
175
+ end
176
+ end
177
+ end
178
+ end
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: mongrel
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.3.12.1
6
+ version: 0.3.12.2
7
7
  date: 2006-04-04 00:00:00 -04:00
8
8
  summary: A small fast HTTP library and server that runs Rails, Camping, and Nitro apps.
9
9
  require_paths:
@@ -247,6 +247,7 @@ files:
247
247
  - test/test_ws.rb
248
248
  - lib/mongrel
249
249
  - lib/mongrel.rb
250
+ - lib/mongrel/#rails.rb#
250
251
  - lib/mongrel/camping.rb
251
252
  - lib/mongrel/cgi.rb
252
253
  - lib/mongrel/command