veloze
Version:
A modern and fast express-like webserver for the web
55 lines (40 loc) • 1.23 kB
Markdown
[◀︎ middlewares/tooBusy](../middleware/tooBusy.md)
[🛖](../index.md)
[](../request/getHeader.md)
Parses the 'accept' request header. MIME types are returned as they appear.
| type | property | description |
| -------------------- | --------- | ----------------------------- |
| http.IncomingMessage | req | request object |
| boolean | \[weight] | optionally returns the weight |
```js
req.headers.accept =
"text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8";
const parsed = accept(req);
// parsed === [
// 'text/html',
// 'application/xhtml+xml',
// 'application/xml',
// 'image/webp',
// '*/*'
// ]
```
Parse with weights
```js
req.headers.accept =
"text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8";
const parsed = accept(req, true);
// parsed === [
// ['text/html', 1],
// ['application/xhtml+xml', 1],
// ['application/xml', 0.9],
// ['image/webp', 1],
// ['*/*', 0.8]
// ]
```
Parses the 'accept-encoding' request header
Uses same API as `accept()`.
---
[🔝 TOP](