on master help sign in
Review fixes
9ad2efeJulian K. Arni
servant/CHANGELOG.md+5
@@ -1,3 +1,8 @@
1+upcoming
2+--------
3+
4+* Added 'noHeader' function for *not* adding response headers.
5+
10.9
60.9
2---
7---
3
8
servant/src/Servant/API/ResponseHeaders.hs+6−6
@@ -45,7 +45,7 @@ import Prelude ()
45import Prelude.Compat
45import Prelude.Compat
46
46
47-- | Response Header objects. You should never need to construct one directly.
47-- | Response Header objects. You should never need to construct one directly.
48−-- Instead, use 'addHeader'.
48+-- Instead, use 'addOptionalHeader.
49data Headers ls a = Headers { getResponse :: a
49data Headers ls a = Headers { getResponse :: a
50 -- ^ The underlying value of a 'Headers'
50 -- ^ The underlying value of a 'Headers'
51 , getHeadersHList :: HList ls
51 , getHeadersHList :: HList ls
@@ -110,17 +110,17 @@ instance OVERLAPPABLE_ ( KnownSymbol h, GetHeaders (HList rest), ToHttpApiData v
110-- We need all these fundeps to save type inference
110-- We need all these fundeps to save type inference
111class AddHeader h v orig new
111class AddHeader h v orig new
112 | h v orig -> new, new -> h, new -> v, new -> orig where
112 | h v orig -> new, new -> h, new -> v, new -> orig where
113− addHeader' :: Header h v -> orig -> new -- ^ N.B.: The same header can't be added multiple times
113+ addOptionalHeader :: Header h v -> orig -> new -- ^ N.B.: The same header can't be added multiple times
114
114
115
115
116instance OVERLAPPING_ ( KnownSymbol h, ToHttpApiData v )
116instance OVERLAPPING_ ( KnownSymbol h, ToHttpApiData v )
117 => AddHeader h v (Headers (fst ': rest) a) (Headers (Header h v ': fst ': rest) a) where
117 => AddHeader h v (Headers (fst ': rest) a) (Headers (Header h v ': fst ': rest) a) where
118− addHeader' hdr (Headers resp heads) = Headers resp (HCons hdr heads)
118+ addOptionalHeader hdr (Headers resp heads) = Headers resp (HCons hdr heads)
119
119
120instance OVERLAPPABLE_ ( KnownSymbol h, ToHttpApiData v
120instance OVERLAPPABLE_ ( KnownSymbol h, ToHttpApiData v
121 , new ~ (Headers '[Header h v] a) )
121 , new ~ (Headers '[Header h v] a) )
122 => AddHeader h v a new where
122 => AddHeader h v a new where
123− addHeader' hdr resp = Headers resp (HCons hdr HNil)
123+ addOptionalHeader hdr resp = Headers resp (HCons hdr HNil)
124
124
125-- | @addHeader@ adds a header to a response. Note that it changes the type of
125-- | @addHeader@ adds a header to a response. Note that it changes the type of
126-- the value in the following ways:
126-- the value in the following ways:
@@ -143,7 +143,7 @@ instance OVERLAPPABLE_ ( KnownSymbol h, ToHttpApiData v
143-- the type can be inferred from the API type, in other cases you may find
143-- the type can be inferred from the API type, in other cases you may find
144-- yourself needing to add annotations.
144-- yourself needing to add annotations.
145addHeader :: AddHeader h v orig new => v -> orig -> new
145addHeader :: AddHeader h v orig new => v -> orig -> new
146−addHeader = addHeader' . Header
146+addHeader = addOptionalHeader . Header
147
147
148-- | Deliberately do not add a header to a value.
148-- | Deliberately do not add a header to a value.
149--
149--
@@ -151,7 +151,7 @@ addHeader = addHeader' . Header
151-- >>> getHeaders example1
151-- >>> getHeaders example1
152-- []
152-- []
153noHeader :: AddHeader h v orig new => orig -> new
153noHeader :: AddHeader h v orig new => orig -> new
154−noHeader = addHeader' MissingHeader
154+noHeader = addOptionalHeader MissingHeader
155
155
156-- $setup
156-- $setup
157-- >>> import Servant.API
157-- >>> import Servant.API