-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | A library for client-side HTTP
--
-- A library for client-side HTTP
@package HTTP
@version 3001.1.3
-- | An library for creating abstract streams. Originally part of
-- Gray's\/Bringert's HTTP module.
--
--
-- - Changes by Robin Bate Boerop robin@bateboerop.name: -
-- Removed unnecessary import statements. - Moved Debug code to
-- StreamDebugger.hs - Moved Socket-related code to StreamSocket.hs.
-- - Changes by Simon Foster: - Split Network.HTTPmodule up into to
-- separate Network.[Stream,TCP,HTTP] modules
--
module Network.Stream
-- | Streams should make layering of TLS protocol easier in future, they
-- allow reading/writing to files etc for debugging, they allow use of
-- protocols other than TCP/IP and they allow customisation.
--
-- Instances of this class should not trim the input in any way, e.g.
-- leave LF on line endings etc. Unless that is exactly the behaviour you
-- want from your twisted instances ;)
class Stream x
readLine :: (Stream x) => x -> IO (Result String)
readBlock :: (Stream x) => x -> Int -> IO (Result String)
writeBlock :: (Stream x) => x -> String -> IO (Result ())
close :: (Stream x) => x -> IO ()
data ConnError
ErrorReset :: ConnError
ErrorClosed :: ConnError
ErrorParse :: String -> ConnError
ErrorMisc :: String -> ConnError
-- | This is the type returned by many exported network functions.
type Result a = Either ConnError a
bindE :: Result a -> (a -> Result b) -> Result b
instance Show ConnError
instance Eq ConnError
-- | Implements debugging of Streams. Originally part of
-- Gray's\/Bringert's HTTP module.
--
--
module Network.StreamDebugger
-- | Allows stream logging. Refer to debugStream below.
data StreamDebugger x
-- | Wraps a stream with logging I/O. The first argument is a filename
-- which is opened in AppendMode.
debugStream :: (Stream a) => FilePath -> a -> IO (StreamDebugger a)
instance (Stream x) => Stream (StreamDebugger x)
-- | Socket Stream instance. Originally part of Gray's\/Bringert's HTTP
-- module.
--
--
-- - Changes by Robin Bate Boerop robin@bateboerop.name: - Made
-- dependencies explicit in import statements. - Removed false
-- dependencies in import statements. - Created separate module for
-- instance Stream Socket.
-- - Changes by Simon Foster: - Split module up into to sepearate
-- Network.[Stream,TCP,HTTP] modules
--
module Network.StreamSocket
-- | Exception handler for socket operations.
handleSocketError :: Socket -> Exception -> IO (Result a)
myrecv :: Socket -> Int -> IO String
instance Stream Socket
-- | An easy access TCP library. Makes the use of TCP in Haskell much
-- easier. This was originally part of Gray's\/Bringert's HTTP module.
--
--
-- - Changes by Robin Bate Boerop robin@bateboerop.name: - Made
-- dependencies explicit in import statements. - Removed false
-- dependencies from import statements. - Removed unused exported
-- functions.
-- - Changes by Simon Foster: - Split module up into to sepearate
-- Network.[Stream,TCP,HTTP] modules
--
module Network.TCP
-- | The Connection newtype is a wrapper that allows us to make
-- connections an instance of the StreamIn/Out classes, without ghc
-- extensions. While this looks sort of like a generic reference to the
-- transport layer it is actually TCP specific, which can be seen in the
-- implementation of the 'Stream Connection' instance.
data Connection
-- | This function establishes a connection to a remote host, it uses
-- getHostByName which interrogates the DNS system, hence may
-- trigger a network connection.
--
-- Add a persistant option? Current persistant is default. Use
-- Result type for synchronous exception reporting?
openTCPPort :: String -> Int -> IO Connection
-- | Checks both that the underlying Socket is connected and that the
-- connection peer matches the given host name (which is recorded
-- locally).
isConnectedTo :: Connection -> String -> IO Bool
instance Eq Conn
instance Stream Connection
-- |
-- - Changes by Robin Bate Boerop robin@bateboerop.name: - Made
-- dependencies explicit in import statements. - Removed false
-- dependencies in import statements. - Added missing type signatures. -
-- Created Network.HTTP.Headers from Network.HTTP modules.
--
--
-- See changes history and TODO list in Network.HTTP module.
--
--
--
--
-- - Host Required by HTTP/1.1, if not supplied as part
-- of a request a default Host value is extracted from the
-- request-uri.
-- - Connection If this header is present in any
-- request or response, and it's value is close, then the current
-- request/response is the last to be allowed on that connection.
-- - Expect Should a request contain a body, an Expect
-- header will be added to the request. The added header has the value
-- "100-continue". After a 417 "Expectation Failed" response the request
-- is attempted again without this added Expect header.
-- - TransferEncoding,ContentLength,... if request is
-- inconsistent with any of these header values then you may not receive
-- any response or will generate an error response (probably 4xx).
--
module Network.HTTP.Headers
-- | This class allows us to write generic header manipulation functions
-- for both Request and Response data types.
class HasHeaders x
getHeaders :: (HasHeaders x) => x -> [Header]
setHeaders :: (HasHeaders x) => x -> [Header] -> x
-- | The Header data type pairs header names & values.
data Header
Header :: HeaderName -> String -> Header
-- | HTTP Header Name type: Why include this at all? I have some reasons 1)
-- prevent spelling errors of header names, 2) remind everyone of what
-- headers are available, 3) might speed up searches for specific
-- headers.
--
-- Arguments against: 1) makes customising header names laborious 2)
-- increases code volume.
data HeaderName
HdrCacheControl :: HeaderName
HdrConnection :: HeaderName
HdrDate :: HeaderName
HdrPragma :: HeaderName
HdrTransferEncoding :: HeaderName
HdrUpgrade :: HeaderName
HdrVia :: HeaderName
HdrAccept :: HeaderName
HdrAcceptCharset :: HeaderName
HdrAcceptEncoding :: HeaderName
HdrAcceptLanguage :: HeaderName
HdrAuthorization :: HeaderName
HdrCookie :: HeaderName
HdrExpect :: HeaderName
HdrFrom :: HeaderName
HdrHost :: HeaderName
HdrIfModifiedSince :: HeaderName
HdrIfMatch :: HeaderName
HdrIfNoneMatch :: HeaderName
HdrIfRange :: HeaderName
HdrIfUnmodifiedSince :: HeaderName
HdrMaxForwards :: HeaderName
HdrProxyAuthorization :: HeaderName
HdrRange :: HeaderName
HdrReferer :: HeaderName
HdrUserAgent :: HeaderName
HdrAge :: HeaderName
HdrLocation :: HeaderName
HdrProxyAuthenticate :: HeaderName
HdrPublic :: HeaderName
HdrRetryAfter :: HeaderName
HdrServer :: HeaderName
HdrSetCookie :: HeaderName
HdrVary :: HeaderName
HdrWarning :: HeaderName
HdrWWWAuthenticate :: HeaderName
HdrAllow :: HeaderName
HdrContentBase :: HeaderName
HdrContentEncoding :: HeaderName
HdrContentLanguage :: HeaderName
HdrContentLength :: HeaderName
HdrContentLocation :: HeaderName
HdrContentMD5 :: HeaderName
HdrContentRange :: HeaderName
HdrContentType :: HeaderName
HdrETag :: HeaderName
HdrExpires :: HeaderName
HdrLastModified :: HeaderName
HdrContentTransferEncoding :: HeaderName
-- | Allows for unrecognised or experimental headers.
HdrCustom :: String -> HeaderName
insertHeader :: (HasHeaders a) => HeaderName -> String -> a -> a
insertHeaderIfMissing :: (HasHeaders a) => HeaderName -> String -> a -> a
-- | Inserts a header with the given name and value. Allows duplicate
-- header names.
--
-- Adds the new header only if no previous header shares the same name.
--
-- Removes old headers with duplicate name.
--
-- Inserts multiple headers.
insertHeaders :: (HasHeaders a) => [Header] -> a -> a
-- | Gets a list of headers with a particular HeaderName.
retrieveHeaders :: (HasHeaders a) => HeaderName -> a -> [Header]
replaceHeader :: (HasHeaders a) => HeaderName -> String -> a -> a
-- | Lookup presence of specific HeaderName in a list of Headers Returns
-- the value from the first matching header.
findHeader :: (HasHeaders a) => HeaderName -> a -> Maybe String
lookupHeader :: HeaderName -> [Header] -> Maybe String
parseHeaders :: [String] -> Result [Header]
parseHeader :: String -> Result Header
headerMap :: [(String, HeaderName)]
instance Eq HeaderName
instance Show HeaderName
instance Show Header
-- | An easy HTTP interface enjoy.
--
--
-- - Changes by Robin Bate Boerop robin@bateboerop.name: - Made
-- dependencies explicit in import statements. - Removed false
-- dependencies in import statements. - Added missing type signatures. -
-- Moved Header-related code to Network.HTTP.Headers module.
-- - Changes by Simon Foster: - Split module up into to sepearate
-- Network.[Stream,TCP,HTTP] modules - Created functions receiveHTTP and
-- responseHTTP to allow server side interactions (although 100-continue
-- is unsupported and I haven't checked for standard compliancy). -
-- Pulled the transfer functions from sendHTTP to global scope to allow
-- access by above functions.
-- - Changes by Graham Klyne: - export httpVersion - use new URI module
-- (similar to old, but uses revised URI datatype)
-- - Changes by Bjorn Bringert:
-- - handle URIs with a port number - added debugging toggle - disabled
-- 100-continue transfers to get HTTP/1.0 compatibility - change
-- ioError to throw - Added simpleHTTP_, which takes a
-- stream argument.
-- - Changes from 0.1 - change openHTTP to openTCP,
-- removed closeTCP - use close from Stream class.
-- - added use of inet_addr to openHTTP, allowing use of IP dot
-- notation addresses. - reworking of the use of Stream, including
-- alterations to make sendHTTP generic and the addition of a
-- debugging stream. - simplified error handling.
-- - TODO - request pipelining - https upgrade (includes full TLS, i.e.
-- SSL, implementation) - use of Stream classes will pay off - consider C
-- implementation of encryption/decryption - comm timeouts - MIME &
-- entity stuff (happening in separate module) - support "*"
-- uri-request-string for OPTIONS request method
-- - Header notes:
--
--
--
-- - Host Required by HTTP/1.1, if not supplied as part
-- of a request a default Host value is extracted from the
-- request-uri.
-- - Connection If this header is present in any
-- request or response, and it's value is close, then the current
-- request/response is the last to be allowed on that connection.
-- - Expect Should a request contain a body, an Expect
-- header will be added to the request. The added header has the value
-- "100-continue". After a 417 "Expectation Failed" response the request
-- is attempted again without this added Expect header.
-- - TransferEncoding,ContentLength,... if request is
-- inconsistent with any of these header values then you may not receive
-- any response or will generate an error response (probably 4xx).
--
--
--
-- - Response code notes Some response codes induce special
-- behaviour:
--
--
--
-- - 1xx "100 Continue" will cause any unsent request
-- body to be sent. "101 Upgrade" will be returned. Other 1xx responses
-- are ignored.
-- - 417 The reason for this code is "Expectation
-- failed", indicating that the server did not like the Expect
-- "100-continue" header added to a request. Receipt of 417 will induce
-- another request attempt (without Expect header), unless no Expect
-- header had been added (in which case 417 response is returned).
--
module Network.HTTP
httpVersion :: String
-- | An HTTP Request. The Show instance of this type is used for
-- message serialisation, which means no body data is output.
data Request
Request :: URI -> RequestMethod -> [Header] -> String -> Request
-- | might need changing in future 1) to support * uri in OPTIONS
-- request 2) transparent support for both relative & absolute uris,
-- although this should already work (leave scheme & host parts
-- empty).
rqURI :: Request -> URI
rqMethod :: Request -> RequestMethod
rqHeaders :: Request -> [Header]
rqBody :: Request -> String
type RequestData = (RequestMethod, URI, [Header])
-- | An HTTP Response. The Show instance of this type is used for
-- message serialisation, which means no body data is output,
-- additionally the output will show an HTTP version of 1.1 instead of
-- the actual version returned by a server.
data Response
Response :: ResponseCode -> String -> [Header] -> String -> Response
rspCode :: Response -> ResponseCode
rspReason :: Response -> String
rspHeaders :: Response -> [Header]
rspBody :: Response -> String
-- | The HTTP request method, to be used in the Request object. We
-- are missing a few of the stranger methods, but these are not really
-- necessary until we add full TLS.
data RequestMethod
HEAD :: RequestMethod
PUT :: RequestMethod
GET :: RequestMethod
POST :: RequestMethod
DELETE :: RequestMethod
OPTIONS :: RequestMethod
TRACE :: RequestMethod
Custom :: String -> RequestMethod
type ResponseCode = (Int, Int, Int)
-- | Simple way to get a resource across a non-persistant connection.
-- Headers that may be altered: Host Altered only if no Host header is
-- supplied, HTTP/1.1 requires a Host header. Connection Where no
-- allowance is made for persistant connections the Connection header
-- will be set to close
simpleHTTP :: Request -> IO (Result Response)
-- | Like simpleHTTP, but acting on an already opened stream.
simpleHTTP_ :: (Stream s) => s -> Request -> IO (Result Response)
sendHTTP :: (Stream s) => s -> Request -> IO (Result Response)
-- | Receive and parse a HTTP request from the given Stream. Should be used
-- for server side interactions.
receiveHTTP :: (Stream s) => s -> IO (Result Request)
-- | Process request body (called after successful getRequestHead)
processRequest :: (Stream s) => s -> RequestData -> IO (Result Request)
-- | Reads and parses request headers.
getRequestHead :: (Stream s) => s -> IO (Result RequestData)
-- | Very simple function, send a HTTP response over the given stream. This
-- could be improved on to use different transfer types.
respondHTTP :: (Stream s) => s -> Response -> IO ()
-- | Converts a single value to the application/x-www-form-urlencoded
-- encoding.
urlEncode :: String -> String
-- | Converts a single value from the application/x-www-form-urlencoded
-- encoding.
urlDecode :: String -> String
-- | Formats name-value pairs as application/x-www-form-urlencoded.
urlEncodeVars :: [(String, String)] -> String
data URIAuthority
URIAuthority :: Maybe String -> Maybe String -> String -> Maybe Int -> URIAuthority
user :: URIAuthority -> Maybe String
password :: URIAuthority -> Maybe String
host :: URIAuthority -> String
port :: URIAuthority -> Maybe Int
getAuth :: (Monad m) => Request -> m URIAuthority
-- | Parse the authority part of a URL.
--
--
-- RFC 1738, section 3.1:
--
-- //<user>:<password>@<host>:<port>/<url-path>
-- Some or all of the parts "<user>:<password>@", ":<password>",
-- ":<port>", and "/<url-path>" may be excluded.
--
parseURIAuthority :: String -> Maybe URIAuthority
instance Show RequestMethod
instance Eq RequestMethod
instance Eq URIAuthority
instance Show URIAuthority
instance HasHeaders Response
instance Show Response
instance HasHeaders Request
instance Show Request
-- | An HTTP/1.1 compatible wrapper for the HTTP module.
module Network.Browser
data BrowserState
data BrowserAction a
data Cookie
MkCookie :: String -> String -> String -> Maybe String -> Maybe String -> Maybe String -> Cookie
ckDomain :: Cookie -> String
ckName :: Cookie -> String
ckValue :: Cookie -> String
ckPath :: Cookie -> Maybe String
ckComment :: Cookie -> Maybe String
ckVersion :: Cookie -> Maybe String
data Form
Form :: RequestMethod -> URI -> [FormVar] -> Form
-- | Specifies if a proxy should be used for the request.
data Proxy
-- | Don't use a proxy.
NoProxy :: Proxy
-- | Use the proxy given. Should be of the form http://host:port,
-- host, host:port, or http://host
Proxy :: String -> (Maybe Authority) -> Proxy
-- | Apply a browser action to a state.
browse :: BrowserAction a -> IO a
request :: Request -> BrowserAction (URI, Response)
setAllowRedirects :: Bool -> BrowserAction ()
getAllowRedirects :: BrowserAction Bool
data Authority
AuthBasic :: String -> String -> String -> URI -> Authority
auRealm :: Authority -> String
auUsername :: Authority -> String
auPassword :: Authority -> String
auSite :: Authority -> URI
AuthDigest :: String -> String -> String -> String -> Maybe Algorithm -> [URI] -> Maybe String -> [Qop] -> Authority
auRealm :: Authority -> String
auUsername :: Authority -> String
auPassword :: Authority -> String
auNonce :: Authority -> String
auAlgorithm :: Authority -> Maybe Algorithm
auDomain :: Authority -> [URI]
auOpaque :: Authority -> Maybe String
auQop :: Authority -> [Qop]
-- | Interacting with browser state:
getAuthorities :: BrowserAction [Authority]
setAuthorities :: [Authority] -> BrowserAction ()
addAuthority :: Authority -> BrowserAction ()
getAuthorityGen :: BrowserAction (URI -> String -> IO (Maybe (String, String)))
setAuthorityGen :: (URI -> String -> IO (Maybe (String, String))) -> BrowserAction ()
setAllowBasicAuth :: Bool -> BrowserAction ()
setCookieFilter :: (URI -> Cookie -> IO Bool) -> BrowserAction ()
defaultCookieFilter :: URI -> Cookie -> IO Bool
userCookieFilter :: URI -> Cookie -> IO Bool
getCookies :: BrowserAction [Cookie]
setCookies :: [Cookie] -> BrowserAction ()
-- | Adds a cookie to the browser state, removing duplicates.
addCookie :: Cookie -> BrowserAction ()
setErrHandler :: (String -> IO ()) -> BrowserAction ()
setOutHandler :: (String -> IO ()) -> BrowserAction ()
setProxy :: Proxy -> BrowserAction ()
setDebugLog :: Maybe String -> BrowserAction ()
out :: String -> BrowserAction ()
err :: String -> BrowserAction ()
-- | Do an io action
ioAction :: IO a -> BrowserAction a
defaultGETRequest :: URI -> Request
formToRequest :: Form -> Request
-- | Returns a URI that is consistent with the first argument uri when read
-- in the context of a second. If second argument is not sufficient
-- context for determining a full URI then anarchy reins.
uriDefaultTo :: URI -> URI -> URI
uriTrimHost :: URI -> URI
instance Eq Qop
instance Show Qop
instance Eq Algorithm
instance Show Cookie
instance Read Cookie
instance Functor BrowserAction
instance Monad BrowserAction
instance Show BrowserState
instance Show Algorithm
instance Eq Cookie