Browse files

Add workaround for 502's on bad `gem push`

If we return a 401 without reading the request body (ie, bad API token)
then apache gets confused and shows the user a 502. So we have to be
sure to read the body even if we don't need it.
  • Loading branch information...
1 parent ccd3403 commit e7b69023992ab37d5d820f3cc15f26f702a784a4 @evanphx evanphx committed Mar 20, 2012
Showing with 7 additions and 0 deletions.
  1. +7 −0 app/controllers/application_controller.rb
View
7 app/controllers/application_controller.rb
@@ -15,6 +15,13 @@ def authenticate_with_api_key
def verify_authenticated_user
if current_user.nil?
+ # When in passenger, this forces the whole body to be read before
+ # we return a 401 and end the request. We need to do this because
+ # otherwise apache is confused why we never read the whole body.
+ #
+ # This works because request.body is a RewindableInput which will
+ # slurp all the socket data into a tempfile, satisfying apache.
+ request.body.size if request.body.respond_to? :size
render :text => t(:please_sign_up), :status => 401
end
end

0 comments on commit e7b6902

Please sign in to comment.