Skip to content

Commit

Permalink
Merge pull request #1231 from benoitc/fix/gh1177
Browse files Browse the repository at this point in the history
prevent crash when reporting an error
  • Loading branch information
benoitc committed Mar 22, 2016
2 parents 31fd844 + 1ccebab commit 7be2b8d
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions gunicorn/workers/base.py
Expand Up @@ -5,12 +5,12 @@

from datetime import datetime
import os
from random import randint
import signal
from ssl import SSLError
import sys
import time
import traceback
from random import randint


from gunicorn import util
from gunicorn.workers.workertmp import WorkerTmp
Expand Down Expand Up @@ -188,7 +188,8 @@ def handle_error(self, req, client, addr, exc):
if isinstance(exc, (InvalidRequestLine, InvalidRequestMethod,
InvalidHTTPVersion, InvalidHeader, InvalidHeaderName,
LimitRequestLine, LimitRequestHeaders,
InvalidProxyLine, ForbiddenProxyRequest)):
InvalidProxyLine, ForbiddenProxyRequest,
SSLError)):

status_int = 400
reason = "Bad Request"
Expand All @@ -213,12 +214,16 @@ def handle_error(self, req, client, addr, exc):
reason = "Forbidden"
mesg = "Request forbidden"
status_int = 403
elif isinstance(exc, SSLError):
reason = "Forbidden"
mesg = "'%s'" % str(exc)
status_int = 403

msg = "Invalid request from ip={ip}: {error}"
self.log.debug(msg.format(ip=addr[0], error=str(exc)))
else:
self.log.exception("Error handling request %s", req.uri)

if hasattr(req, "uri"):
self.log.exception("Error handling request %s", req.uri)
status_int = 500
reason = "Internal Server Error"
mesg = ""
Expand Down

0 comments on commit 7be2b8d

Please sign in to comment.