Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hack /client/:cid/nonce to also return a Content-Length Header #3771

Closed
wants to merge 1 commit into from
Closed
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
28 changes: 24 additions & 4 deletions libs/wire-api/src/Wire/API/Routes/Public/Brig.hs
Original file line number Diff line number Diff line change
Expand Up @@ -844,19 +844,39 @@ type NewNonce name method statusCode =
method
'[JSON]
( WithHeaders
'[Header "Replay-Nonce" NonceHeader, Header "Cache-Control" CacheControl]
-- The response contains explicit 'Content-Length' header to
-- get around https://github.com/yesodweb/wai/issues/956
'[Header "Replay-Nonce" NonceHeader, Header "Cache-Control" CacheControl, Header "Content-Length" ZeroContentLength]
(Nonce, CacheControl)
(RespondEmpty statusCode "No Content")
)
)

-- | Used to get around https://github.com/yesodweb/wai/issues/956
data ZeroContentLength = ZeroContentLength

instance S.ToParamSchema ZeroContentLength where
toParamSchema _ =
mempty
& S.description ?~ "This field exists to get around a server bug, please do not use."
& S.type_ ?~ S.OpenApiInteger
& S.minimum_ ?~ 0
& S.maximum_ ?~ 0

instance FromHttpApiData ZeroContentLength where
parseUrlPiece "0" = Right ZeroContentLength
parseUrlPiece x = Left $ "Expected ZeroContentLength to only be 0, got: " <> x

instance ToHttpApiData ZeroContentLength where
toUrlPiece ZeroContentLength = "0"

newtype NonceHeader = NonceHeader Nonce
deriving (Eq, Show)
deriving newtype (FromByteString, ToByteString, ToParamSchema, ToHttpApiData, FromHttpApiData)

instance AsHeaders '[NonceHeader, CacheControl] () (Nonce, CacheControl) where
fromHeaders (I (NonceHeader n) :* (I cc :* Nil), ()) = (n, cc)
toHeaders (n, cc) = (I (NonceHeader n) :* (I cc :* Nil), ())
instance AsHeaders '[NonceHeader, CacheControl, ZeroContentLength] () (Nonce, CacheControl) where
fromHeaders (I (NonceHeader n) :* (I cc :* (I _ :* Nil)), ()) = (n, cc)
toHeaders (n, cc) = (I (NonceHeader n) :* (I cc :* (I ZeroContentLength :* Nil)), ())

type ClientAPI =
Named
Expand Down
Loading