From 74079325a09f89f2651fdd6d45e54b017397ab99 Mon Sep 17 00:00:00 2001 From: colin-adams Date: Fri, 15 Jun 2012 07:57:48 -0700 Subject: [PATCH] Updated Library conneg (markdown) --- Library-conneg.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/Library-conneg.md b/Library-conneg.md index 7362b58a..2d43309e 100644 --- a/Library-conneg.md +++ b/Library-conneg.md @@ -9,5 +9,51 @@ That call defines our defaults for media-type, language, charset and encoding, r The user agent (a web browser, for example. or the curl program), can request different representations by using headers. For example, `Accept: application/json; q=0.2, application/xml` says the client would be very happy to get back an XML representation (if you omit the q for quality parameter, it defaults to 1, which is best), but (s)he will tolerate JSON. Clearly, we are going to be able to satisfy that client, as we serve JSON by default. But what if the client had requested `Accept: application/xml;q=0.8, text/html`? In this example, we are going to serve both JSON and XML representations upon request. A client who requests `Accept: text/html, text/plain` is going to be disappointed. For the other aspects (language, charset and encoding), we are not going to offer any choices. That does not mean we ignore the client's headers for these aspects. We are going to check if our representation is acceptable to the client, and if not, return a 406 Not Acceptable response (an alternative is to send our representation anyway, and let the user decide whether or not to use it). +Next, we need to declare all the representations we support: + +` mime_types_supported: LINKED_LIST [STRING] is + -- Media types `Current' supports + once + create Result.make + Result.put_front ({HTTP_MIME_TYPES}.application_xml) + Result.put_front ({HTTP_MIME_TYPES}.application_json) + ensure + mime_types_supported_not_void: Result /= Void + no_void_entry: not Result.has (Void) + end + + charsets_supported: LINKED_LIST [STRING] is + -- Character sets `Current' supports + once + create Result.make + Result.put_front ("UTF-8") + ensure + charsets_supported_not_void: Result /= Void + no_void_entry: not Result.has (Void) + end + + encodings_supported: LINKED_LIST [STRING] is + -- Encodings `Current' supports + once + create Result.make + Result.put_front ("identity") + Result.put_front ("") -- identity encoding + ensure + encoding_supported_not_void: Result /= Void + no_void_entry: not Result.has (Void) + end + + languages_supported: LINKED_LIST [STRING] is + -- Languages `Current' supports + once + create Result.make + Result.put_front ("en") + ensure + languages_supported_not_void: Result /= Void + no_void_entry: not Result.has (Void) + end + +Now we are in a position to do some negotiating. At the beginning of your handler(s), code: +