Setting Headers

An important part of formulating a proper HTTP response is to set the headers. For example, setting the Content-Type header tells the browser how to handle responses. The Response object provides several helper methods to get and set the header values that are sent with HTTP responses.

The most commonly used methods are get(header) and set(header, value), which get and set any header value. For example, the following code first gets the Content-Type header and then sets it:

var oldType = res.get('Content-Type'),
res.set('Content-Type', 'text/plain'),

Table 18.3 describes the helper methods to get and set header values.

Image

Table 18.3 Methods to get and set header values on the Response object

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.181.61