aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2017-05-13 23:45:56 +0300
committerIgor Pashev <pashev.igor@gmail.com>2017-05-13 23:45:56 +0300
commit41133e1f2e83fff0dea8a5a1ce1ea53b2d9aa2d8 (patch)
tree15d59c0f8c6e9632341ac6606105e87d55b1edb9
parent850e5cc2d4ef96a2dd2a43c9b8d4c1355eb7a148 (diff)
downloadsproxy2-41133e1f2e83fff0dea8a5a1ce1ea53b2d9aa2d8.tar.gz
Respond with 502 on every backend exception
From RFC 7231: 6.6.3. 502 Bad Gateway The 502 (Bad Gateway) status code indicates that the server, while acting as a gateway or proxy, received an invalid response from an inbound server it accessed while attempting to fulfill the request.
-rw-r--r--src/Sproxy/Application.hs8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/Sproxy/Application.hs b/src/Sproxy/Application.hs
index 5de9474..3d6598f 100644
--- a/src/Sproxy/Application.hs
+++ b/src/Sproxy/Application.hs
@@ -30,8 +30,8 @@ import Network.HTTP.Conduit (requestBodySourceChunkedIO, requestBodySourceIO)
import Network.HTTP.Types (RequestHeaders, ResponseHeaders, methodGet, methodPost)
import Network.HTTP.Types.Header ( hConnection,
hContentLength, hContentType, hCookie, hLocation, hTransferEncoding )
-import Network.HTTP.Types.Status ( Status(..), badRequest400, forbidden403, found302,
- internalServerError500, methodNotAllowed405, movedPermanently301,
+import Network.HTTP.Types.Status ( Status(..), badGateway502, badRequest400, forbidden403,
+ found302, internalServerError500, methodNotAllowed405, movedPermanently301,
networkAuthenticationRequired511, notFound404, ok200, seeOther303, temporaryRedirect307 )
import Network.Socket (NameInfoFlag(NI_NUMERICHOST), getNameInfo)
import Network.Wai.Conduit (sourceRequestBody, responseSource)
@@ -383,12 +383,16 @@ notFound msg req resp = do
logException :: W.Middleware
logException app req resp =
catches (app req resp) [
+ Handler badGateway,
Handler internalError
]
where
internalError :: SomeException -> IO W.ResponseReceived
internalError = response internalServerError500
+ badGateway :: BE.HttpException -> IO W.ResponseReceived
+ badGateway = response badGateway502
+
response :: Exception e => Status -> e -> IO W.ResponseReceived
response st e = do
Log.error $ show (statusCode st) ++ " " ++ unpack (statusMessage st)