From fff08a29e7cca7a7c3ca38a0360bcc686e7ca633 Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Mon, 16 Sep 2013 22:33:18 +0200 Subject: [PATCH] Accepts "*" as valid media type (interpreted as */* to be flexible) --- library/network/protocol/http/src/http_media_type.e | 11 +++++++++-- .../protocol/http/tests/http_content_type_set.e | 4 ++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/library/network/protocol/http/src/http_media_type.e b/library/network/protocol/http/src/http_media_type.e index 940f3d84..2addad59 100644 --- a/library/network/protocol/http/src/http_media_type.e +++ b/library/network/protocol/http/src/http_media_type.e @@ -97,9 +97,16 @@ feature {NONE} -- Initialization -- Extract type and subtype p := t.index_of ('/', 1) if p = 0 then - has_error := True + t.right_adjust type := t - subtype := "" + if t.same_string ("*") then + -- Flexible parser allowing "*" even if this is not really a valid media-type + -- let's interpret it as "*/*" + subtype := "*" + else + has_error := True + subtype := "*" + end else subtype := t.substring (p + 1, t.count) type := t diff --git a/library/network/protocol/http/tests/http_content_type_set.e b/library/network/protocol/http/tests/http_content_type_set.e index 1a37ffba..f93b4eab 100644 --- a/library/network/protocol/http/tests/http_content_type_set.e +++ b/library/network/protocol/http/tests/http_content_type_set.e @@ -19,6 +19,10 @@ feature -- Content type test_content_type_with_params ("text/plain; param1=%"something;foo=bar%"; param2=%"another-thing%"", "text", "plain", <<["param1", "something;foo=bar"], ["param2", "another-thing"]>> ) + test_content_type ("*", "*", "*") + test_content_type_with_params ("* ; q=0.8", "*", "*", <<["q", "0.8"]>>) + test_content_type ("*/*", "*", "*") + test_content_type ("text/*", "text", "*") end test_http_content_type