Module middleware/accept
This module provides middleware to check if a HTTP request accepts the possible response and makes content negotiation more convenient.
Functions
- middleware (next, app)
middleware (next, app)
This middleware installs a accept function in the application object.
If the client request does not accept one of the specified content types,
the middleware returns a 406 - Not Acceptable response.
Applying this middleware adds an accepted property to the request object.
This contains an array with the client's accepted media types sorted
from highest to the lowest quality.
Example
app.configure("accept", "route");
app.accept(["text/plain", "text/html"]);
app.get("/", function(req) {
if (req.accepted[0].subType === "html") {
return response.html("");
} else {
return response.text("foo");
}
});
Parameters
| Function | next | the wrapped middleware chain |
| Object | app | the Stick Application object |
Returns
| Function | a JSGI middleware function |