Headers.has() - Web APIs 编辑
The has()
method of the Headers
interface returns a boolean stating whether a Headers
object contains a certain header.
For security reasons, some headers can only be controlled by the user agent. These headers include the forbidden header names and forbidden response header names.
Syntax
myHeaders.has(name);
Parameters
name
- The name of the HTTP header you want to test for. If the given name is not a valid HTTP header name, this method throws a
TypeError
.
Returns
A Boolean
.
Example
Creating an empty Headers
object is simple:
var myHeaders = new Headers(); // Currently empty
You could add a header to this using Headers.append
, then test for the existence of it using has()
:
myHeaders.append('Content-Type', 'image/jpeg');
myHeaders.has('Content-Type'); // Returns true
myHeaders.has('Accept-Encoding'); // Returns false
Specifications
Specification | Status | Comment |
---|---|---|
Fetch The definition of 'has()' in that specification. | Living Standard |
Browser compatibility
BCD tables only load in the browser
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论