Mercurial > hg > orthanc
changeset 5339:cb11e5ced4e3
added tests from issue #216
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 28 Jun 2023 10:32:58 +0200 |
parents | 78c59b02b121 |
children | 990cfa101803 |
files | OrthancFramework/Sources/HttpServer/HttpContentNegociation.cpp OrthancFramework/UnitTestsSources/RestApiTests.cpp |
diffstat | 2 files changed, 55 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/OrthancFramework/Sources/HttpServer/HttpContentNegociation.cpp Wed Jun 28 08:29:43 2023 +0200 +++ b/OrthancFramework/Sources/HttpServer/HttpContentNegociation.cpp Wed Jun 28 10:32:58 2023 +0200 @@ -66,7 +66,6 @@ const Handler& handler_; uint8_t level_; float quality_; - std::string application_; Dictionary parameters_; static float GetQuality(const Dictionary& parameters) @@ -111,7 +110,6 @@ const Dictionary& parameters) : handler_(handler), quality_(GetQuality(parameters)), - application_(type + "/" + subtype), parameters_(parameters) { if (type == "*" && subtype == "*") @@ -248,7 +246,17 @@ { std::string key, value; - if (!SplitPair(key, value, tokens[i], '=')) + if (SplitPair(key, value, tokens[i], '=')) + { + // Remove the enclosing quotes, if present + if (!value.empty() && + value[0] == '"' && + value[value.size() - 1] == '"') + { + value = value.substr(1, value.size() - 2); + } + } + else { key = Toolbox::StripSpaces(tokens[i]); value = "";
--- a/OrthancFramework/UnitTestsSources/RestApiTests.cpp Wed Jun 28 08:29:43 2023 +0200 +++ b/OrthancFramework/UnitTestsSources/RestApiTests.cpp Wed Jun 28 10:32:58 2023 +0200 @@ -461,7 +461,7 @@ // preferred media types, but if they do not exist, then send the // text/x-dvi entity, and if that does not exist, send the // text/plain entity."" - const std::string T1 = "text/plain; q=0.5, text/html ; hello = world , text/x-dvi; q=0.8, text/x-c"; + const std::string T1 = "text/plain; q=0.5, text/html ; hello = \"world\" , text/x-dvi; q=0.8, text/x-c"; { HttpContentNegociation d; @@ -526,6 +526,49 @@ ASSERT_EQ(1u, h.GetParameters().size()); ASSERT_EQ("0.5", h.GetParameters() ["q"]); } + + // Below are the tests from issue 216: + // https://bugs.orthanc-server.com/show_bug.cgi?id=216 + + { + HttpContentNegociation d; + d.Register("application/dicom+json", h); + ASSERT_TRUE(d.Apply("image/webp, */*;q=0.8, text/html, application/xhtml+xml, application/xml;q=0.9")); + ASSERT_EQ("application", h.GetType()); + ASSERT_EQ("dicom+json", h.GetSubType()); + ASSERT_EQ(1u, h.GetParameters().size()); + ASSERT_EQ("0.8", h.GetParameters() ["q"]); + } + + { + HttpContentNegociation d; + d.Register("application/dicom+json", h); + ASSERT_TRUE(d.Apply("image/webp, */*; q = \"0.8\" , text/html, application/xhtml+xml, application/xml;q=0.9")); + ASSERT_EQ("application", h.GetType()); + ASSERT_EQ("dicom+json", h.GetSubType()); + ASSERT_EQ(1u, h.GetParameters().size()); + ASSERT_EQ("0.8", h.GetParameters() ["q"]); + } + + { + HttpContentNegociation d; + d.Register("application/dicom+json", h); + ASSERT_TRUE(d.Apply("text/html, application/xhtml+xml, application/xml, image/webp, */*;q=0.8")); + ASSERT_EQ("application", h.GetType()); + ASSERT_EQ("dicom+json", h.GetSubType()); + ASSERT_EQ(1u, h.GetParameters().size()); + ASSERT_EQ("0.8", h.GetParameters() ["q"]); + } + + { + HttpContentNegociation d; + d.Register("application/dicom+json", h); + ASSERT_TRUE(d.Apply("text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2")); + ASSERT_EQ("application", h.GetType()); + ASSERT_EQ("dicom+json", h.GetSubType()); + ASSERT_EQ(1u, h.GetParameters().size()); + ASSERT_EQ(".2", h.GetParameters() ["q"]); + } }