Skip to content

Instantly share code, notes, and snippets.

@pheaver
Created December 12, 2010 21:05
Show Gist options
  • Save pheaver/738326 to your computer and use it in GitHub Desktop.
Save pheaver/738326 to your computer and use it in GitHub Desktop.
-- {-# OPTIONS_GHC -Wall #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Data.ByteString ( ByteString )
import qualified Data.ByteString.Char8 as BS
import Data.Enumerator
import Data.Monoid
import Snap.Http.Server
import Snap.Http.Server.Config
import Snap.Iteratee
import Snap.Loader.Static (loadSnapTH)
import Snap.Types
--------------------------------------------------------------------------------
load :: IO ()
load = return ()
cleanup :: () -> IO ()
cleanup () = return ()
runIt :: () -> Snap ()
runIt () = do
xs <- runRequestBody iter
mapM_ writeBS xs
return ()
iter :: Iteratee ByteString IO [ByteString]
iter = joinI $
(\i -> takeNoMoreThan 10 i) $$
consume
main :: IO ()
main = do
let conf = completeConfig $ addListen (ListenHttp "0.0.0.0" 9000) mempty
(_, snap) <- $(loadSnapTH 'load 'cleanup 'runIt)
httpServe conf snap
--------------------------------------------------------------------------------
<html>
test<br>
<form target="foo" action='http://localhost:9000/' method='POST' enctype='multipart/form-data'>
<input name="a" value="default a" type="text">
<input name="b" value="default b" type="text">
<input type="checkbox" name="dry-run" value="yes">Dry run
<input name="file" type="file">
<input type="submit">
</form>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment