blob: 0d3aea85993f56b51e18340d8f87675b330de063 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
--- a/test/Network/HTTP/ClientSpec.hs
+++ b/test/Network/HTTP/ClientSpec.hs
@@ -15,83 +15,4 @@
main = hspec spec
spec :: Spec
-spec = describe "Client" $ do
- it "works" $ withSocketsDo $ do
- req <- parseUrlThrow "http://httpbin.org/"
- man <- newManager defaultManagerSettings
- res <- httpLbs req man
- responseStatus res `shouldBe` status200
-
- describe "method in URL" $ do
- it "success" $ withSocketsDo $ do
- req <- parseUrlThrow "POST http://httpbin.org/post"
- man <- newManager defaultManagerSettings
- res <- httpLbs req man
- responseStatus res `shouldBe` status200
-
- it "failure" $ withSocketsDo $ do
- req <- parseRequest "PUT http://httpbin.org/post"
- man <- newManager defaultManagerSettings
- res <- httpLbs req man
- responseStatus res `shouldBe` status405
-
- describe "redirects" $ do
- it "follows redirects" $ do
- req <- parseRequest "http://httpbin.org/redirect-to?url=http://httpbin.org"
- man <- newManager defaultManagerSettings
- res <- httpLbs req man
- responseStatus res `shouldBe` status200
-
- it "allows to disable redirect following" $ do
- req <- (\ r -> r{ redirectCount = 0 }) <$>
- parseRequest "http://httpbin.org/redirect-to?url=http://httpbin.org"
- man <- newManager defaultManagerSettings
- res <- httpLbs req man
- responseStatus res `shouldBe` found302
-
- context "managerModifyResponse" $ do
- it "allows to modify the response status code" $ do
- let modify :: Response BodyReader -> IO (Response BodyReader)
- modify res = do
- return res {
- responseStatus = (responseStatus res) {
- statusCode = 201
- }
- }
- settings = defaultManagerSettings { managerModifyResponse = modify }
- man <- newManager settings
- res <- httpLbs "http://httpbin.org" man
- (statusCode.responseStatus) res `shouldBe` 201
-
- it "modifies the response body" $ do
- let modify :: Response BodyReader -> IO (Response BodyReader)
- modify res = do
- reader <- constBodyReader [BS.pack "modified response body"]
- return res {
- responseBody = reader
- }
- settings = defaultManagerSettings { managerModifyResponse = modify }
- man <- newManager settings
- res <- httpLbs "http://httpbin.org" man
- responseBody res `shouldBe` "modified response body"
-
- context "managerModifyRequest" $ do
- it "port" $ do
- let modify req = return req { port = 80 }
- settings = defaultManagerSettings { managerModifyRequest = modify }
- man <- newManager settings
- res <- httpLbs "http://httpbin.org:1234" man
- responseStatus res `shouldBe` status200
-
- it "checkResponse" $ do
- let modify req = return req { checkResponse = \_ _ -> error "some exception" }
- settings = defaultManagerSettings { managerModifyRequest = modify }
- man <- newManager settings
- httpLbs "http://httpbin.org" man `shouldThrow` anyException
-
- it "redirectCount" $ do
- let modify req = return req { redirectCount = 0 }
- settings = defaultManagerSettings { managerModifyRequest = modify }
- man <- newManager settings
- response <- httpLbs "http://httpbin.org/redirect-to?url=foo" man
- responseStatus response `shouldBe` found302
+spec = return ()
|