gdritter repos shelob / master
Update for new deps Getty Ritter 3 years ago
6 changed file(s) with 26 addition(s) and 29 deletion(s). Collapse all Expand all
2020 , Network.Shelob.Utils
2121 hs-source-dirs: src
2222 ghc-options: -Wall
23 build-depends: base >=4.7 && <4.10
23 build-depends: base >=4.7 && <5
2424 , bytestring
25 , network
2625 , deepseq
2726 default-language: Haskell2010
2827 default-extensions: OverloadedStrings,
2928 ScopedTypeVariables
3029
31 executable example
32 hs-source-dirs: example
33 main-is: Main.hs
34 ghc-options: -Wall
35 build-depends: base, shelob, pretty-show
36 default-language: Haskell2010
37 default-extensions: OverloadedStrings
30 -- executable example
31 -- hs-source-dirs: example
32 -- main-is: Main.hs
33 -- ghc-options: -Wall
34 -- build-depends: base, shelob, pretty-show
35 -- default-language: Haskell2010
36 -- default-extensions: OverloadedStrings
7171 = HTTPError deriving (Typeable, Show)
7272
7373 instance Ex.Exception HTTPError where
74 toException = undefined
75 fromException = undefined
44
55 import qualified Data.ByteString as BS
66 import qualified Data.ByteString.Char8 as BS8
7 import qualified Network.Socket as Sock
8 import qualified System.IO as H
97
108 import Network.Shelob.Connection
119 import Network.Shelob.Request
3937 , userAgent
4038 ]
4139
42 httpConnection :: String -> IO Connection
43 httpConnection host = do
44 addrInfo <- Sock.getAddrInfo Nothing (Just host) (Just "http")
45 case addrInfo of
46 [] -> error ("unable to look up " ++ host)
47 info:_ -> do
48 s <- Sock.socket (Sock.addrFamily info)
49 (Sock.addrSocketType info)
50 (Sock.addrProtocol info)
51 Sock.connect s (Sock.addrAddress info)
52 h <- Sock.socketToHandle s H.ReadWriteMode
53 return $ handleToConnection h
54
5540 makeRequest :: Connection -> Request -> IO (Either HTTPError Response)
5641 makeRequest conn req = do
5742 let pReq = pRequest req
58 print pReq
5943 connWrite conn pReq
6044 readResponse conn req
11 module Main where
22
3 import qualified Network.Shelob as HTTP (httpConnection)
43 import qualified Network.Shelob.Client as HTTP
54 import qualified Network.Shelob.Types as HTTP
65 import Text.Show.Pretty
1515 exposed-modules: Network.Shelob.Client
1616 hs-source-dirs: src
1717 ghc-options: -Wall
18 build-depends: base >=4.7 && <4.10
18 build-depends: base >=4.7 && <5
1919 , shelob
2020 , text
2121 , bytestring
2222 , aeson
23 , network
2324 default-language: Haskell2010
2425 default-extensions: OverloadedStrings,
2526 ScopedTypeVariables
88 import qualified Data.ByteString.Char8 as BS8
99 import qualified Data.Text as T
1010 import qualified Data.Text.Encoding as T
11 import qualified Network.Socket as Sock
12 import qualified System.IO as H
1113
1214 import Network.Shelob
15 import Network.Shelob.Connection
1316 import Network.Shelob.Types
1417
1518
110113 where hs' = [ Header "Content-Length" (BS8.pack (show (BS.length body)))
111114 , userAgent
112115 ]
116
117 httpConnection :: String -> IO Connection
118 httpConnection host = do
119 addrInfo <- Sock.getAddrInfo Nothing (Just host) (Just "http")
120 case addrInfo of
121 [] -> error ("unable to look up " ++ host)
122 info:_ -> do
123 s <- Sock.socket (Sock.addrFamily info)
124 (Sock.addrSocketType info)
125 (Sock.addrProtocol info)
126 Sock.connect s (Sock.addrAddress info)
127 h <- Sock.socketToHandle s H.ReadWriteMode
128 return $ handleToConnection h