Skip to content

Commit

Permalink
Add Cache-Control: no-cache to headers
Browse files Browse the repository at this point in the history
  • Loading branch information
bflyblue committed Oct 18, 2023
1 parent a982473 commit e62fbb5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Update version bounds to support GHC 9.6 and servant 0.20
- Drop support for `jsForAPI` and the dependency on `servant-js`
- Remove dependency on pipes, breaking change for `eventSource` function
- Add "Cache-Control: no-cache" to headers

## 0.2.1.0 -- 2021-04-21

Expand Down
4 changes: 2 additions & 2 deletions src/Servant/API/EventStream.hs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ type EventSource = SourceIO ServerEvent

-- | This is mostly to guide reverse-proxies like
-- <https://www.nginx.com/resources/wiki/start/topics/examples/x-accel/#x-accel-buffering nginx>
type EventSourceHdr = Headers '[Header "X-Accel-Buffering" Text] EventSource
type EventSourceHdr = Headers '[Header "X-Accel-Buffering" Text, Header "Cache-Control" Text] EventSource

-- | See details at
-- https://hackage.haskell.org/package/wai-extra-3.1.6/docs/Network-Wai-EventSource-EventStream.html#v:eventToBuilder
instance MimeRender EventStream ServerEvent where
mimeRender _ = maybe "" toLazyByteString . eventToBuilder

eventSource :: EventSource -> EventSourceHdr
eventSource = addHeader @"X-Accel-Buffering" "no"
eventSource = addHeader @"X-Accel-Buffering" "no" . addHeader @"Cache-Control" "no-cache"

0 comments on commit e62fbb5

Please sign in to comment.