Mercurial > hg > orthanc
comparison OrthancCppClient/HttpClient.cpp @ 473:c9a5d72f8481
changing the namespace of HTTP enumerations
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 15 Jul 2013 17:22:13 +0200 |
parents | a6fe16a31615 |
children | 72cca077abf8 |
comparison
equal
deleted
inserted
replaced
472:722b56b99093 | 473:c9a5d72f8481 |
---|---|
96 // that happens on modern Linux versions. | 96 // that happens on modern Linux versions. |
97 // http://stackoverflow.com/questions/9191668/error-longjmp-causes-uninitialized-stack-frame | 97 // http://stackoverflow.com/questions/9191668/error-longjmp-causes-uninitialized-stack-frame |
98 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_NOSIGNAL, 1)); | 98 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_NOSIGNAL, 1)); |
99 | 99 |
100 url_ = ""; | 100 url_ = ""; |
101 method_ = Orthanc_HttpMethod_Get; | 101 method_ = HttpMethod_Get; |
102 lastStatus_ = Orthanc_HttpStatus_200_Ok; | 102 lastStatus_ = HttpStatus_200_Ok; |
103 isVerbose_ = false; | 103 isVerbose_ = false; |
104 } | 104 } |
105 | 105 |
106 | 106 |
107 HttpClient::HttpClient() : pimpl_(new PImpl) | 107 HttpClient::HttpClient() : pimpl_(new PImpl) |
160 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_USERPWD, credentials_.c_str())); | 160 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_USERPWD, credentials_.c_str())); |
161 } | 161 } |
162 | 162 |
163 switch (method_) | 163 switch (method_) |
164 { | 164 { |
165 case Orthanc_HttpMethod_Get: | 165 case HttpMethod_Get: |
166 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HTTPGET, 1L)); | 166 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HTTPGET, 1L)); |
167 break; | 167 break; |
168 | 168 |
169 case Orthanc_HttpMethod_Post: | 169 case HttpMethod_Post: |
170 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POST, 1L)); | 170 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POST, 1L)); |
171 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HTTPHEADER, pimpl_->postHeaders_)); | 171 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_HTTPHEADER, pimpl_->postHeaders_)); |
172 | 172 |
173 if (postData_.size() > 0) | 173 if (postData_.size() > 0) |
174 { | 174 { |
181 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POSTFIELDSIZE, 0)); | 181 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_POSTFIELDSIZE, 0)); |
182 } | 182 } |
183 | 183 |
184 break; | 184 break; |
185 | 185 |
186 case Orthanc_HttpMethod_Delete: | 186 case HttpMethod_Delete: |
187 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_NOBODY, 1L)); | 187 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_NOBODY, 1L)); |
188 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_CUSTOMREQUEST, "DELETE")); | 188 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_CUSTOMREQUEST, "DELETE")); |
189 break; | 189 break; |
190 | 190 |
191 case Orthanc_HttpMethod_Put: | 191 case HttpMethod_Put: |
192 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_PUT, 1L)); | 192 CheckCode(curl_easy_setopt(pimpl_->curl_, CURLOPT_PUT, 1L)); |
193 break; | 193 break; |
194 | 194 |
195 default: | 195 default: |
196 throw HttpException("HttpClient: Internal error"); | 196 throw HttpException("HttpClient: Internal error"); |
203 CheckCode(curl_easy_getinfo(pimpl_->curl_, CURLINFO_RESPONSE_CODE, &status)); | 203 CheckCode(curl_easy_getinfo(pimpl_->curl_, CURLINFO_RESPONSE_CODE, &status)); |
204 | 204 |
205 if (status == 0) | 205 if (status == 0) |
206 { | 206 { |
207 // This corresponds to a call to an inexistent host | 207 // This corresponds to a call to an inexistent host |
208 lastStatus_ = Orthanc_HttpStatus_500_InternalServerError; | 208 lastStatus_ = HttpStatus_500_InternalServerError; |
209 } | 209 } |
210 else | 210 else |
211 { | 211 { |
212 lastStatus_ = static_cast<Orthanc_HttpStatus>(status); | 212 lastStatus_ = static_cast<HttpStatus>(status); |
213 } | 213 } |
214 | 214 |
215 return (status >= 200 && status < 300); | 215 return (status >= 200 && status < 300); |
216 } | 216 } |
217 | 217 |