@@ -168,7 +168,15 @@ module Network.HTTP.Req
168 , responseTimeout
168 , responseTimeout
169 , httpVersion
169 , httpVersion
170 -- * Response
170 -- * Response
171+ -- ** Response interpretations
172+ , IgnoredResponseBody
171− -- $response
173+ -- ** Inspecting a response
175+ , responseStatusCode
176+ , responseStatusMessage
179+ -- ** Defining your own interpretation
172 , HttpResponse (..)
180 , HttpResponse (..)
173 -- * Other
181 -- * Other
174 , CanHaveBody (..)
182 , CanHaveBody (..)
@@ -983,15 +991,68 @@ httpVersion major minor = withRequest $ \x ->
983 Y.HttpVersion (fromIntegral major) (fromIntegral minor) }
991 Y.HttpVersion (fromIntegral major) (fromIntegral minor) }
985----------------------------------------------------------------------------
993----------------------------------------------------------------------------
986−-- Response
994+-- Response interpretations
996+data IgnoredResponseBody = IgnoredResponseBody (L.Response ())
998+----------------------------------------------------------------------------
988−-- $response
999+-- Inspecting a response
990−-- Something.
1001+-- | Get response body.
1004+ :: HttpResponse response
1006+ -> HttpResponseBody response
1007+responseBody = L.responseBody . toVanillaResponse
1009+-- | Get response status code.
1012+ :: HttpResponse response
1015+responseStatusCode =
1016+ fromIntegral . Y.statusCode . L.responseStatus . toVanillaResponse
1018+-- | Get response status message.
1020+responseStatusMessage
1021+ :: HttpResponse response
1024+responseStatusMessage =
1025+ Y.statusMessage . L.responseStatus . toVanillaResponse
1027+-- | Look a particular header from a response.
1030+ :: HttpResponse response
1031+ => response -- ^ Response interpretation
1032+ -> ByteString -- ^ Header to lookup
1033+ -> Maybe ByteString -- ^ Header value if found
1034+responseHeader r h =
1035+ (lookup (CI.mk h) . L.responseHeaders . toVanillaResponse) r
1037+-- | Get response 'L.CookieJar'.
1040+ :: HttpResponse response
1043+responseCookieJar = L.responseCookieJar . toVanillaResponse
1045+----------------------------------------------------------------------------
1046+-- Response — defining your own interpretation
992-- | Here we need to provide various options how to consume responses.
1048-- | Here we need to provide various options how to consume responses.
994class HttpResponse response where
1050class HttpResponse response where
1052+ type HttpResponseBody response :: *
1054+ toVanillaResponse :: response -> L.Response (HttpResponseBody response)
995 getHttpResponse :: L.Manager -> L.Request -> IO response
1056 getHttpResponse :: L.Manager -> L.Request -> IO response
997----------------------------------------------------------------------------
1058----------------------------------------------------------------------------