From 9ad2efe8629c34678813b54292b4788f1d403f6f Mon Sep 17 00:00:00 2001 From: "Julian K. Arni" Date: Mon, 24 Oct 2016 17:15:29 +0200 Subject: [PATCH] Review fixes --- servant/CHANGELOG.md | 5 +++++ servant/src/Servant/API/ResponseHeaders.hs | 12 ++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/servant/CHANGELOG.md b/servant/CHANGELOG.md index 15a5532a..2b79fe63 100644 --- a/servant/CHANGELOG.md +++ b/servant/CHANGELOG.md @@ -1,3 +1,8 @@ +upcoming +-------- + +* Added 'noHeader' function for *not* adding response headers. + 0.9 --- diff --git a/servant/src/Servant/API/ResponseHeaders.hs b/servant/src/Servant/API/ResponseHeaders.hs index 9d81b97a..f6208dc2 100644 --- a/servant/src/Servant/API/ResponseHeaders.hs +++ b/servant/src/Servant/API/ResponseHeaders.hs @@ -45,7 +45,7 @@ import Prelude () import Prelude.Compat -- | Response Header objects. You should never need to construct one directly. --- Instead, use 'addHeader'. +-- Instead, use 'addOptionalHeader. data Headers ls a = Headers { getResponse :: a -- ^ The underlying value of a 'Headers' , getHeadersHList :: HList ls @@ -110,17 +110,17 @@ instance OVERLAPPABLE_ ( KnownSymbol h, GetHeaders (HList rest), ToHttpApiData v -- We need all these fundeps to save type inference class AddHeader h v orig new | h v orig -> new, new -> h, new -> v, new -> orig where - addHeader' :: Header h v -> orig -> new -- ^ N.B.: The same header can't be added multiple times + addOptionalHeader :: Header h v -> orig -> new -- ^ N.B.: The same header can't be added multiple times instance OVERLAPPING_ ( KnownSymbol h, ToHttpApiData v ) => AddHeader h v (Headers (fst ': rest) a) (Headers (Header h v ': fst ': rest) a) where - addHeader' hdr (Headers resp heads) = Headers resp (HCons hdr heads) + addOptionalHeader hdr (Headers resp heads) = Headers resp (HCons hdr heads) instance OVERLAPPABLE_ ( KnownSymbol h, ToHttpApiData v , new ~ (Headers '[Header h v] a) ) => AddHeader h v a new where - addHeader' hdr resp = Headers resp (HCons hdr HNil) + addOptionalHeader hdr resp = Headers resp (HCons hdr HNil) -- | @addHeader@ adds a header to a response. Note that it changes the type of -- the value in the following ways: @@ -143,7 +143,7 @@ instance OVERLAPPABLE_ ( KnownSymbol h, ToHttpApiData v -- the type can be inferred from the API type, in other cases you may find -- yourself needing to add annotations. addHeader :: AddHeader h v orig new => v -> orig -> new -addHeader = addHeader' . Header +addHeader = addOptionalHeader . Header -- | Deliberately do not add a header to a value. -- @@ -151,7 +151,7 @@ addHeader = addHeader' . Header -- >>> getHeaders example1 -- [] noHeader :: AddHeader h v orig new => orig -> new -noHeader = addHeader' MissingHeader +noHeader = addOptionalHeader MissingHeader -- $setup -- >>> import Servant.API