Installations
npm install accepts
Developer
jshttp
Developer Guide
Module System
Unable to determine the module system for this package.
Min. Node Version
>= 0.6
Typescript Support
No
Node Version
16.13.1
NPM Version
8.1.2
Statistics
255 Stars
254 Commits
44 Forks
19 Watching
4 Branches
29 Contributors
Updated on 11 Nov 2024
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
7,150,723,200
Last day
-5.8%
6,170,905
Compared to previous day
Last week
2.4%
36,226,389
Compared to previous week
Last month
7.8%
150,037,358
Compared to previous month
Last year
3.7%
1,580,723,704
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
accepts
Higher level content negotiation based on negotiator. Extracted from koa for general use.
In addition to negotiator, it allows:
- Allows types as an array or arguments list, ie
(['text/html', 'application/json'])
as well as('text/html', 'application/json')
. - Allows type shorthands such as
json
. - Returns
false
when no types match - Treats non-existent headers as
*
Installation
This is a Node.js module available through the
npm registry. Installation is done using the
npm install
command:
1$ npm install accepts
API
1var accepts = require('accepts')
accepts(req)
Create a new Accepts
object for the given req
.
.charset(charsets)
Return the first accepted charset. If nothing in charsets
is accepted,
then false
is returned.
.charsets()
Return the charsets that the request accepts, in the order of the client's preference (most preferred first).
.encoding(encodings)
Return the first accepted encoding. If nothing in encodings
is accepted,
then false
is returned.
.encodings()
Return the encodings that the request accepts, in the order of the client's preference (most preferred first).
.language(languages)
Return the first accepted language. If nothing in languages
is accepted,
then false
is returned.
.languages()
Return the languages that the request accepts, in the order of the client's preference (most preferred first).
.type(types)
Return the first accepted type (and it is returned as the same text as what
appears in the types
array). If nothing in types
is accepted, then false
is returned.
The types
array can contain full MIME types or file extensions. Any value
that is not a full MIME type is passed to require('mime-types').lookup
.
.types()
Return the types that the request accepts, in the order of the client's preference (most preferred first).
Examples
Simple type negotiation
This simple example shows how to use accepts
to return a different typed
respond body based on what the client wants to accept. The server lists it's
preferences in order and will get back the best match between the client and
server.
1var accepts = require('accepts') 2var http = require('http') 3 4function app (req, res) { 5 var accept = accepts(req) 6 7 // the order of this list is significant; should be server preferred order 8 switch (accept.type(['json', 'html'])) { 9 case 'json': 10 res.setHeader('Content-Type', 'application/json') 11 res.write('{"hello":"world!"}') 12 break 13 case 'html': 14 res.setHeader('Content-Type', 'text/html') 15 res.write('<b>hello, world!</b>') 16 break 17 default: 18 // the fallback is text/plain, so no need to specify it above 19 res.setHeader('Content-Type', 'text/plain') 20 res.write('hello, world!') 21 break 22 } 23 24 res.end() 25} 26 27http.createServer(app).listen(3000)
You can test this out with the cURL program:
1curl -I -H'Accept: text/html' http://localhost:3000/
License
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
security policy file detected
Details
- Info: security policy file detected: github.com/jshttp/.github/SECURITY.md:1
- Warn: no linked content found
- Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/jshttp/.github/SECURITY.md:1
- Info: Found text in security policy: github.com/jshttp/.github/SECURITY.md:1
Reason
4 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 3
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:43: update your workflow using https://app.stepsecurity.io/secureworkflow/jshttp/accepts/ci.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:85: update your workflow using https://app.stepsecurity.io/secureworkflow/jshttp/accepts/ci.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:97: update your workflow using https://app.stepsecurity.io/secureworkflow/jshttp/accepts/ci.yml/master?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/ci.yml:61
- Info: 3 out of 4 GitHub-owned GitHubAction dependencies pinned
- Info: 1 out of 3 third-party GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
Found 4/29 approved changesets -- score normalized to 1
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Info: topLevel permissions set to 'read-all': .github/workflows/scorecard.yml:18
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 7 are checked with a SAST tool
Score
4.2
/10
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More