http-wget (empty) → 0.0.0
raw patch · 4 files changed
+120/−0 lines, 4 filesdep +basedep +processsetup-changed
Dependencies added: base, process
Files
- LICENSE +25/−0
- Network/HTTP/Wget.hs +66/−0
- Setup.lhs +7/−0
- http-wget.cabal +22/−0
+ LICENSE view
@@ -0,0 +1,25 @@+The following license covers this documentation, and the source code, except+where otherwise indicated.++Copyright 2008, Michael Snoyman. All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++* Redistributions of source code must retain the above copyright notice, this+ list of conditions and the following disclaimer.++* Redistributions in binary form must reproduce the above copyright notice,+ this list of conditions and the following disclaimer in the documentation+ and/or other materials provided with the distribution.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS "AS IS" AND ANY EXPRESS OR+IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO+EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT+NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,+OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE+OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Network/HTTP/Wget.hs view
@@ -0,0 +1,66 @@+---------------------------------------------------------+-- |+-- Module : Network.HTTP.Wget+-- Copyright : Michael Snoyman+-- License : BSD3+--+-- Maintainer : Michael Snoyman <michael@snoyman.com>+-- Stability : Stable+-- Portability : portable+--+-- Provide a simple HTTP client interface by wrapping the wget command line tool.+--+---------------------------------------------------------+module Network.HTTP.Wget+ ( wget+ ) where++import System.Process+import System.Exit+import System.IO+import Numeric (showHex)+import Data.List (intercalate)++-- | Get a response from the given URL with the given parameters.+wget :: Monad m+ => String -- ^ The URL.+ -> [(String, String)] -- ^ Get parameters.+ -> [(String, String)] -- ^ Post parameters. If empty, this will be a get request.+ -> IO (m String) -- ^ The response body.+wget url get post = do+ let getSepChar :: Char+ getSepChar = if '?' `elem` url then '&' else '?'+ get' :: String+ get' = if null get then "" else getSepChar : urlEncodePairs get+ post' :: [String]+ post' = if null post+ then []+ else ["--post-data", urlEncodePairs post]+ (Nothing, Just hout, Just herr, phandle) <- createProcess $ (proc "wget"+ ((url ++ get') : post' ++ ["-O", "-"])+ ) { std_out = CreatePipe, std_err = CreatePipe }+ exitCode <- waitForProcess phandle+ case exitCode of+ ExitSuccess -> hGetContents hout >>= return . return+ _ -> hGetContents herr >>= return . fail++urlEncodePairs :: [(String, String)] -> String+urlEncodePairs = intercalate "&" . map urlEncodePair++urlEncodePair :: (String, String) -> String+urlEncodePair (x, y) = urlEncode x ++ '=' : urlEncode y++urlEncode :: String -> String+urlEncode = concatMap urlEncodeChar++urlEncodeChar :: Char -> String+urlEncodeChar x+ | safeChar (fromEnum x) = return x+ | otherwise = '%' : showHex (fromEnum x) ""++safeChar :: Int -> Bool+safeChar x+ | x >= fromEnum 'a' && x <= fromEnum 'z' = True+ | x >= fromEnum 'A' && x <= fromEnum 'Z' = True+ | x >= fromEnum '0' && x <= fromEnum '9' = True+ | otherwise = False
+ Setup.lhs view
@@ -0,0 +1,7 @@+#!/usr/bin/env runhaskell++> module Main where+> import Distribution.Simple++> main :: IO ()+> main = defaultMain
+ http-wget.cabal view
@@ -0,0 +1,22 @@+name: http-wget+version: 0.0.0+license: BSD3+license-file: LICENSE+author: Michael Snoyman <michael@snoyman.com>+maintainer: Michael Snoyman <michael@snoyman.com>+synopsis: Provide a simple HTTP client interface by wrapping the wget+ command line tool.+description: This provides the simplest interface I could imagine to+ making HTTP requests. It supports GET and POST parameters.+ Since it simply wraps the WGET program, there are no+ library dependencies, and it automatically gets HTTPS.+category: Network+stability: stable+cabal-version: >= 1.2+build-type: Simple+homepage: http://github.com/snoyberg/http-wget/tree/master++library+ build-depends: base, process+ exposed-modules: Network.HTTP.Wget+ ghc-options: -Wall