Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

[CAD-1353] Add JSON size check for offline metadata. #13

Merged
merged 1 commit into from
Jul 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/DbSyncPlugin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,18 @@ fetchInsertPoolMetadata tracer md = do

liftIO . logInfo tracer $ "HTTP Client GET request."

-- The response size check.
_responseRaw <- handleExceptT (\(e :: HttpException) -> NEError $ show e) $ withResponse request manager $ \responseBR -> do
-- We read the first chunk that should contain all the bytes from the reponse.
responseBSFirstChunk <- brReadSome (responseBody responseBR) 512
-- If there are more bytes in the second chunk, we don't go any further since that
-- violates the size constraint.
responseBSSecondChunk <- brReadSome (responseBody responseBR) 512
if BL.null responseBSSecondChunk
then pure responseBSFirstChunk
else throwIO $ HttpExceptionRequest request NoResponseDataReceived

-- The request for fetching the full content strictly.
let httpRequest :: MonadIO n => n (Response BL.ByteString)
httpRequest = liftIO $ httpLbs request manager

Expand Down