From 68ec6fb29c51598a73b8c1f2dfaf27fcc237bc48 Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Fri, 14 Dec 2012 15:52:54 +0100 Subject: [PATCH] Made WSF_REQUEST.is_content_type_accepted safer. --- library/server/wsf/src/wsf_request.e | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/library/server/wsf/src/wsf_request.e b/library/server/wsf/src/wsf_request.e index 99e5d22a..5c5bf280 100644 --- a/library/server/wsf/src/wsf_request.e +++ b/library/server/wsf/src/wsf_request.e @@ -256,8 +256,30 @@ feature -- Helper is_content_type_accepted (a_content_type: READABLE_STRING_GENERAL): BOOLEAN -- Does client accepts content_type for the response? + --| Based on header "Accept:" that can be for instance + --| text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 + local + i, j: INTEGER do if attached http_accept as l_accept then + i := l_accept.substring_index (a_content_type, 1) + if i > 0 then + -- contains the text, now check if this is the exact text + if + i = 1 -- At the beginning of text + or else l_accept[i-1].is_space -- preceded by space + or else l_accept[i-1] = ',' -- preceded by other mime type + then + j := i + a_content_type.count + if l_accept.valid_index (j) then + Result := l_accept[j] = ',' -- followed by other mime type + or else l_accept[j] = ';' -- followed by quality ;q=... + or else l_accept[j].is_space -- followed by space + else -- end of text + Result := True + end + end + end Result := l_accept.has_substring (a_content_type) end end