Complete the code to access HTTP headers in an Express route.
app.get('/info', (req, res) => { const headers = req.[1]; res.send(headers); });
The req.headers object contains all HTTP headers sent by the client.
Complete the code to read the 'user-agent' header from the request.
app.get('/agent', (req, res) => { const userAgent = req.headers['[1]']; res.send(userAgent); });
The 'user-agent' header tells the server about the client's browser or tool.
Fix the error in accessing the 'content-type' header from the request.
app.post('/data', (req, res) => { const contentType = req.[1]['content-type']; res.send(contentType); });
The 'content-type' header is inside req.headers, not in body, params, or query.
Fill both blanks to check if the 'authorization' header exists and send a response.
app.get('/auth', (req, res) => { if (req.[1]['[2]']) { res.send('Authorized'); } else { res.status(401).send('Unauthorized'); } });
Check req.headers['authorization'] to see if the client sent an authorization token.
Fill all three blanks to create a middleware that logs the 'host' header and calls next().
function logHost(req, res, [1]) { console.log('Host:', req.[2]['[3]']); [1](); }
Middleware functions get next as the third argument. Use req.headers['host'] to get the host header, then call next() to continue.