Source

csconneg / README

Full commit
CsConneg aims to implement content negotiation as described in section 1.4 of
RFC 2616 (http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html).

Current version focuses on media type negotiation. Negotiation of other
representation aspects (language, charset, encoding) is not covered.

Example of usage:

    void handleRequest(HttpContext http)
    {
        new CsConneg.Builder()
            .MediaHandler(
                "text/html", delegate
                {
                    // Serve HTML.
                    http.Response.ContentType = "text/html";
                    http.Response.Write("<html>...</html>");
                }
            .MediaHandler(
                "application/json", delegate
                {
                    // Serve JSON.
                    http.Response.ContentType = "application/json";
                    http.Response.Write("{spam: 42}");
                },
            .NoMatchHandler(
                delegate
                {
                    // Have no acceptable media types to serve.
                    http.Response.Code = 406; // "Not Acceptable"
                })
            .Build()
            .Dispatch(http.Request.Headers["Accept"] ?? "*/*");
    }