Mercurial > hg > orthanc
comparison OrthancFramework/Sources/HttpServer/HttpContentNegociation.h @ 5338:78c59b02b121
accept parameters are now provided to HttpContentNegociation::IHandler::Handle()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 28 Jun 2023 08:29:43 +0200 |
parents | 0ea402b4d901 |
children | 48b8dae6dc77 |
comparison
equal
deleted
inserted
replaced
5337:b376abae664a | 5338:78c59b02b121 |
---|---|
37 namespace Orthanc | 37 namespace Orthanc |
38 { | 38 { |
39 class ORTHANC_PUBLIC HttpContentNegociation : public boost::noncopyable | 39 class ORTHANC_PUBLIC HttpContentNegociation : public boost::noncopyable |
40 { | 40 { |
41 public: | 41 public: |
42 typedef std::map<std::string, std::string> HttpHeaders; | 42 typedef std::map<std::string, std::string> Dictionary; |
43 | 43 |
44 class IHandler : public boost::noncopyable | 44 class IHandler : public boost::noncopyable |
45 { | 45 { |
46 public: | 46 public: |
47 virtual ~IHandler() | 47 virtual ~IHandler() |
48 { | 48 { |
49 } | 49 } |
50 | 50 |
51 virtual void Handle(const std::string& type, | 51 virtual void Handle(const std::string& type, |
52 const std::string& subtype) = 0; | 52 const std::string& subtype, |
53 const Dictionary& parameters) = 0; | |
53 }; | 54 }; |
54 | 55 |
55 private: | 56 private: |
56 struct Handler | 57 struct Handler |
57 { | 58 { |
64 IHandler& handler); | 65 IHandler& handler); |
65 | 66 |
66 bool IsMatch(const std::string& type, | 67 bool IsMatch(const std::string& type, |
67 const std::string& subtype) const; | 68 const std::string& subtype) const; |
68 | 69 |
69 void Call() const | 70 void Call(const Dictionary& parameters) const |
70 { | 71 { |
71 handler_.Handle(type_, subtype_); | 72 handler_.Handle(type_, subtype_, parameters); |
72 } | 73 } |
73 }; | 74 }; |
74 | 75 |
75 | 76 |
76 struct Reference; | 77 struct Reference; |
84 static bool SplitPair(std::string& first /* out */, | 85 static bool SplitPair(std::string& first /* out */, |
85 std::string& second /* out */, | 86 std::string& second /* out */, |
86 const std::string& source, | 87 const std::string& source, |
87 char separator); | 88 char separator); |
88 | 89 |
89 static float GetQuality(const Tokens& parameters); | 90 static void SelectBestMatch(std::unique_ptr<Reference>& target, |
90 | |
91 static void SelectBestMatch(std::unique_ptr<Reference>& best, | |
92 const Handler& handler, | 91 const Handler& handler, |
93 const std::string& type, | 92 const std::string& type, |
94 const std::string& subtype, | 93 const std::string& subtype, |
95 float quality); | 94 const Dictionary& parameters); |
96 | 95 |
97 public: | 96 public: |
98 void Register(const std::string& mime, | 97 void Register(const std::string& mime, |
99 IHandler& handler); | 98 IHandler& handler); |
100 | 99 |
101 bool Apply(const HttpHeaders& headers); | 100 bool Apply(const Dictionary& headers); |
102 | 101 |
103 bool Apply(const std::string& accept); | 102 bool Apply(const std::string& accept); |
104 }; | 103 }; |
105 } | 104 } |