# HG changeset patch # User Sebastien Jodogne # Date 1687941178 -7200 # Node ID cb11e5ced4e328f0661b403c09f96e90f9eb810a # Parent 78c59b02b12105d06246f0919fcf2cedad4bf36b added tests from issue 216 diff -r 78c59b02b121 -r cb11e5ced4e3 OrthancFramework/Sources/HttpServer/HttpContentNegociation.cpp --- 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 = ""; diff -r 78c59b02b121 -r cb11e5ced4e3 OrthancFramework/UnitTestsSources/RestApiTests.cpp --- 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"]); + } }