Haskell HTTP request analysis

Which library should I use to parse HTTP requests from a socket stream? I wish I could give a lazy ByteString that can contain partial or multiple HTTP requests.

I'm also interested in something similar for responding to HTTP requests (pass it a response object and get a lazy ByteString to write to the socket)

Edited to add additional information : This interface would be ideal, but, of course, was not required:

ByteString {- the initial buffer -} -> (Maybe Request, ByteString {- remaining buffer -})

In the case of a partial request, the Maybe request does not matter, and the ByteString matches the input.

Thank: -)

+3
source share
3 answers
0

, . Conduit, Pipes ( , ), Iteratee, enumerator, iterIO . , , .

Conduit hackage.haskell.org http-conduit . HTTP-, .

import Data.Conduit.Binary (sinkFile)
import Network.HTTP.Conduit
import qualified Data.Conduit as C

main :: IO ()
main = do
     request <- parseUrl "http://google.com/"
     withManager $ \manager -> do
         Response _ _ _ src <- http request manager
         src C.$$+- sinkFile "google.html"
+1

Pipes have a different strategy than cables by function. Conduit combines all of its functions together, while Pipes prefers to pack them separately.

pipes-bytestring is the package I think you were looking for.

It can be installed by doing:

cabal install pipes-bytestring

To find other pipe packages that you can run:

cabal list pipes

or you can also do a hackage search

0
source

All Articles