on master help sign in
Include charset= in Warp-generated responses
commit1daa65863367251d965be36e5fb388d54681cb0b authorMichael Snoyman <michael@snoyman.com> dateWed 2 Apr 2014, 10:37 (13 years ago) parent57fd84e
3 files changed+6−5
warp/Network/Wai/Handler/Warp/Response.hs+1−1 warp/Network/Wai/Handler/Warp/Settings.hs+4−3 warp/warp.cabal+1−1
warp/Network/Wai/Handler/Warp/Response.hs+1−1
@@ -215,7 +215,7 @@ sendRsp conn ver s0 hs0 restore (RspFile path mPart mRange hook) = restore $ do
215215 where
216216 hs = addAcceptRanges hs0
217217 s2 = H.status404
218− hs2 = replaceHeader H.hContentType "text/plain" hs0
218+ hs2 = replaceHeader H.hContentType "text/plain; charset=utf-8" hs0
219219 body = fromByteString "File not found"
220220
221221----------------------------------------------------------------
warp/Network/Wai/Handler/Warp/Settings.hs+4−3
@@ -8,7 +8,6 @@ import Control.Monad (when)
88import qualified Data.ByteString as S
99import qualified Data.Text as T
1010import qualified Data.Text.IO as TIO
11−import qualified Data.ByteString.Lazy.Char8 as L8
1211import Data.Conduit
1312import Data.Conduit.Network (HostPreference)
1413import GHC.IO.Exception (IOErrorType(..))
@@ -19,6 +18,8 @@ import Network.Wai.Handler.Warp.Timeout
1918import Network.Wai.Handler.Warp.Types
2019import System.IO (stderr)
2120import System.IO.Error (ioeGetErrorType)
21+import qualified Data.Text.Lazy as TL
22+import qualified Data.Text.Lazy.Encoding as TLE
2223
2324-- | Various Warp server settings. This is purposely kept as an abstract data
2425-- type so that new settings can be added without breaking backwards
@@ -98,11 +99,11 @@ defaultExceptionHandler _ e =
9899 $ TIO.hPutStrLn stderr $ T.pack $ show e
99100
100101defaultExceptionResponse :: SomeException -> Response
101−defaultExceptionResponse _ = responseLBS H.internalServerError500 [(H.hContentType, "text/plain")] "Something went wrong"
102+defaultExceptionResponse _ = responseLBS H.internalServerError500 [(H.hContentType, "text/plain; charset=utf-8")] "Something went wrong"
102103
103104-- | Default implementation of 'settingsOnExceptionResponse' for the debugging purpose. 500, text/plain, a showed exception.
104105exceptionResponseForDebug :: SomeException -> Response
105−exceptionResponseForDebug e = responseLBS H.internalServerError500 [(H.hContentType, "text/plain")] (L8.pack $ "Exception: " ++ show e)
106+exceptionResponseForDebug e = responseLBS H.internalServerError500 [(H.hContentType, "text/plain; charset=utf-8")] (TLE.encodeUtf8 $ TL.pack $ "Exception: " ++ show e)
106107
107108{-# DEPRECATED settingsPort "Use setPort instead" #-}
108109{-# DEPRECATED settingsHost "Use setHost instead" #-}
warp/warp.cabal+1−1
@@ -1,5 +1,5 @@
11Name: warp
2−Version: 2.1.3.3
2+Version: 2.1.3.4
33Synopsis: A fast, light-weight web server for WAI applications.
44License: MIT
55License-file: LICENSE