cancel
Showing results for 
Search instead for 
Did you mean: 

How to add Header in CAP Service Response?

rewatiraman_gds
Participant
0 Kudos

Hi Everyone,

I have a requirement where I need to add below Headers in CAP Service Response.

  • Content-Security-Policy
  • X-Content-type-options
  • Cache-Control
  • X-XSS-Protection

Please suggest !!!

Best Regards,

Rewati Raman

Accepted Solutions (0)

Answers (3)

Answers (3)

SebastianEsch
Active Participant
0 Kudos

Hi,

you can also avoid private APIs by using:

req.res.setHeader('header-name', 'header-value')

Kind regards,

Sebastian 

0 Kudos

Hi ajitkpanda , can you please provide any documentation on the implementation part.

Thanks

rewatiraman_gds
Participant
0 Kudos

Hi ajitkpanda ,

Thanks for the reply. I have figure out my issue.

I used helmet nodejs module for the headers.

const cds = require("@sap/cds");const proxy = require("@sap/cds-odata-v2-adapter-proxy");const helmet = require("helmet");var cache = require('cache-control');cds.on("bootstrap", app => { app.use(proxy()); app.use(helmet()); app.use(cache({ '/index.html': 1000, '/none/**/*.html': false, '/private.html': 'private, max-age=300', '/**': 500 // Default to caching all items for 500 }));});
module.exports = cds.server;
Ajit_K_Panda
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Rewati,

You can add by using the following methods:

1) req._.odataRes.setHeader

2) req._.res.set('field','value')

Thanks, Ajit