So I have a little application that does not need sessions at all. To turn them off, I added this line in my environment.rb file: ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS = false However, when I run this application, I get this from the webserver: environment.rb:87: warning: already initialized constant DEFAULT_SESSION_OPTIONS I cannot find where it is already initialized. Where should I be looking for this? Shelby
On Aug 19, 2005, at 9:36 PM, Shelby Westman wrote:> So I have a little application that does not need sessions at all. To > turn them off, I added this line in my environment.rb file: > ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS = false > > However, when I run this application, I get this from the webserver: > environment.rb:87: warning: already initialized constant > DEFAULT_SESSION_OPTIONS > > I cannot find where it is already initialized. Where should I be > looking for this?It is defined in CgiRequest itself. However, the good news is that in the next version of rails, you can just put the following in your ApplicationController: session :off The bad news is you can''t do that until the next version of rails. So, instead, try: ActionController::CgiRequest.remove_const(:DEFAULT_SESSION_OPTIONS) ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS = false - Jamis
Jamis wrote:> The bad news is you can''t do that until the next version of rails. > So, instead, try: > > ActionController::CgiRequest.remove_const(:DEFAULT_SESSION_OPTIONS) > ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS = false >I gave it a try, and WebBrick wasn''t happy. This is what it told me: ./script/../config/environment.rb:87: private method `remove_const'' called for ActionController::CgiRequest:Class (NoMethodError) from script/server:42:in `require'' from script/server:42 Shelby
Shelby Westman wrote:> Jamis wrote: > >>The bad news is you can''t do that until the next version of rails. >>So, instead, try: >> >> ActionController::CgiRequest.remove_const(:DEFAULT_SESSION_OPTIONS) >> ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS = false >> > > > I gave it a try, and WebBrick wasn''t happy. This is what it told me: > ../script/../config/environment.rb:87: private method `remove_const'' > called for ActionController::CgiRequest:Class (NoMethodError) > from script/server:42:in `require'' > from script/server:42This is defined on line 42 in: gems/1.8/gems/actionpack-1.9.1/lib/action_controller/cgi_process.rb You can remove the const by doing: ActionController::CgiRequest.send( :remove_const, :DEFAULT_SESSION_OPTIONS ) ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS = false Zach
On Aug 19, 2005, at 10:11 PM, Shelby Westman wrote:> Jamis wrote: > >> The bad news is you can''t do that until the next version of rails. >> So, instead, try: >> >> ActionController::CgiRequest.remove_const >> (:DEFAULT_SESSION_OPTIONS) >> ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS = false >> >> > > I gave it a try, and WebBrick wasn''t happy. This is what it told me: > ./script/../config/environment.rb:87: private method `remove_const'' > called for ActionController::CgiRequest:Class (NoMethodError) > from script/server:42:in `require'' > from script/server:42Yup, my bad, I always forget that''s a private method. You can do as Zach suggested and use send to invoke the method, even though it isn''t public. - Jamis
To have no sessions, I tried: ActionController::CgiRequest.send( :remove_const, :DEFAULT_SESSION_OPTIONS ) ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS = false This did allow the webrick server to start, but Webrick fails to run the application. The webrick server says "/find not found". "/find" is the root level of the application as defined in routes.rb. Webrick also said: #<TypeError: cannot convert nil into Array> ...lib/webrick_server.rb:113:in `concat''", However, the app _does_ work ok in lighttpd with the DEFAULT_SESSION_OPTIONS = false. So I looked at line 113 in the webrick server code. I''ve quoted the whole method below. Line 113 is the one has something to do with setting a cookie. I don''t know why the absence of sessions would cause the webrick server to fail here... Is this a bug in Webrick? def handle_dispatch(req, res, origin = nil) data = StringIO.new Dispatcher.dispatch( CGI.new("query", create_env_table(req, origin), StringIO.new(req.body || "")), ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, data ) header, body = extract_header_and_body(data) assign_status(res, header) res.cookies.concat(header.delete(''set-cookie'')) header.each { |key, val| res[key] = val.join(", ") } res.body = body return true rescue => err p err, err.backtrace return false end
On Aug 20, 2005, at 8:21 AM, Shelby Westman wrote:> To have no sessions, I tried: > > ActionController::CgiRequest.send( :remove_const, > :DEFAULT_SESSION_OPTIONS ) > ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS = false > > This did allow the webrick server to start, but Webrick fails to run > the application. The webrick server says "/find not found". "/find" > is the root level of the application as defined in routes.rb. > Webrick also said: > #<TypeError: cannot convert nil into Array> > ...lib/webrick_server.rb:113:in `concat''", > > However, the app _does_ work ok in lighttpd with the > DEFAULT_SESSION_OPTIONS = false. > > So I looked at line 113 in the webrick server code. I''ve quoted the > whole method below. Line 113 is the one has something to do with > setting a cookie. I don''t know why the absence of sessions would > cause the webrick server to fail here... Is this a bug in Webrick? > > def handle_dispatch(req, res, origin = nil) > data = StringIO.new > Dispatcher.dispatch( > CGI.new("query", create_env_table(req, origin), > StringIO.new(req.body || "")), > ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, > data > ) > > header, body = extract_header_and_body(data) > assign_status(res, header) > res.cookies.concat(header.delete(''set-cookie''))Yes, the above line appears to be buggy, in that it always assumes that the browser is sending exactly one cookie. There may, in fact, be zero or many. If you could file a bug report on the rails trac about this (http://dev.rubyonrails.com), that''d be great. - Jamis> header.each { |key, val| res[key] = val.join(", ") } > > res.body = body > return true > rescue => err > p err, err.backtrace > return false > end > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
You can also edit webrick_server.rb:113 res.cookies.concat(header.delete(''set-cookie'')) and add a block after the delete with an empty array like so: res.cookies.concat(header.delete(''set-cookie'') {[]} ) and the problem goes away. - Guy On 8/20/05, Jamis Buck <jamis-uHoyYlH2B+GakBO8gow8eQ@public.gmane.org> wrote:> On Aug 20, 2005, at 8:21 AM, Shelby Westman wrote: > > > To have no sessions, I tried: > > > > ActionController::CgiRequest.send( :remove_const, > > :DEFAULT_SESSION_OPTIONS ) > > ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS = false > > > > This did allow the webrick server to start, but Webrick fails to run > > the application. The webrick server says "/find not found". "/find" > > is the root level of the application as defined in routes.rb. > > Webrick also said: > > #<TypeError: cannot convert nil into Array> > > ...lib/webrick_server.rb:113:in `concat''", > > > > However, the app _does_ work ok in lighttpd with the > > DEFAULT_SESSION_OPTIONS = false. > > > > So I looked at line 113 in the webrick server code. I''ve quoted the > > whole method below. Line 113 is the one has something to do with > > setting a cookie. I don''t know why the absence of sessions would > > cause the webrick server to fail here... Is this a bug in Webrick? > > > > def handle_dispatch(req, res, origin = nil) > > data = StringIO.new > > Dispatcher.dispatch( > > CGI.new("query", create_env_table(req, origin), > > StringIO.new(req.body || "")), > > ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, > > data > > ) > > > > header, body = extract_header_and_body(data) > > assign_status(res, header) > > res.cookies.concat(header.delete(''set-cookie'')) > > Yes, the above line appears to be buggy, in that it always assumes > that the browser is sending exactly one cookie. There may, in fact, > be zero or many. If you could file a bug report on the rails trac > about this (http://dev.rubyonrails.com), that''d be great. > > - Jamis > > > header.each { |key, val| res[key] = val.join(", ") } > > > > res.body = body > > return true > > rescue => err > > p err, err.backtrace > > return false > > end > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
on 8/19/2005 8:36 PM Shelby Westman said the following:>So I have a little application that does not need sessions at all. To >turn them off, I added this line in my environment.rb file: >ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS = false > >However, when I run this application, I get this from the webserver: >environment.rb:87: warning: already initialized constant DEFAULT_SESSION_OPTIONS > >I cannot find where it is already initialized. Where should I be >looking for this? >It is initialized in ActionController::CgiRequest, which is in gems/actionpack*/lib/action_controller/cgi_process.rb. The fact that the documentation (AWDwR, p 319) says that you should reinitialize a constant seems to me to be a bug in the documentation. That it seems like this is the only way to turn off sessions seems like a bug in the implementation. If you look at the code in ActionController::CgiRequest, you can see that the initialization of DEFAULT_SESSION_OPTIONS is conditional upon it not being already defined, so perhaps there has been a change in the execution path of the code. Does your application work with this configuration? My applications rely on sessions, so they all break with this same line, which implies that the definition serves to stop the creation of session, at least under webrick. Ray