This article mainly introduces the instructions for using the removeHeader, setHeader, and getHeader methods of http.response. This chapter introduces the instructions, syntax, and syntax of http.response.removeHeader, http.response.setHeader, http.response.getHeader and other methods. For receiving parameters, usage examples and implementation source code, friends in need can refer to the
http.response.removeHeader
method description:
Remove headers waiting to be sent implicitly.
Syntax:
response.removeHeader(name)
Receive parameters:
name: The type of response header. Note that this name is not case sensitive.
Example:
response.removeHeader("Content-Encoding");
http.response.setHeader
Method description:
Set header file information.
If the information to be sent already contains a header file, the value of the header file will be overwritten after executing this method.
If a header file needs to pass multiple values, you can use an array.
Syntax:
response.setHeader(name, value)
Receive parameters:
name The type of response header. Note that the name is not distinguished. Upper and lower case.
value The value of the response header
Example:
response.setHeader("Content-Type", "text/html"); //或者使用数组形式 response.setHeader("Set-Cookie", ["type=ninja", "language=javascript"]);
http.response.getHeader
Method description:
Read queued but not yet sent to the client header information.
Syntax:
response.getHeader(name)
Receive parameters:
name The type of response header. Note that this name is not case-sensitive.
Example:
var contentType = response.getHeader('content-type');
The above is the entire content of this chapter. For more related tutorials, please visit the Node.js video tutorial!