comparison Framework/Oracle/HttpCommand.h @ 979:18d53a8b41b7

HttpCommand
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 03 Sep 2019 17:52:28 +0200
parents
children e6d2ff8f1ab4 2d8ab34c8c91
comparison
equal deleted inserted replaced
978:0e21ecafcc23 979:18d53a8b41b7
1 /**
2 * Stone of Orthanc
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
6 *
7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU Affero General Public License
9 * as published by the Free Software Foundation, either version 3 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/
20
21
22 #pragma once
23
24 #include "../Messages/IMessage.h"
25 #include "OracleCommandWithPayload.h"
26
27 #include <Core/Enumerations.h>
28
29 #include <map>
30 #include <json/value.h>
31
32 namespace OrthancStone
33 {
34 class HttpCommand : public OracleCommandWithPayload
35 {
36 public:
37 typedef std::map<std::string, std::string> HttpHeaders;
38
39 class SuccessMessage : public OriginMessage<HttpCommand>
40 {
41 ORTHANC_STONE_MESSAGE(__FILE__, __LINE__);
42
43 private:
44 HttpHeaders headers_;
45 std::string answer_;
46
47 public:
48 SuccessMessage(const HttpCommand& command,
49 const HttpHeaders& answerHeaders,
50 std::string& answer /* will be swapped to avoid a memcpy() */);
51
52 const std::string& GetAnswer() const
53 {
54 return answer_;
55 }
56
57 void ParseJsonBody(Json::Value& target) const;
58
59 const HttpHeaders& GetAnswerHeaders() const
60 {
61 return headers_;
62 }
63 };
64
65
66 private:
67 Orthanc::HttpMethod method_;
68 std::string url_;
69 std::string body_;
70 HttpHeaders headers_;
71 unsigned int timeout_;
72
73 public:
74 HttpCommand();
75
76 virtual Type GetType() const
77 {
78 return Type_Http;
79 }
80
81 void SetMethod(Orthanc::HttpMethod method)
82 {
83 method_ = method;
84 }
85
86 void SetUrl(const std::string& url)
87 {
88 url_ = url;
89 }
90
91 void SetBody(const std::string& body)
92 {
93 body_ = body;
94 }
95
96 void SetBody(const Json::Value& json);
97
98 void SwapBody(std::string& body)
99 {
100 body_.swap(body);
101 }
102
103 void SetHttpHeaders(const HttpHeaders& headers)
104 {
105 headers_ = headers;
106 }
107
108 void SetHttpHeader(const std::string& key,
109 const std::string& value)
110 {
111 headers_[key] = value;
112 }
113
114 Orthanc::HttpMethod GetMethod() const
115 {
116 return method_;
117 }
118
119 const std::string& GetUrl() const
120 {
121 return url_;
122 }
123
124 const std::string& GetBody() const;
125
126 const HttpHeaders& GetHttpHeaders() const
127 {
128 return headers_;
129 }
130
131 void SetTimeout(unsigned int seconds)
132 {
133 timeout_ = seconds;
134 }
135
136 unsigned int GetTimeout() const
137 {
138 return timeout_;
139 }
140 };
141 }