Skip to content

Commit

Permalink
Cookies are now only set when changed (closes #1)
Browse files Browse the repository at this point in the history
  • Loading branch information
judofyr committed Nov 2, 2009
1 parent 5600fe6 commit 99cfee3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions lib/camping-unabridged.rb
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,8 @@ def to_a
@env['rack.session'] = @state
r = Rack::Response.new(@body, @status, @headers)
@cookies.each do |k, v|
v = {:value => v, :path => self / "/"} if String === v
next if @old_cookies[k] == v
v = { :value => v, :path => self / "/" } if String === v
r.set_cookie(k, v)
end
r.to_a
Expand All @@ -367,7 +368,7 @@ def initialize(env, m) #:nodoc:
@root, @input, @cookies, @state,
@headers, @status, @method =
r.script_name.sub(/\/$/,''), n(r.params),
H[r.cookies], H[r.session],
H[@old_cookies = r.cookies], H[r.session],
{}, m =~ /r(\d+)/ ? $1.to_i : 200, m
end

Expand Down
6 changes: 3 additions & 3 deletions lib/camping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ def r s,b,h={};b,h=h,b if Hash===b;@status=s;
to_s;end;def r404 p;P%"#{p} not found"end;def r500 k,m,e;raise e;end
def r501 m;P%"#{m.upcase} not implemented"end;def to_a
@env['rack.session']=@state;r=Rack::Response.new(@body,@status,@headers)
@cookies.each{|k,v|v={:value=>v,:path=>self/"/"} if String===v
r.set_cookie(k,v)}
@cookies.each{|k,v|next if @old_cookies[k]==v;v={:value=>v,:path=>self/"/"} if
String===v;r.set_cookie(k,v)}
r.to_a;end;def initialize(env,m)
r=@request=Rack::Request.new(@env=env)
@root,@input,@cookies,@state,@headers,@status,@method=
r.script_name.sub(/\/$/,''),n(r.params),
H[r.cookies],H[r.session],{},m=~/r(\d+)/?$1.to_i: 200,m
H[@old_cookies = r.cookies],H[r.session],{},m=~/r(\d+)/?$1.to_i: 200,m
end;def n h;Hash===h ?h.inject(H[]){|m,(k,v)|m[k]=n(v);m}: h end;def service *a
r=catch(:halt){send(@method,*a)};@body||=r
self;end;end;module Controllers;@r=[];class<<self;def r;@r end;def R *u;r=@r
Expand Down

0 comments on commit 99cfee3

Please sign in to comment.