Complete the code to get the value of the 'Content-Type' header from the response.
let contentType = pm.response.headers.get('[1]');
The 'Content-Type' header tells us the media type of the response. Using pm.response.headers.get('Content-Type') retrieves its value.
Complete the code to check if the response headers include 'Cache-Control'.
let hasCacheControl = pm.response.headers.has('[1]');
The has() method checks if a header exists. We want to check for 'Cache-Control' exactly.
Fix the error in the code to correctly assert the 'Server' header value is 'nginx'.
pm.test('Server header is nginx', function () { pm.expect(pm.response.headers.get('[1]')).to.eql('nginx'); });
Header names are case-insensitive but Postman expects the exact header name as sent. 'Server' is the correct header name to get.
Fill both blanks to create a test that asserts the 'Content-Length' header is greater than 100.
pm.test('Content-Length is greater than 100', function () { pm.expect(parseInt(pm.response.headers.get('[1]'))).to.be.[2](100); });
We get the 'Content-Length' header and parse it as an integer. Then we assert it is above 100 using to.be.above(100).
Fill all three blanks to create a test that asserts the 'ETag' header exists and starts with a double quote.
pm.test('ETag header exists and starts with a quote', function () { let etag = pm.response.headers.get('[1]'); pm.expect(etag).to.not.be.[2]; pm.expect(etag.startsWith('[3]')).to.be.true; });
startsWith.We get the 'ETag' header, assert it is not null, and check it starts with a double quote character.