Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added Readme

  • Loading branch information...
commit 10939a10fc529866921202c957cd66f606d32209 1 parent b1ee4ab
@niclashoyer authored
Showing with 77 additions and 0 deletions.
  1. +77 −0 README.md
View
77 README.md
@@ -0,0 +1,77 @@
+# Accept
+
+Accept parses all accept header fields and sorts them according to the HTTP
+specification.
+
+## Supported Header Fields
+
+### Accept
+Parsed into `req.accept.types`.
+
+### Accept-Charset
+Parsed into `req.accept.charsets`.
+
+### Accept-Encoding
+Parsed into `req.accept.encodings`.
+
+### Accept-Language
+Parsed into `req.accept.languages`.
+
+### Accept-Ranges
+Parsed into `req.accept.ranges`.
+
+## Installation
+
+```bash
+npm install http-accept
+```
+
+## Usage
+
+Just `require 'http-accept'` and throw it into a connect compatible middlware
+stack.
+
+```coffeescript
+connect = require 'connect'
+http = require 'http'
+accept = require 'http-accept'
+
+app = connect()
+app.use connect.logger 'dev'
+app.use accept
+app.use (req, res) ->
+ console.log req.accept
+ res.end()
+
+http.createServer(app).listen 3000
+```
+
+A request from a browser on `http://localhost:3000` would print out
+
+```json
+{ types:
+ [ { type: 'text',
+ subtype: 'html',
+ params: {},
+ mediarange: 'text/html',
+ quality: 1 },
+ { type: 'application',
+ subtype: 'xhtml+xml',
+ params: {},
+ mediarange: 'application/xhtml+xml',
+ quality: 1 },
+ { type: 'application',
+ subtype: 'xml',
+ params: [Object],
+ mediarange: 'application/xml',
+ quality: 0.9 },
+ { type: '*',
+ subtype: '*',
+ params: [Object],
+ mediarange: '*/*',
+ quality: 0.8 } ],
+ charsets: undefined,
+ encodings: [ 'gzip', 'deflate' ],
+ languages: [ 'de-de', 'de', 'en-us', 'en' ],
+ ranges: undefined }
+```
Please sign in to comment.
Something went wrong with that request. Please try again.