Server IP : 108.163.255.210 / Your IP : 18.191.116.61 Web Server : Apache System : Linux blossom.urlnameserver.com 3.10.0-1160.80.1.el7.x86_64 #1 SMP Tue Nov 8 15:48:59 UTC 2022 x86_64 User : ( 1172) PHP Version : 7.2.34 Disable Function : eval,escapeshellarg,proc_close,proc_get_status,proc_nice,proc_open,symlink,system,pcntl_exec,getrusage,chown,chgp,closelog,openlog,syslog,define_syslog_variables,php_ini_loaded_file,getservbyname,getservbyport,posix_getgid,posix_getgrgid,proc_terminate,pfsockopen,apache_child_terminate,posix_mkfifo,posix_setpgid,posix_setuid,hypot,pg_host,pos,posix_access,posix_getcwd,posix_getservbyname,myshellexec,getpid,posix_getsid,posix_isatty,posix_kill,posix_mknod,posix_setgid,posix_setsid,posix_setuid,posix_times,posix_uname,ps_fill,posix_getpwuid,global,ini_restore,zip_open,zip_read,rar_open,bzopen,bzread,bzwrite,apache_get_modules,apache_get_version,phpversionphpinfo,php_ini_scanned_files,get_current_user,disk_total_space,diskfreespace,leak,imap_list,hypo,filedump,safe_mode,getmygid,apache_getenv,apache_setenv,bzread,bzwrite,bzopen,phpini,higlight_file,dos_conv,get_cwd,er_log,cmd,e_name,vdir,get_dir,only_read,ftok,ftpexec,posix_getpwnam,mysql_list_dbs,disk_free_space,session_save_path,confirm_phpdoc_compiled,zip_entry_rea,php_u,psockopen,crack_opendict,crack_getlastmessage,crack_closedict,crack_check,fpassthru,posix_get_last_error,posix_getlogin,posix_getgroups,posix_strerror,posix_getrlimit,posix_getpgrp,posix_getgrnam,pos,dl MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/unilinki/public_html/unilinkindia.com/old/node_modules/accepts/ |
Upload File : |
# accepts [![NPM Version][npm-version-image]][npm-url] [![NPM Downloads][npm-downloads-image]][npm-url] [![Node.js Version][node-version-image]][node-version-url] [![Build Status][travis-image]][travis-url] [![Test Coverage][coveralls-image]][coveralls-url] Higher level content negotiation based on [negotiator](https://www.npmjs.com/package/negotiator). Extracted from [koa](https://www.npmjs.com/package/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](https://nodejs.org/en/) module available through the [npm registry](https://www.npmjs.com/). Installation is done using the [`npm install` command](https://docs.npmjs.com/getting-started/installing-npm-packages-locally): ```sh $ npm install accepts ``` ## API <!-- eslint-disable no-unused-vars --> ```js var 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 types 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. ```js var accepts = require('accepts') var http = require('http') function app (req, res) { var accept = accepts(req) // the order of this list is significant; should be server preferred order switch (accept.type(['json', 'html'])) { case 'json': res.setHeader('Content-Type', 'application/json') res.write('{"hello":"world!"}') break case 'html': res.setHeader('Content-Type', 'text/html') res.write('<b>hello, world!</b>') break default: // the fallback is text/plain, so no need to specify it above res.setHeader('Content-Type', 'text/plain') res.write('hello, world!') break } res.end() } http.createServer(app).listen(3000) ``` You can test this out with the cURL program: ```sh curl -I -H'Accept: text/html' http://localhost:3000/ ``` ## License [MIT](LICENSE) [coveralls-image]: https://badgen.net/coveralls/c/github/jshttp/accepts/master [coveralls-url]: https://coveralls.io/r/jshttp/accepts?branch=master [node-version-image]: https://badgen.net/npm/node/accepts [node-version-url]: https://nodejs.org/en/download [npm-downloads-image]: https://badgen.net/npm/dm/accepts [npm-url]: https://npmjs.org/package/accepts [npm-version-image]: https://badgen.net/npm/v/accepts [travis-image]: https://badgen.net/travis/jshttp/accepts/master [travis-url]: https://travis-ci.org/jshttp/accepts