From 53a206694a5bdd7d583be773375239f576f254f3 Mon Sep 17 00:00:00 2001 From: colin-adams Date: Fri, 15 Jun 2012 08:04:30 -0700 Subject: [PATCH] Updated Library conneg (markdown) --- Library-conneg.md | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/Library-conneg.md b/Library-conneg.md index 2d43309e..9aa4ed8b 100644 --- a/Library-conneg.md +++ b/Library-conneg.md @@ -12,7 +12,7 @@ The user agent (a web browser, for example. or the curl program), can request di Next, we need to declare all the representations we support: ` mime_types_supported: LINKED_LIST [STRING] is - -- Media types `Current' supports + -- Media types 'Current' supports once create Result.make Result.put_front ({HTTP_MIME_TYPES}.application_xml) @@ -23,7 +23,7 @@ Next, we need to declare all the representations we support: end charsets_supported: LINKED_LIST [STRING] is - -- Character sets `Current' supports + -- Character sets 'Current' supports once create Result.make Result.put_front ("UTF-8") @@ -33,7 +33,7 @@ Next, we need to declare all the representations we support: end encodings_supported: LINKED_LIST [STRING] is - -- Encodings `Current' supports + -- Encodings 'Current' supports once create Result.make Result.put_front ("identity") @@ -44,7 +44,7 @@ Next, we need to declare all the representations we support: end languages_supported: LINKED_LIST [STRING] is - -- Languages `Current' supports + -- Languages 'Current' supports once create Result.make Result.put_front ("en") @@ -55,5 +55,20 @@ Next, we need to declare all the representations we support: Now we are in a position to do some negotiating. At the beginning of your handler(s), code: - +` +local + l_media_variants: MEDIA_TYPE_VARIANT_RESULTS + do + l_media_variants:= conneg.media_type_preference (mime_types_supported, a_req.http_accept) + if not l_media_variants.is_acceptable then + send_unacceptable_media_type (a_res) + elseif not conneg.charset_preference (charsets_supported, a_req.http_accept_charset).is_acceptable then + send_unacceptable_charset (a_res) + elseif not conneg.encoding_preference (encodings_supported, a_req.http_accept_encoding).is_acceptable then + send_unacceptable_encoding (a_res) + elseif not conneg.language_preference (languages_supported, a_req.http_accept_language).is_acceptable then + send_unacceptable_encoding (a_res) + else + -- We have agreed a representation, let's go and serve it to the client +`