Description:
fixed X-Sendfile restriction on output download
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r291:43d936feb73b - - 1 file changed: 4 inserted, 0 deleted

@@ -146,29 +146,33
146 redirect_to :action => 'list' and return
146 redirect_to :action => 'list' and return
147 end
147 end
148 case_num = params[:num].to_i
148 case_num = params[:num].to_i
149 out_filename = output_filename(@user.login,
149 out_filename = output_filename(@user.login,
150 @submission.problem.name,
150 @submission.problem.name,
151 @submission.id,
151 @submission.id,
152 case_num)
152 case_num)
153 if !FileTest.exists?(out_filename)
153 if !FileTest.exists?(out_filename)
154 flash[:notice] = 'Output not found.'
154 flash[:notice] = 'Output not found.'
155 redirect_to :action => 'list' and return
155 redirect_to :action => 'list' and return
156 end
156 end
157
157
158 + if defined?(USE_APACHE_XSENDFILE) and USE_APACHE_XSENDFILE
158 response.headers['Content-Type'] = "application/force-download"
159 response.headers['Content-Type'] = "application/force-download"
159 response.headers['Content-Disposition'] = "attachment; filename=\"output-#{case_num}.txt\""
160 response.headers['Content-Disposition'] = "attachment; filename=\"output-#{case_num}.txt\""
160 response.headers["X-Sendfile"] = out_filename
161 response.headers["X-Sendfile"] = out_filename
161 response.headers['Content-length'] = File.size(out_filename)
162 response.headers['Content-length'] = File.size(out_filename)
162 render :nothing => true
163 render :nothing => true
164 + else
165 + send_file out_filename, :stream => false, :filename => "output-#{case_num}.txt", :type => "text/plain"
166 + end
163 end
167 end
164
168
165 def error
169 def error
166 @user = User.find(session[:user_id])
170 @user = User.find(session[:user_id])
167 end
171 end
168
172
169 # announcement refreshing and hiding methods
173 # announcement refreshing and hiding methods
170
174
171 def announcements
175 def announcements
172 if params.has_key? 'recent'
176 if params.has_key? 'recent'
173 prepare_announcements(params[:recent])
177 prepare_announcements(params[:recent])
174 else
178 else
You need to be logged in to leave comments. Login now