Gathering detailed insights and metrics for accepts
Gathering detailed insights and metrics for accepts
Gathering detailed insights and metrics for accepts
Gathering detailed insights and metrics for accepts
npm install accepts
Module System
Unable to determine the module system for this package.
Min. Node Version
Typescript Support
Node Version
NPM Version
255 Stars
254 Commits
44 Forks
19 Watching
4 Branches
29 Contributors
Updated on 11 Nov 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
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
Higher level content negotiation based on negotiator. Extracted from koa for general use.
In addition to negotiator, it allows:
(['text/html', 'application/json'])
as well as ('text/html', 'application/json')
.json
.false
when no types match*
This is a Node.js module available through the
npm registry. Installation is done using the
npm install
command:
1$ npm install accepts
1var accepts = require('accepts')
Create a new Accepts
object for the given req
.
Return the first accepted charset. If nothing in charsets
is accepted,
then false
is returned.
Return the charsets that the request accepts, in the order of the client's preference (most preferred first).
Return the first accepted encoding. If nothing in encodings
is accepted,
then false
is returned.
Return the encodings that the request accepts, in the order of the client's preference (most preferred first).
Return the first accepted language. If nothing in languages
is accepted,
then false
is returned.
Return the languages that the request accepts, in the order of the client's preference (most preferred first).
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
.
Return the types that the request accepts, in the order of the client's preference (most preferred first).
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/
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
Reason
security policy file detected
Details
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
Reason
Found 4/29 approved changesets -- score normalized to 1
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
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