ihttp 0.2.1 → 0.2.2
raw patch · 6 files changed
+72/−7 lines, 6 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ Network.IHttp.Request: mkGetRequest :: ByteString -> ByteString -> Request
+ Network.IHttp.Simple: httpRequest :: MonadIO m => HttpConfig -> Handle -> Request -> Iteratee ByteString m Response
+ Network.IHttp.Simple: httpTimeout :: HttpConfig -> Int
- Network.IHttp.Simple: HttpConfig :: Int -> Int -> Int -> HttpConfig
+ Network.IHttp.Simple: HttpConfig :: Int -> Int -> Int -> Int -> HttpConfig
Files
- Network/IHttp/Header.hs +12/−0
- Network/IHttp/Parsers.hs +12/−0
- Network/IHttp/Request.hs +16/−1
- Network/IHttp/Simple.hs +18/−3
- Network/IHttp/Types.hs +11/−1
- ihttp.cabal +3/−2
Network/IHttp/Header.hs view
@@ -31,6 +31,18 @@ import Network.IHttp.Types +-- TODO: Turn a 'HeaderMap' to a record of common headers.++-- commonHeaders :: HeaderMap -> CommonHeaders+-- commonHeaders m =+-- let (ctype, charset) = do+-- typeStr <- M.lookup "CONTENT-TYPE" m++-- CommonHeaders { contentCharsetHeader = undefined,+-- contentLengthHeader = undefined,+-- contentTypeHeader = undefined }++ -- | Enumerate a 'HeaderMap' as a protocol string stream. You can use -- 'Data.Enumerator.Binary.iterHandle' to send it. Note that this -- enumerator never generates continuation lines. It also does not
Network/IHttp/Parsers.hs view
@@ -32,6 +32,18 @@ import Network.IHttp.Types +-- TODO: Parse the content of the *Content-Type* header to MIME type and set+-- of parameters.++-- contentTypeP :: Parser (ByteString, Map ByteString ByteString)+-- contentTypeP =+-- contType <- httpTokenP+-- char '/'+-- subType <- httpTokenP+-- char ';'+-- skipSpace++ -- | Parse an HTTP status code. httpCodeP :: Parser Int
Network/IHttp/Request.hs view
@@ -16,11 +16,15 @@ -- * Enumerators enumRequest,- enumRequestLine+ enumRequestLine,++ -- * Helper functions+ mkGetRequest ) where import qualified Data.ByteString as B+import qualified Data.Map as M import Data.ByteString (ByteString) import Data.Enumerator as E import Data.Enumerator.List as EL@@ -65,6 +69,17 @@ showVersion version, "\r\n" ] where space = B.singleton 32+++-- | Construct a HTTP 1.1 GET request with the given domain (first+-- argument) and URI (second argument).++mkGetRequest :: ByteString -> ByteString -> Request+mkGetRequest domain uri =+ Request { requestHeaders = M.singleton "Host" domain,+ requestMethod = GetMethod,+ requestUri = uri,+ requestVersion = Http1_1 } -- | Get the next full request from a 'netLinesEmpty'-splitted byte
Network/IHttp/Simple.hs view
@@ -14,16 +14,19 @@ -- * Iteratees getRequest,- getResponse+ getResponse,+ httpRequest ) where +import Control.ContStuff import Data.ByteString (ByteString) import Data.Enumerator as E import Data.Enumerator.NetLines import Network.IHttp.Request import Network.IHttp.Response import Network.IHttp.Types+import System.IO -- | HTTP iteratees configuration.@@ -32,7 +35,8 @@ HttpConfig { httpMaxLine :: Int, -- ^ Maximum protocol line length. httpMaxHeaderContent :: Int, -- ^ Maximum header content length.- httpMaxHeaders :: Int -- ^ Maximum number of headers.+ httpMaxHeaders :: Int, -- ^ Maximum number of headers.+ httpTimeout :: Int -- ^ Write timeout in milliseconds. } @@ -43,7 +47,8 @@ defHttpConfig = HttpConfig { httpMaxLine = 1024, httpMaxHeaderContent = 8192,- httpMaxHeaders = 128 }+ httpMaxHeaders = 128,+ httpTimeout = 30000 } -- | Get the next full request from the given raw byte stream.@@ -60,3 +65,13 @@ getResponse cfg = joinI $ netLinesEmpty (httpMaxLine cfg) $$ response (httpMaxHeaderContent cfg) (httpMaxHeaders cfg)+++-- | Send a request to the given output handle and return its response.++httpRequest ::+ MonadIO m =>+ HttpConfig -> Handle -> Request -> Iteratee ByteString m Response+httpRequest cfg h req = do+ tryIO . run_ $ enumRequest req $$ iterHandleTimeout (httpTimeout cfg) h+ getResponse cfg
Network/IHttp/Types.hs view
@@ -23,9 +23,19 @@ where import Control.Exception as Ex-import Data.ByteString (ByteString)+import Data.ByteString.Char8 (ByteString) import Data.Map (Map) import Data.Typeable+++-- TODO: Common HTTP headers with correct types.++-- data CommonHeaders =+-- CommonHeaders {+-- contentCharsetHeader :: Maybe ByteString, -- ^ Document character set.+-- contentLengthHeader :: Maybe Integer, -- ^ Length of document in bytes.+-- contentTypeHeader :: Maybe ByteString -- ^ MIME type of document.+-- } -- | Map of HTTP headers.
ihttp.cabal view
@@ -1,5 +1,5 @@ Name: ihttp-Version: 0.2.1+Version: 0.2.2 Category: Network Synopsis: Incremental HTTP iteratee Maintainer: Ertugrul Söylemez <es@ertes.de>@@ -37,6 +37,7 @@ -- Executable ihttp-test -- Build-depends:--- base >= 4 && <= 5+-- base >= 4 && <= 5,+-- network >= 2.2.1.10 -- Main-is: Test.hs -- GHC-Options: -W