Description:
fixed X-Sendfile restriction on output download
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r291:43d936feb73b - - 1 file changed: 9 inserted, 5 deleted
@@ -134,53 +134,57 | |||
|
134 | 134 | end |
|
135 | 135 | prepare_grading_result(@submission) |
|
136 | 136 | end |
|
137 | 137 | |
|
138 | 138 | def load_output |
|
139 | 139 | if !Configuration.show_grading_result or params[:num]==nil |
|
140 | 140 | redirect_to :action => 'list' and return |
|
141 | 141 | end |
|
142 | 142 | @user = User.find(session[:user_id]) |
|
143 | 143 | @submission = Submission.find(params[:id]) |
|
144 | 144 | if @submission.user!=@user |
|
145 | 145 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
146 | 146 | redirect_to :action => 'list' and return |
|
147 | 147 | end |
|
148 | 148 | case_num = params[:num].to_i |
|
149 | 149 | out_filename = output_filename(@user.login, |
|
150 | 150 | @submission.problem.name, |
|
151 | 151 | @submission.id, |
|
152 | 152 | case_num) |
|
153 | 153 | if !FileTest.exists?(out_filename) |
|
154 | 154 | flash[:notice] = 'Output not found.' |
|
155 | 155 | redirect_to :action => 'list' and return |
|
156 | 156 | end |
|
157 | 157 | |
|
158 | - response.headers['Content-Type'] = "application/force-download" | |
|
159 | - response.headers['Content-Disposition'] = "attachment; filename=\"output-#{case_num}.txt\"" | |
|
160 | - response.headers["X-Sendfile"] = out_filename | |
|
161 |
- response.headers[ |
|
|
162 | - render :nothing => true | |
|
158 | + if defined?(USE_APACHE_XSENDFILE) and USE_APACHE_XSENDFILE | |
|
159 | + response.headers['Content-Type'] = "application/force-download" | |
|
160 | + response.headers['Content-Disposition'] = "attachment; filename=\"output-#{case_num}.txt\"" | |
|
161 | + response.headers["X-Sendfile"] = out_filename | |
|
162 | + response.headers['Content-length'] = File.size(out_filename) | |
|
163 | + render :nothing => true | |
|
164 | + else | |
|
165 | + send_file out_filename, :stream => false, :filename => "output-#{case_num}.txt", :type => "text/plain" | |
|
166 | + end | |
|
163 | 167 | end |
|
164 | 168 | |
|
165 | 169 | def error |
|
166 | 170 | @user = User.find(session[:user_id]) |
|
167 | 171 | end |
|
168 | 172 | |
|
169 | 173 | # announcement refreshing and hiding methods |
|
170 | 174 | |
|
171 | 175 | def announcements |
|
172 | 176 | if params.has_key? 'recent' |
|
173 | 177 | prepare_announcements(params[:recent]) |
|
174 | 178 | else |
|
175 | 179 | prepare_announcements |
|
176 | 180 | end |
|
177 | 181 | render(:partial => 'announcement', |
|
178 | 182 | :collection => @announcements, |
|
179 | 183 | :locals => {:announcement_effect => true}) |
|
180 | 184 | end |
|
181 | 185 | |
|
182 | 186 | protected |
|
183 | 187 | |
|
184 | 188 | def prepare_announcements(recent=nil) |
|
185 | 189 | if Configuration.show_tasks_to?(@user) |
|
186 | 190 | @announcements = Announcement.find_published(true) |
You need to be logged in to leave comments.
Login now