~alcinnz/hurl

ref: e9e75cebf9d684a1552bcbe11e8de3f274424433 hurl/Main2.hs -rw-r--r-- 980 bytes
e9e75ceb — Adrian Cochrane Release HURL v2.3.0.1 1 year, 8 months ago
                                                                                
12c81bf0 Adrian Cochrane
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
{-# LANGUAGE OverloadedStrings #-}
module Main where

import Network.URI.Fetch
-- Input parsing
import System.Environment (getArgs)
import Network.URI (parseURI, nullURI)
import Data.Maybe (fromJust)
-- Where to save files
import System.Directory (getCurrentDirectory)
import qualified Data.ByteString.Char8 as C8

main :: IO ()
main = do
    url:encoding:args <- getArgs
    let url' = fromJust $ parseURI url
    putStrLn encoding
    session <- newSession
    dir <- getCurrentDirectory

    resp <- submitURL' session ["*/*"] url' "POST" (C8.pack encoding) $map parseArg args
    res <- saveDownload nullURI dir resp
    putStrLn $ show res

parseArg ('-':arg) | (key, '=':value) <- break (== '=') arg = (key, Left value)
    | otherwise = (arg, Left "")
parseArg ('+':arg) | (key, '=':value) <- break (== '=') arg = (key, Right value)
    | otherwise = (arg, Left "")
parseArg arg | (key, '=':value) <- break (== '=') arg = (key, Left value)
    | otherwise = (arg, Left "")