Skip to content

Commit 4bbbe27

Browse files
authored
Merge pull request #33 from aviaviavi/no-log-bytes
don't log byte responses
2 parents 31555e4 + c936b18 commit 4bbbe27

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

curl-runnings.cabal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
--
33
-- see: https://github.com/sol/hpack
44
--
5-
-- hash: e6387b40a3da0bc0956a40390de8a48fca58d266b6a9865655e5dba0905f0088
5+
-- hash: 2ef05b4af0ee7565019a5729c09d3a678a43e0cb2357bcd40a77a9b19b3aed2a
66

77
name: curl-runnings
8-
version: 0.9.0
8+
version: 0.9.1
99
synopsis: A framework for declaratively writing curl based API tests
1010
description: Please see the README on Github at <https://github.com/aviaviavi/curl-runnings#readme>
1111
category: Testing

package.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: curl-runnings
2-
version: 0.9.0
2+
version: 0.9.1
33
github: aviaviavi/curl-runnings
44
license: MIT
55
author: Avi Press

src/Testing/CurlRunnings.hs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ module Testing.CurlRunnings
99
, decodeFile
1010
) where
1111

12+
import Control.Exception
1213
import Control.Monad
1314
import Data.Aeson
1415
import Data.Aeson.Types
@@ -75,9 +76,28 @@ runCase state curlCase = do
7576
DEBUG
7677
("Request body: " <> (pShow $ fromMaybe emptyObject replacedJSON))
7778
response <- httpBS request
78-
logger state DEBUG (pShow response)
79+
-- If the response is just returning bytes, we won't print them
80+
let responseHeaderValues = map snd (getResponseHeaders response)
81+
if "application/octet-stream" `notElem` responseHeaderValues &&
82+
"application/vnd.apple.pkpass" `notElem` responseHeaderValues
83+
then catch
84+
(logger state DEBUG (pShow response))
85+
(\(e :: IOException) ->
86+
logger state ERROR ("Error logging response: " <> pShow e))
87+
-- TODO: we should log as much info as possible without printing the raw body
88+
else logger
89+
state
90+
DEBUG
91+
"Response output supressed (returned content-type was bytes)"
7992
returnVal <-
80-
(return . decode . B.fromStrict $ getResponseBody response) :: IO (Maybe Value)
93+
catch
94+
((return . decode . B.fromStrict $ getResponseBody response) :: IO (Maybe Value))
95+
(\(e :: IOException) ->
96+
logger
97+
state
98+
ERROR
99+
("Error decoding response into json: " <> pShow e) >>
100+
return (Just Null))
81101
let returnCode = getResponseStatusCode response
82102
receivedHeaders = fromHTTPHeaders $ responseHeaders response
83103
assertionErrors =

0 commit comments

Comments
 (0)