Home > Web Front-end > JS Tutorial > Instructions for using the removeHeader, setHeader, and getHeader methods of http.response in node.js

Instructions for using the removeHeader, setHeader, and getHeader methods of http.response in node.js

PHPz
Release: 2018-09-30 10:32:43
Original
2676 people have browsed it

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)
Copy after login

Receive parameters:

name: The type of response header. Note that this name is not case sensitive.

Example:

response.removeHeader("Content-Encoding");
Copy after login

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)
Copy after login

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"]);
Copy after login

http.response.getHeader

Method description:

Read queued but not yet sent to the client header information.

Syntax:

response.getHeader(name)
Copy after login

Receive parameters:

name The type of response header. Note that this name is not case-sensitive.

Example:

var contentType = response.getHeader('content-type');
Copy after login

The above is the entire content of this chapter. For more related tutorials, please visit the Node.js video tutorial!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template