Document the 'Snap.Test' module. #205

Merged
merged 2 commits into from Jul 29, 2014

3 participants

@23Skidoo

No description provided.

@23Skidoo 23Skidoo changed the title from Document the 'Snap.Test' module to Document the 'Snap.Test' module. Jul 16, 2014
@dbp

Is f8b6849 supposed to be included with this?

@23Skidoo

@dbp Yes. I needed it to document setSecure.

@gregorycollins gregorycollins and 1 other commented on an outdated diff Jul 16, 2014
src/Snap/Internal/Test/RequestBuilder.hs
@@ -111,6 +111,37 @@ mkDefaultRequest = do
-- 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 :-)
--
+--
+-- Example:
+--
+-- @
+-- ghci> :set -XOverloadedStrings
+-- ghci> import qualified "Data.Map" as M
+-- ghci> 'buildRequest' $ 'get' \"\/foo\/bar\" M.empty
+-- Request <
@gregorycollins
Snap Framework member

Yuck. What do you think about improving the output of the Show instance while you are doing this? I would prefer that to happen rather than this regurgitation ever making it into the comments.

The status line and headers can be printed much more compactly. This request would look better as something like:

GET /foo/bar HTTP/1.1
host: localhost

sn="localhost" c=127.0.0.1:60000 s=127.0.0.1:8080 ctx=/

Sure, can do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@23Skidoo

@gregorycollins I've updated this pull request.

@gregorycollins gregorycollins and 1 other commented on an outdated diff Jul 17, 2014
src/Snap/Internal/Test/RequestBuilder.hs
@@ -111,6 +111,19 @@ mkDefaultRequest = do
-- 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 :-)
--
+--
+-- Example:
+--
+-- @
+-- ghci> :set -XOverloadedStrings
+-- ghci> import qualified "Data.Map" as M
+-- ghci> 'buildRequest' $ 'get' \"\/foo\/bar\" M.empty
+-- GET \/foo\/bar
+-- host: localhost
+--
+-- sn="localhost" c=127.0.0.1:60000 s=127.0.0.1:8080
+-- ctx=\/ pthinfo=foo\/bar cntntlen=0 ver=(1,1)
@gregorycollins
Snap Framework member

Thanks so much Mikhail, this looks much better already.

A few tweaks:

  • You can move the version to the GET line (i.e. you can render the http status line the same, GET /foo/bar HTTP/1.1)

  • "pthinfo" can be omitted (we maintain this identity:

rqURI r == rqContextPath r <> rqPathInfo r
               <> let q = rqQueryString r
                   in (if S.null q then "" else "?") <> q

so the pathInfo can be deduced from the URI and the context.

  • Change "cntntlen" to "clen", and make Nothing render as "n/a"

All done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@gregorycollins
Snap Framework member

Awesome. Sorry for taking so long to approve, I'm moving house and I've been on holiday.

@gregorycollins gregorycollins merged commit 04c1b18 into snapframework:master Jul 29, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment