I have a controller using a get handler that returns a Future<Content>
. I would like to add a header to the response (Cache-Control to be specific). I was thinking that it should be easy but I'm not finding how to do it. Which would be the way to add a header in this case? When we are working with Content
instead of Response
To solve the problem you could write your endpoint like this
struct Something: Content {
let text: String
}
router.get("customresponse") { req -> Future<Response> in
return try Something(text: "Hello world").encode(for: req).map { response in
response.http.headers.add(name: .cacheControl, value: "something")
return response
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With