snoyberg/http-enumerator — Issue #48: http mangles the query string too much
Author: erikd
Created: 2011-12-23 00:00:26+00:00
State: open

I have a URL that's getting mangled by parseUrl and renderQuery.

If I write a program like:

import Network.HTTP.Enumerator
import qualified Data.ByteString.Lazy as L
import Network (withSocketsDo)

url = "http://www.mega-nerd.com/cgi-bin/Count.cgi?ft=6|frgb=55;55;55|tr=0|trgb=0;0;0|wxh=15;20|md=7|dd=B|st=1|sh=1|df=libsndfile.dat"

main = withSocketsDo $ simpleHttp url >>= L.putStr

and run it as:

runhaskell simpleHttp.hs > a.gif

I get a different result than if I had done:

wget $url -O b.gif

Basically the problem is that if you just consider the query string part, the parseUrl ---> renderQuery path is not the identity function.

The query:

?ft=6|frgb=55;55;55|tr=0|trgb=0;0;0|wxh=15;20|md=7|dd=B|st=1|sh=1|df=libsndfile.dat

becomes:

?ft=6%7Cfrgb%3D55&55&55%7Ctr=0%7Ctrgb%3D0&0&0%7Cwxh=15&20%7Cmd=7%7Cdd%3DB%7Cst%3D1%7Csh%3D1%7Cdf%3Dlibsndfile.dat

You could of course say that the CGI script should handle a URI encoded string and I would agree, but I also don't think http-enumerator should be mangling it as much as it does. In fact, I don't http-enumerator should be parsing it into a Query at all, but should leave it as a ByteString (of course in Warp its a completely different matter).

If you agree, I can submit a pull request that fixes this. Obviously this will require a significant version bump but I'll leave that to you.

Cheers,
Erik