Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Destrictify some less often used fields in Request, and remove unused…

… rqSnapletPath altogether.
  • Loading branch information...
commit bdcc3c9b884efa8d0c884efe4c8ea2ee823d8082 1 parent 0ed5205
@gregorycollins gregorycollins authored
View
44 src/Snap/Internal/Http/Types.hs
@@ -186,30 +186,30 @@ newtype SomeEnumerator = SomeEnumerator (forall a . Enumerator ByteString IO a)
data Request = Request
{ -- | The server name of the request, as it came in from the request's
-- @Host:@ header.
- rqServerName :: !ByteString
+ rqServerName :: ByteString
-- | Returns the port number the HTTP server is listening on.
, rqServerPort :: !Int
-- | The remote IP address.
- , rqRemoteAddr :: !ByteString
+ , rqRemoteAddr :: ByteString
-- | The remote TCP port number.
- , rqRemotePort :: !Int
+ , rqRemotePort :: Int
-- | The local IP address for this request.
- , rqLocalAddr :: !ByteString
+ , rqLocalAddr :: ByteString
-- | Returns the port number the HTTP server is listening on.
- , rqLocalPort :: !Int
+ , rqLocalPort :: Int
-- | Returns the HTTP server's idea of its local hostname.
- , rqLocalHostname :: !ByteString
+ , rqLocalHostname :: ByteString
-- | Returns @True@ if this is an @HTTPS@ session.
- , rqIsSecure :: !Bool
+ , rqIsSecure :: Bool
, rqHeaders :: Headers
- , rqBody :: IORef SomeEnumerator
+ , rqBody :: !(IORef SomeEnumerator)
-- | Returns the @Content-Length@ of the HTTP request body.
, rqContentLength :: !(Maybe Int)
@@ -218,38 +218,26 @@ data Request = Request
, rqMethod :: !Method
-- | Returns the HTTP version used by the client.
- , rqVersion :: !HttpVersion
+ , rqVersion :: HttpVersion
-- | Returns a list of the cookies that came in from the HTTP request
-- headers.
, rqCookies :: [Cookie]
-
- -- | We'll be doing web components (or \"snaplets\") for version 0.2.
- -- The \"snaplet path\" refers to the place on the URL where your
- -- containing snaplet is hung. The value of 'rqSnapletPath' is either
- -- @\"\"@ (at the top-level context) or is a path beginning with a
- -- slash, but not ending with one.
+ -- | Handlers can be hung on a @URI@ \"entry point\"; this is called the
+ -- \"context path\". If a handler is hung on the context path
+ -- @\"\/foo\/\"@, and you request @\"\/foo\/bar\"@, the value of
+ -- 'rqPathInfo' will be @\"bar\"@.
--
- -- An identity is that:
+ -- The following identity holds:
--
- -- > rqURI r == S.concat [ rqSnapletPath r
- -- > , rqContextPath r
+ -- > rqURI r == S.concat [ rqContextPath r
-- > , rqPathInfo r
-- > , let q = rqQueryString r
-- > in if S.null q
-- > then ""
-- > else S.append "?" q
-- > ]
- --
- -- note that until we introduce snaplets in v0.2, 'rqSnapletPath' will
- -- be \"\"
- , rqSnapletPath :: !ByteString
-
- -- | Handlers can be hung on a @URI@ \"entry point\"; this is called the
- -- \"context path\". If a handler is hung on the context path
- -- @\"\/foo\/\"@, and you request @\"\/foo\/bar\"@, the value of
- -- 'rqPathInfo' will be @\"bar\"@.
, rqPathInfo :: !ByteString
-- | The \"context path\" of the request; catenating 'rqContextPath',
@@ -300,7 +288,6 @@ instance Show Request where
, cookies
, pathinfo
, contextpath
- , snapletpath
, uri
, params
]
@@ -341,7 +328,6 @@ instance Show Request where
]
pathinfo = concat [ "pathinfo: ", toStr $ rqPathInfo r ]
contextpath = concat [ "contextpath: ", toStr $ rqContextPath r ]
- snapletpath = concat [ "snapletpath: ", toStr $ rqSnapletPath r ]
uri = concat [ "URI: ", toStr $ rqURI r ]
params' = " " ++
(concat $ intersperse "\n " $
View
11 src/Snap/Internal/Test/RequestBuilder.hs
@@ -87,7 +87,6 @@ mkDefaultRequest = do
(1,1)
[]
""
- ""
"/"
"/"
""
@@ -98,6 +97,10 @@ mkDefaultRequest = do
------------------------------------------------------------------------------
-- | Runs a 'RequestBuilder', producing the desired 'Request'.
+--
+-- N.B. /please/ don't use the request you get here in a real Snap application;
+-- things will probably break. Don't say you weren't warned :-)
+--
buildRequest :: MonadIO m => RequestBuilder m () -> m Request
buildRequest mm = do
let (RequestBuilder m) = (mm >> fixup)
@@ -364,8 +367,7 @@ encodeMultipart kvps = do
fixupURI :: Monad m => RequestBuilder m ()
fixupURI = do
rq <- rGet
- let u = S.concat [ rqSnapletPath rq
- , rqContextPath rq
+ let u = S.concat [ rqContextPath rq
, rqPathInfo rq
, let q = rqQueryString rq
in if S.null q
@@ -432,8 +434,7 @@ setHttpVersion v = rModify $ \rq -> rq { rqVersion = v }
-- Note that 'rqContextPath' is never set by any 'RequestBuilder' function.
setRequestPath :: Monad m => ByteString -> RequestBuilder m ()
setRequestPath p0 = do
- rModify $ \rq -> rq { rqSnapletPath = ""
- , rqContextPath = "/"
+ rModify $ \rq -> rq { rqContextPath = "/"
, rqPathInfo = p }
fixupURI
View
8 test/suite/Snap/Core/Tests.hs
@@ -98,7 +98,7 @@ mkRequest uri = do
enum <- newIORef $ SomeEnumerator returnI
return $! Request "foo" 80 "127.0.0.1" 999 "foo" 1000 "foo" False H.empty
- enum Nothing GET (1,1) [] "" uri "/"
+ enum Nothing GET (1,1) [] uri "/"
(S.concat ["/",uri]) "" Map.empty Map.empty Map.empty
@@ -110,7 +110,7 @@ mkRequestQuery uri k v = do
let q = S.concat [k,"=", S.concat v]
return $ Request "foo" 80 "foo" 999 "foo" 1000 "foo" False H.empty
- enum Nothing GET (1,1) [] "" uri "/"
+ enum Nothing GET (1,1) [] uri "/"
(S.concat ["/",uri,"?",q]) q mp mp Map.empty
@@ -119,7 +119,7 @@ mkZomgRq = do
enum <- newIORef $ SomeEnumerator returnI
return $ Request "foo" 80 "127.0.0.1" 999 "foo" 1000 "foo" False H.empty
- enum Nothing GET (1,1) [] "" "/" "/" "/" ""
+ enum Nothing GET (1,1) [] "/" "/" "/" ""
Map.empty Map.empty Map.empty
@@ -139,7 +139,7 @@ mkRqWithEnum :: (forall a . Enumerator ByteString IO a) -> IO Request
mkRqWithEnum e = do
enum <- newIORef $ SomeEnumerator e
return $ Request "foo" 80 "foo" 999 "foo" 1000 "foo" False H.empty
- enum Nothing GET (1,1) [] "" "/" "/" "/" ""
+ enum Nothing GET (1,1) [] "/" "/" "/" ""
Map.empty Map.empty Map.empty
testCatchIO :: Test
View
2  test/suite/Snap/Internal/Http/Types/Tests.hs
@@ -37,7 +37,7 @@ mkRq :: IO Request
mkRq = do
enum <- newIORef (SomeEnumerator $ enumBS "")
return $ Request "foo" 80 "foo" 999 "foo" 1000 "foo" False H.empty
- enum Nothing GET (1,1) [] "" "/" "/" "/" ""
+ enum Nothing GET (1,1) [] "/" "/" "/" ""
Map.empty Map.empty Map.empty
View
2  test/suite/Snap/Util/FileServe/Tests.hs
@@ -151,7 +151,7 @@ mkRequest :: ByteString -> IO Request
mkRequest uri = do
enum <- newIORef $ SomeEnumerator returnI
return $ Request "foo" 80 "foo" 999 "foo" 1000 "foo" False H.empty
- enum Nothing GET (1,1) [] "" pathPart "/"
+ enum Nothing GET (1,1) [] pathPart "/"
(S.concat ["/",uri]) queryPart
Map.empty Map.empty Map.empty
View
8 test/suite/Snap/Util/FileUploads/Tests.hs
@@ -333,7 +333,7 @@ testDisconnectionCleanup = testCase "fileUploads/disconnectionCleanup" $ do
dirs <- liftM (filter (\x -> x /= "." && x /= "..")) $
getDirectoryContents tmpdir
assertEqual "files should be cleaned up" [] dirs
-
+
tmpdir = "tempdirC"
hndl = handleFileUploads tmpdir
@@ -342,7 +342,7 @@ testDisconnectionCleanup = testCase "fileUploads/disconnectionCleanup" $ do
hndl'
hndl' _ = return ()
-
+
------------------------------------------------------------------------------
harness :: FilePath -> Snap a -> ByteString -> IO ()
@@ -372,7 +372,7 @@ mkRequest body = do
]
return $ Request "foo" 80 "foo" 999 "foo" 1000 "foo" False hdrs
- enum Nothing POST (1,1) [] "" "/" "/"
+ enum Nothing POST (1,1) [] "/" "/"
"/" "" Map.empty Map.empty Map.empty
@@ -387,7 +387,7 @@ mkDamagedRequest body = do
]
return $ Request "foo" 80 "foo" 999 "foo" 1000 "foo" False hdrs
- enum Nothing POST (1,1) [] "" "/" "/"
+ enum Nothing POST (1,1) [] "/" "/"
"/" "" Map.empty Map.empty Map.empty
where
enum = enumBS (S.take (S.length body - 1) body) >==> dieNow
View
12 test/suite/Snap/Util/GZip/Tests.hs
@@ -86,7 +86,7 @@ mkNoHeaders = do
enum <- newIORef $ SomeEnumerator returnI
return $ Request "foo" 80 "foo" 999 "foo" 1000 "foo" False emptyHdrs
- enum Nothing GET (1,1) [] "" "/" "/" "/" ""
+ enum Nothing GET (1,1) [] "/" "/" "/" ""
Map.empty Map.empty Map.empty
@@ -95,7 +95,7 @@ mkGzipRq = do
enum <- newIORef $ SomeEnumerator returnI
return $ Request "foo" 80 "foo" 999 "foo" 1000 "foo" False gzipHdrs
- enum Nothing GET (1,1) [] "" "/" "/" "/" ""
+ enum Nothing GET (1,1) [] "/" "/" "/" ""
Map.empty Map.empty Map.empty
mkXGzipRq :: IO Request
@@ -103,7 +103,7 @@ mkXGzipRq = do
enum <- newIORef $ SomeEnumerator returnI
return $ Request "foo" 80 "foo" 999 "foo" 1000 "foo" False xGzipHdrs
- enum Nothing GET (1,1) [] "" "/" "/" "/" ""
+ enum Nothing GET (1,1) [] "/" "/" "/" ""
Map.empty Map.empty Map.empty
@@ -114,7 +114,7 @@ mkCompressRq = do
enum <- newIORef $ SomeEnumerator returnI
return $ Request "foo" 80 "foo" 999 "foo" 1000 "foo" False compressHdrs
- enum Nothing GET (1,1) [] "" "/" "/" "/" ""
+ enum Nothing GET (1,1) [] "/" "/" "/" ""
Map.empty Map.empty Map.empty
@@ -123,7 +123,7 @@ mkXCompressRq = do
enum <- newIORef $ SomeEnumerator returnI
return $ Request "foo" 80 "foo" 999 "foo" 1000 "foo" False xCompressHdrs
- enum Nothing GET (1,1) [] "" "/" "/" "/" ""
+ enum Nothing GET (1,1) [] "/" "/" "/" ""
Map.empty Map.empty Map.empty
@@ -134,7 +134,7 @@ mkBadRq = do
enum <- newIORef $ SomeEnumerator returnI
return $ Request "foo" 80 "foo" 999 "foo" 1000 "foo" False badHdrs
- enum Nothing GET (1,1) [] "" "/" "/" "/" ""
+ enum Nothing GET (1,1) [] "/" "/" "/" ""
Map.empty Map.empty Map.empty
Please sign in to comment.
Something went wrong with that request. Please try again.