on master help sign in
settingsNoParsePath
42a1391Michael Snoyman
warp/Network/Wai/Handler/Warp.hs+1
@@ -36,6 +36,7 @@ module Network.Wai.Handler.Warp (
36 , settingsManager
36 , settingsManager
37 , settingsFdCacheDuration
37 , settingsFdCacheDuration
38 , settingsBeforeMainLoop
38 , settingsBeforeMainLoop
39+ , settingsNoParsePath
39 -- * Data types
40 -- * Data types
40 , HostPreference (..)
41 , HostPreference (..)
41 , Port
42 , Port
warp/Network/Wai/Handler/Warp/Request.hs+6−4
@@ -26,6 +26,7 @@ import Network.Wai.Handler.Warp.Conduit
26import Network.Wai.Handler.Warp.Header
26import Network.Wai.Handler.Warp.Header
27import Network.Wai.Handler.Warp.ReadInt
27import Network.Wai.Handler.Warp.ReadInt
28import Network.Wai.Handler.Warp.RequestHeader
28import Network.Wai.Handler.Warp.RequestHeader
29+import Network.Wai.Handler.Warp.Settings (Settings, settingsNoParsePath)
29import qualified Network.Wai.Handler.Warp.Timeout as Timeout
30import qualified Network.Wai.Handler.Warp.Timeout as Timeout
30import Network.Wai.Handler.Warp.Types
31import Network.Wai.Handler.Warp.Types
31import Network.Wai.Internal
32import Network.Wai.Internal
@@ -41,7 +42,8 @@ maxTotalHeaderLength = 50 * 1024
41
42
42-- | Receiving a HTTP request from 'Connection' and parsing its header
43-- | Receiving a HTTP request from 'Connection' and parsing its header
43-- to create 'Request'.
44-- to create 'Request'.
45+recvRequest :: Settings
44−recvRequest :: Connection
46+ -> Connection
45 -> InternalInfo
47 -> InternalInfo
46 -> SockAddr -- ^ Peer's address.
48 -> SockAddr -- ^ Peer's address.
47 -> Source IO ByteString -- ^ Where HTTP request comes from.
49 -> Source IO ByteString -- ^ Where HTTP request comes from.
@@ -52,9 +54,9 @@ recvRequest :: Connection
52 -- 'IndexedHeader' of HTTP request for internal use, and
54 -- 'IndexedHeader' of HTTP request for internal use, and
53 -- leftover source (i.e. body and other HTTP reqeusts in HTTP pipelining).
55 -- leftover source (i.e. body and other HTTP reqeusts in HTTP pipelining).
54
56
55−recvRequest conn ii addr src0 = do
57+recvRequest settings conn ii addr src0 = do
56 (src, hdrlines) <- src0 $$+ headerLines
58 (src, hdrlines) <- src0 $$+ headerLines
57− (method, path, query, httpversion, hdr) <- parseHeaderLines hdrlines
59+ (method, unparsedPath, path, query, httpversion, hdr) <- parseHeaderLines hdrlines
58 let idxhdr = indexRequestHeader hdr
60 let idxhdr = indexRequestHeader hdr
59 expect = idxhdr ! idxExpect
61 expect = idxhdr ! idxExpect
60 cl = idxhdr ! idxContentLength
62 cl = idxhdr ! idxContentLength
@@ -65,7 +67,7 @@ recvRequest conn ii addr src0 = do
65 requestMethod = method
67 requestMethod = method
66 , httpVersion = httpversion
68 , httpVersion = httpversion
67 , pathInfo = H.decodePathSegments path
69 , pathInfo = H.decodePathSegments path
68− , rawPathInfo = path
70+ , rawPathInfo = if settingsNoParsePath settings then unparsedPath else path
69 , rawQueryString = query
71 , rawQueryString = query
70 , queryString = H.parseQuery query
72 , queryString = H.parseQuery query
71 , requestHeaders = hdr
73 , requestHeaders = hdr
warp/Network/Wai/Handler/Warp/RequestHeader.hs+2−1
@@ -27,6 +27,7 @@ import qualified Network.HTTP.Types.Header as HH
27parseHeaderLines :: [ByteString]
27parseHeaderLines :: [ByteString]
28 -> IO (H.Method
28 -> IO (H.Method
29 ,ByteString -- Path
29 ,ByteString -- Path
30+ ,ByteString -- Path, parsed
30 ,ByteString -- Query
31 ,ByteString -- Query
31 ,H.HttpVersion
32 ,H.HttpVersion
32 ,H.RequestHeaders
33 ,H.RequestHeaders
@@ -36,7 +37,7 @@ parseHeaderLines (firstLine:otherLines) = do
36 (method, path', query, httpversion) <- parseRequestLine firstLine
37 (method, path', query, httpversion) <- parseRequestLine firstLine
37 let path = parsePath path'
38 let path = parsePath path'
38 hdr = map parseHeader otherLines
39 hdr = map parseHeader otherLines
39− return (method, path, query, httpversion, hdr)
40+ return (method, path', path, query, httpversion, hdr)
40
41
41----------------------------------------------------------------
42----------------------------------------------------------------
42
43
warp/Network/Wai/Handler/Warp/Run.hs+1−1
@@ -228,7 +228,7 @@ serveConnection conn ii addr settings app =
228 internalError = responseLBS H.internalServerError500 [(H.hContentType, "text/plain")] "Something went wrong"
228 internalError = responseLBS H.internalServerError500 [(H.hContentType, "text/plain")] "Something went wrong"
229
229
230 recvSendLoop fromClient = do
230 recvSendLoop fromClient = do
231− (req, idxhdr, getSource) <- recvRequest conn ii addr fromClient
231+ (req, idxhdr, getSource) <- recvRequest settings conn ii addr fromClient
232 case settingsIntercept settings req of
232 case settingsIntercept settings req of
233 Nothing -> do
233 Nothing -> do
234 -- Let the application run for as long as it wants
234 -- Let the application run for as long as it wants
warp/Network/Wai/Handler/Warp/Settings.hs+9
@@ -35,6 +35,14 @@ data Settings = Settings
35 -- Default: do nothing.
35 -- Default: do nothing.
36 --
36 --
37 -- Since 1.3.6
37 -- Since 1.3.6
38+ , settingsNoParsePath :: Bool
39+ -- ^ Perform no parsing on the rawPathInfo.
40+ --
41+ -- This is useful for writing HTTP proxies.
42+ --
43+ -- Default: False
44+ --
45+ -- Since 2.0.3
38 }
46 }
39
47
40-- | The default settings for the Warp server. See the individual settings for
48-- | The default settings for the Warp server. See the individual settings for
@@ -51,6 +59,7 @@ defaultSettings = Settings
51 , settingsManager = Nothing
59 , settingsManager = Nothing
52 , settingsFdCacheDuration = 10
60 , settingsFdCacheDuration = 10
53 , settingsBeforeMainLoop = return ()
61 , settingsBeforeMainLoop = return ()
62+ , settingsNoParsePath = False
54 }
63 }
55
64
56defaultExceptionHandler :: Maybe Request -> SomeException -> IO ()
65defaultExceptionHandler :: Maybe Request -> SomeException -> IO ()
warp/warp.cabal+1−1
@@ -1,5 +1,5 @@
1Name: warp
1Name: warp
2−Version: 2.0.2.1
2+Version: 2.0.3
3Synopsis: A fast, light-weight web server for WAI applications.
3Synopsis: A fast, light-weight web server for WAI applications.
4License: MIT
4License: MIT
5License-file: LICENSE
5License-file: LICENSE