Update for new deps
Getty Ritter
7 years ago
20 | 20 |
, Network.Shelob.Utils
|
21 | 21 |
hs-source-dirs: src
|
22 | 22 |
ghc-options: -Wall
|
23 | |
build-depends: base >=4.7 && <4.10
|
| 23 |
build-depends: base >=4.7 && <5
|
24 | 24 |
, bytestring
|
25 | |
, network
|
26 | 25 |
, deepseq
|
27 | 26 |
default-language: Haskell2010
|
28 | 27 |
default-extensions: OverloadedStrings,
|
29 | 28 |
ScopedTypeVariables
|
30 | 29 |
|
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
|
71 | 71 |
= HTTPError deriving (Typeable, Show)
|
72 | 72 |
|
73 | 73 |
instance Ex.Exception HTTPError where
|
74 | |
toException = undefined
|
75 | |
fromException = undefined
|
4 | 4 |
|
5 | 5 |
import qualified Data.ByteString as BS
|
6 | 6 |
import qualified Data.ByteString.Char8 as BS8
|
7 | |
import qualified Network.Socket as Sock
|
8 | |
import qualified System.IO as H
|
9 | 7 |
|
10 | 8 |
import Network.Shelob.Connection
|
11 | 9 |
import Network.Shelob.Request
|
|
39 | 37 |
, userAgent
|
40 | 38 |
]
|
41 | 39 |
|
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 | |
|
55 | 40 |
makeRequest :: Connection -> Request -> IO (Either HTTPError Response)
|
56 | 41 |
makeRequest conn req = do
|
57 | 42 |
let pReq = pRequest req
|
58 | |
print pReq
|
59 | 43 |
connWrite conn pReq
|
60 | 44 |
readResponse conn req
|
1 | 1 |
module Main where
|
2 | 2 |
|
3 | |
import qualified Network.Shelob as HTTP (httpConnection)
|
4 | 3 |
import qualified Network.Shelob.Client as HTTP
|
5 | 4 |
import qualified Network.Shelob.Types as HTTP
|
6 | 5 |
import Text.Show.Pretty
|
15 | 15 |
exposed-modules: Network.Shelob.Client
|
16 | 16 |
hs-source-dirs: src
|
17 | 17 |
ghc-options: -Wall
|
18 | |
build-depends: base >=4.7 && <4.10
|
| 18 |
build-depends: base >=4.7 && <5
|
19 | 19 |
, shelob
|
20 | 20 |
, text
|
21 | 21 |
, bytestring
|
22 | 22 |
, aeson
|
| 23 |
, network
|
23 | 24 |
default-language: Haskell2010
|
24 | 25 |
default-extensions: OverloadedStrings,
|
25 | 26 |
ScopedTypeVariables
|
8 | 8 |
import qualified Data.ByteString.Char8 as BS8
|
9 | 9 |
import qualified Data.Text as T
|
10 | 10 |
import qualified Data.Text.Encoding as T
|
| 11 |
import qualified Network.Socket as Sock
|
| 12 |
import qualified System.IO as H
|
11 | 13 |
|
12 | 14 |
import Network.Shelob
|
| 15 |
import Network.Shelob.Connection
|
13 | 16 |
import Network.Shelob.Types
|
14 | 17 |
|
15 | 18 |
|
|
110 | 113 |
where hs' = [ Header "Content-Length" (BS8.pack (show (BS.length body)))
|
111 | 114 |
, userAgent
|
112 | 115 |
]
|
| 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
|