-
Notifications
You must be signed in to change notification settings - Fork 22.4k
/
index.md
77 lines (54 loc) · 1.63 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
---
title: Headers.delete()
slug: Web/API/Headers/delete
page-type: web-api-instance-method
tags:
- API
- Fetch
- Method
- Reference
- delete
browser-compat: api.Headers.delete
---
{{APIRef("Fetch")}}
The **`delete()`** method of the {{domxref("Headers")}}
interface deletes a header from the current `Headers` object.
This method throws a {{jsxref("TypeError")}} for the following reasons:
- The value of the name parameter is not the name of an HTTP header.
- The value of {{Glossary("Guard")}} is `immutable`.
For security reasons, some headers can only be controlled by the user agent. These
headers include the {{Glossary("Forbidden_header_name", "forbidden header names", 1)}}
and {{Glossary("Forbidden_response_header_name", "forbidden response header names",
1)}}.
## Syntax
```js
delete(name)
```
### Parameters
- `name`
- : The name of the HTTP header you want to delete from the `Headers` object.
### Return value
None ({{jsxref("undefined")}}).
## Examples
Creating an empty `Headers` object is simple:
```js
var myHeaders = new Headers(); // Currently empty
```
You could add a header to this using {{domxref("Headers.append")}}:
```js
myHeaders.append('Content-Type', 'image/jpeg');
myHeaders.get('Content-Type'); // Returns 'image/jpeg'
```
You can then delete it again:
```js
myHeaders.delete('Content-Type');
myHeaders.get('Content-Type'); // Returns null, as it has been deleted
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- [ServiceWorker API](/en-US/docs/Web/API/Service_Worker_API)
- [HTTP access control (CORS)](/en-US/docs/Web/HTTP/CORS)
- [HTTP](/en-US/docs/Web/HTTP)